Compare commits

..

No commits in common. "8ca79a1875bf4f837f43dc52b11a98c492e261d5" and "90ca6c4b58559c87561f555e5a380f19c504b0e1" have entirely different histories.

View File

@ -29,12 +29,12 @@ namespace SemiColinGames {
return degToRad[degrees];
}
public static float Sin(double radians) {
return (float) Math.Sin(radians);
public static float Sin(double degrees) {
return (float) Math.Sin(degrees);
}
public static float Cos(double radians) {
return (float) Math.Cos(radians);
public static float Cos(double degrees) {
return (float) Math.Cos(degrees);
}
public static T Clamp<T>(T value, T min, T max) where T : IComparable {
@ -139,6 +139,7 @@ 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);
@ -184,13 +185,14 @@ namespace SemiColinGames {
Vector2 normal = nearTimeX > nearTimeY ?
new Vector2(-signX, 0) :
new Vector2(0, -signY);
Vector2 hitDelta = Vector2.Multiply(delta, -(1.0f - hitTime));
Vector2 hitPos = Vector2.Add(pos, Vector2.Multiply(delta, hitTime));
// 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);
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.
@ -201,16 +203,18 @@ namespace SemiColinGames {
return new Sweep(null, Vector2.Add(box.Position, delta), 1);
}
Hit hit = (Hit) maybeHit;
Vector2 hitPos = Vector2.Add(box.Position, Vector2.Multiply(delta, hit.Time));
Vector2 hitPos = new Vector2(
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?
// 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));
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);
}
}