Geometry cleanups / TODO removal.

This commit is contained in:
Colin McMillen 2020-03-18 16:18:39 -04:00
parent 90ca6c4b58
commit 0bb6f22f3d

View File

@ -139,7 +139,6 @@ namespace SemiColinGames {
return null; return null;
} }
// TODO: which of delta/normal/hitPos do we actually care about?
if (px < py) { if (px < py) {
int sign = Math.Sign(dx); int sign = Math.Sign(dx);
Vector2 delta = new Vector2(px * sign, 0); Vector2 delta = new Vector2(px * sign, 0);
@ -185,14 +184,13 @@ namespace SemiColinGames {
Vector2 normal = nearTimeX > nearTimeY ? Vector2 normal = nearTimeX > nearTimeY ?
new Vector2(-signX, 0) : new Vector2(-signX, 0) :
new Vector2(0, -signY); new Vector2(0, -signY);
// TODO: replace these with Vector2.Multiply (etc) Vector2 hitDelta = Vector2.Multiply(delta, -(1.0f - hitTime));
Vector2 hitDelta = new Vector2((1.0f - hitTime) * -delta.X, (1.0f - hitTime) * -delta.Y); Vector2 hitPos = Vector2.Add(pos, Vector2.Multiply(delta, hitTime));
Vector2 hitPos = new Vector2(pos.X + delta.X * hitTime, pos.Y + delta.Y * hitTime);
return new Hit(this, hitPos, hitDelta, normal, hitTime); return new Hit(this, hitPos, hitDelta, normal, hitTime);
} }
public Sweep Sweep(AABB box, Vector2 delta) { public Sweep Sweep(AABB box, Vector2 delta) {
// fast-path case if the other box is static // Fast-path case if the other box is static.
if (delta.X == 0 && delta.Y == 0) { if (delta.X == 0 && delta.Y == 0) {
Hit? staticHit = Intersect(box); Hit? staticHit = Intersect(box);
// TODO: I don't understand the original source here, but I think this is correct. // TODO: I don't understand the original source here, but I think this is correct.
@ -203,19 +201,17 @@ namespace SemiColinGames {
return new Sweep(null, Vector2.Add(box.Position, delta), 1); return new Sweep(null, Vector2.Add(box.Position, delta), 1);
} }
Hit hit = (Hit) maybeHit; Hit hit = (Hit) maybeHit;
Vector2 hitPos = new Vector2( Vector2 hitPos = Vector2.Add(box.Position, Vector2.Multiply(delta, hit.Time));
box.Position.X + delta.X * hit.Time,
box.Position.Y + delta.Y * hit.Time);
Vector2 direction = Vector2.Normalize(delta);
// TODO: why is this calculation made, and then thrown away? // TODO: why is this calculation made, and then thrown away?
Vector2 sweepHitPos = new Vector2( // Vector2 direction = Vector2.Normalize(delta);
FMath.Clamp(hit.Position.X + direction.X * box.HalfSize.X, // Vector2 sweepHitPos = new Vector2(
Position.X - HalfSize.X, // FMath.Clamp(hit.Position.X + direction.X * box.HalfSize.X,
Position.X + HalfSize.X), // Position.X - HalfSize.X,
FMath.Clamp(hit.Position.Y + direction.Y * box.HalfSize.Y, // Position.X + HalfSize.X),
Position.Y - HalfSize.Y, // FMath.Clamp(hit.Position.Y + direction.Y * box.HalfSize.Y,
Position.Y + HalfSize.Y)); // Position.Y - HalfSize.Y,
// Position.Y + HalfSize.Y));
return new Sweep(hit, hitPos, hit.Time); return new Sweep(hit, hitPos, hit.Time);
} }
} }
} }