Player: more line-of-sight debug lines

GitOrigin-RevId: 655eef228659215ce53ac3e58bc324581a0fec3f
This commit is contained in:
Colin McMillen 2020-02-04 15:32:04 -05:00
parent 80746ecaed
commit 6b9890b6f7

View File

@ -210,30 +210,34 @@ namespace SemiColinGames {
} }
if (points.Count > hitCount) { if (points.Count > hitCount) {
boxes.Add(box); boxes.Add(box);
Debug.AddRect(box, color);
} }
} }
HashSet<AABB> boxesSeen = new HashSet<AABB>(); HashSet<AABB> boxesSeen = new HashSet<AABB>();
foreach (Vector2 hit in points) { foreach (Vector2 point in points) {
float minTime = 1; float minTime = 1;
AABB? closestBox = null; AABB? closestBox = null;
Vector2 delta = Vector2.Subtract(hit, eyePos); Vector2 delta = Vector2.Subtract(point, eyePos);
foreach (AABB box in boxes) { foreach (AABB box in boxes) {
Hit? maybeHit = box.IntersectSegment(eyePos, delta); Hit? maybeHit = box.IntersectSegment(eyePos, delta);
if (maybeHit != null && maybeHit.Value.Time < minTime) { if (maybeHit != null) {
minTime = maybeHit.Value.Time; float time = FMath.Clamp(maybeHit.Value.Time, 0, 1);
Vector2 target = Vector2.Add(eyePos, Vector2.Multiply(delta, time));
Debug.AddLine(eyePos, target, color);
if (time < minTime) {
minTime = time;
closestBox = box; closestBox = box;
} }
} }
}
if (closestBox != null) { if (closestBox != null) {
Vector2 target = Vector2.Add(eyePos, Vector2.Multiply(delta, minTime));
Debug.AddLine(eyePos, target, color);
boxesSeen.Add(closestBox.Value); boxesSeen.Add(closestBox.Value);
} }
} }
foreach (AABB box in boxesSeen) { foreach (AABB box in boxesSeen) {
Debug.AddRect(box, color); Debug.AddRect(box, Color.Orange);
} }
Debug.AddLine(eyePos, Vector2.Add(eyePos, ray), Color.Red); Debug.AddLine(eyePos, Vector2.Add(eyePos, ray), Color.Red);