Compare commits

...

2 Commits

Author SHA1 Message Date
8ca79a1875 degrees aren't radians 2020-03-18 16:26:55 -04:00
0bb6f22f3d Geometry cleanups / TODO removal. 2020-03-18 16:18:39 -04:00

View File

@ -29,12 +29,12 @@ namespace SemiColinGames {
return degToRad[degrees];
}
public static float Sin(double degrees) {
return (float) Math.Sin(degrees);
public static float Sin(double radians) {
return (float) Math.Sin(radians);
}
public static float Cos(double degrees) {
return (float) Math.Cos(degrees);
public static float Cos(double radians) {
return (float) Math.Cos(radians);
}
public static T Clamp<T>(T value, T min, T max) where T : IComparable {
@ -139,7 +139,6 @@ namespace SemiColinGames {
return null;
}
// TODO: which of delta/normal/hitPos do we actually care about?
if (px < py) {
int sign = Math.Sign(dx);
Vector2 delta = new Vector2(px * sign, 0);
@ -185,14 +184,13 @@ namespace SemiColinGames {
Vector2 normal = nearTimeX > nearTimeY ?
new Vector2(-signX, 0) :
new Vector2(0, -signY);
// TODO: replace these with Vector2.Multiply (etc)
Vector2 hitDelta = new Vector2((1.0f - hitTime) * -delta.X, (1.0f - hitTime) * -delta.Y);
Vector2 hitPos = new Vector2(pos.X + delta.X * hitTime, pos.Y + delta.Y * hitTime);
Vector2 hitDelta = Vector2.Multiply(delta, -(1.0f - hitTime));
Vector2 hitPos = Vector2.Add(pos, Vector2.Multiply(delta, hitTime));
return new Hit(this, hitPos, hitDelta, normal, hitTime);
}
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) {
Hit? staticHit = Intersect(box);
// TODO: I don't understand the original source here, but I think this is correct.
@ -203,18 +201,16 @@ namespace SemiColinGames {
return new Sweep(null, Vector2.Add(box.Position, delta), 1);
}
Hit hit = (Hit) maybeHit;
Vector2 hitPos = new Vector2(
box.Position.X + delta.X * hit.Time,
box.Position.Y + delta.Y * hit.Time);
Vector2 direction = Vector2.Normalize(delta);
Vector2 hitPos = Vector2.Add(box.Position, Vector2.Multiply(delta, hit.Time));
// TODO: why is this calculation made, and then thrown away?
Vector2 sweepHitPos = new Vector2(
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.Y - HalfSize.Y,
Position.Y + HalfSize.Y));
// Vector2 direction = Vector2.Normalize(delta);
// Vector2 sweepHitPos = new Vector2(
// 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.Y - HalfSize.Y,
// Position.Y + HalfSize.Y));
return new Sweep(hit, hitPos, hit.Time);
}
}