rework dimensions and orientation into Placement, optimise requirements to work on previous candidates, use vec3 for positions

This commit is contained in:
2022-11-24 11:34:11 +01:00
parent f13ba4cd95
commit 3e51410ade
36 changed files with 268 additions and 275 deletions

View File

@@ -5,26 +5,29 @@ using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.Requirements
{
[CreateAssetMenu(menuName = "Requirements/Face Space Center")]
public class FaceSpaceCenter : OrientationRequirement
public class FaceSpaceCenter : PlacementRequirement
{
protected override IEnumerable<Orientation> GenerateCandidates(Module module, Space space)
protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space)
{
var orientation = new HashSet<Orientation>(1);
float width = space.rrDimensions.width;
float length = space.rrDimensions.length;
var xRel = module.SrPosition.x / (width - 1);
var zRel = module.SrPosition.y / (length - 1);
if (zRel > xRel)
{
orientation.Add(zRel > 1 - xRel ? Orientation.South : Orientation.East);
}
else
{
orientation.Add(zRel > 1 - xRel ? Orientation.West : Orientation.North);
}
float width = space.rrPlacement.size.x - 1;
float length = space.rrPlacement.size.y - 1;
return orientation;
candidates.RemoveAll(candidate =>
{
var xRel = candidate.position.x / width;
var zRel = candidate.position.z / length;
return candidate.orientation !=
(zRel > xRel
? zRel > 1 - xRel
? Orientation.South
: Orientation.East
: zRel > 1 - xRel
? Orientation.West
: Orientation.North);
});
return candidates;
}
}
}