Compare commits
No commits in common. "8ca79a1875bf4f837f43dc52b11a98c492e261d5" and "90ca6c4b58559c87561f555e5a380f19c504b0e1" have entirely different histories.
8ca79a1875
...
90ca6c4b58
@ -29,12 +29,12 @@ namespace SemiColinGames {
|
|||||||
return degToRad[degrees];
|
return degToRad[degrees];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float Sin(double radians) {
|
public static float Sin(double degrees) {
|
||||||
return (float) Math.Sin(radians);
|
return (float) Math.Sin(degrees);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float Cos(double radians) {
|
public static float Cos(double degrees) {
|
||||||
return (float) Math.Cos(radians);
|
return (float) Math.Cos(degrees);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Clamp<T>(T value, T min, T max) where T : IComparable {
|
public static T Clamp<T>(T value, T min, T max) where T : IComparable {
|
||||||
@ -139,6 +139,7 @@ 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);
|
||||||
@ -184,13 +185,14 @@ 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);
|
||||||
Vector2 hitDelta = Vector2.Multiply(delta, -(1.0f - hitTime));
|
// TODO: replace these with Vector2.Multiply (etc)
|
||||||
Vector2 hitPos = Vector2.Add(pos, Vector2.Multiply(delta, hitTime));
|
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);
|
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.
|
||||||
@ -201,16 +203,18 @@ 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 = 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?
|
// TODO: why is this calculation made, and then thrown away?
|
||||||
// Vector2 direction = Vector2.Normalize(delta);
|
Vector2 sweepHitPos = new Vector2(
|
||||||
// Vector2 sweepHitPos = new Vector2(
|
FMath.Clamp(hit.Position.X + direction.X * box.HalfSize.X,
|
||||||
// FMath.Clamp(hit.Position.X + direction.X * box.HalfSize.X,
|
Position.X - HalfSize.X,
|
||||||
// Position.X - HalfSize.X,
|
Position.X + HalfSize.X),
|
||||||
// Position.X + HalfSize.X),
|
FMath.Clamp(hit.Position.Y + direction.Y * box.HalfSize.Y,
|
||||||
// FMath.Clamp(hit.Position.Y + direction.Y * box.HalfSize.Y,
|
Position.Y - 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user