Skip to content

Commit

Permalink
Rename SweepTest to Sweep and GJKEPA to Collision (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 authored Oct 5, 2024
1 parent 529c1e1 commit c3f720c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions src/Jitter2/Collision/NarrowPhase/NarrowPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public bool RayCast(in ISupportMappable supportA, in JVector origin, in JVector
return true;
}

public bool SweepTest(ref MinkowskiDifference mkd, in JVector sweep,
public bool Sweep(ref MinkowskiDifference mkd, in JVector sweep,
out JVector p1, out JVector p2, out JVector normal, out float fraction)
{
const float CollideEpsilon = 1e-4f;
Expand Down Expand Up @@ -596,7 +596,7 @@ public bool Overlap(in MinkowskiDifference mkd)
return true;
}

public bool SolveGJKEPA(in MinkowskiDifference mkd,
public bool Collision(in MinkowskiDifference mkd,
out JVector point1, out JVector point2, out JVector normal, out float penetration)
{
const float CollideEpsilon = 1e-4f;
Expand Down Expand Up @@ -778,7 +778,7 @@ public static bool RayCast(in ISupportMappable support, in JVector origin, in JV
/// failure, collision information reverts to the type's default values.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GJKEPA(in ISupportMappable supportA, in ISupportMappable supportB,
public static bool Collision(in ISupportMappable supportA, in ISupportMappable supportB,
in JQuaternion orientationB, in JVector positionB,
out JVector pointA, out JVector pointB, out JVector normal, out float penetration)
{
Expand All @@ -789,7 +789,7 @@ public static bool GJKEPA(in ISupportMappable supportA, in ISupportMappable supp
mkd.OrientationB = orientationB;

// ..perform collision detection..
bool success = solver.SolveGJKEPA(mkd, out pointA, out pointB, out normal, out penetration);
bool success = solver.Collision(mkd, out pointA, out pointB, out normal, out penetration);

return success;
}
Expand Down Expand Up @@ -824,7 +824,7 @@ public static bool GJKEPA(in ISupportMappable supportA, in ISupportMappable supp
/// failure, collision information reverts to the type's default values.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GJKEPA(in ISupportMappable supportA, in ISupportMappable supportB,
public static bool Collision(in ISupportMappable supportA, in ISupportMappable supportB,
in JQuaternion orientationA, in JQuaternion orientationB,
in JVector positionA, in JVector positionB,
out JVector pointA, out JVector pointB, out JVector normal, out float penetration)
Expand All @@ -839,7 +839,7 @@ public static bool GJKEPA(in ISupportMappable supportA, in ISupportMappable supp
JVector.ConjugatedTransform(mkd.PositionB, orientationA, out mkd.PositionB);

// ..perform collision detection..
bool success = solver.SolveGJKEPA(mkd, out pointA, out pointB, out normal, out penetration);
bool success = solver.Collision(mkd, out pointA, out pointB, out normal, out penetration);

// ..rotate back. this hopefully saves some matrix vector multiplication
// when calling the support function multiple times.
Expand Down Expand Up @@ -1071,7 +1071,7 @@ public static bool MPREPA(in ISupportMappable supportA, in ISupportMappable supp
/// <param name="fraction">Time of impact. Infinity if no hit is detected.</param>
/// <returns>True if the shapes hit, false otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SweepTest(in ISupportMappable supportA, in ISupportMappable supportB,
public static bool Sweep(in ISupportMappable supportA, in ISupportMappable supportB,
in JQuaternion orientationA, in JQuaternion orientationB,
in JVector positionA, in JVector positionB,
in JVector sweepA, in JVector sweepB,
Expand All @@ -1092,7 +1092,7 @@ public static bool SweepTest(in ISupportMappable supportA, in ISupportMappable s
JVector.ConjugatedTransform(sweep, orientationA, out sweep);

// ..perform toi calculation
bool res = solver.SweepTest(ref mkd, sweep, out pointA, out pointB, out normal, out fraction);
bool res = solver.Sweep(ref mkd, sweep, out pointA, out pointB, out normal, out fraction);

if (!res) return false;

Expand Down Expand Up @@ -1124,7 +1124,7 @@ public static bool SweepTest(in ISupportMappable supportA, in ISupportMappable s
/// <param name="fraction">Time of impact. Infinity if no hit is detected.</param>
/// <returns>True if the shapes hit, false otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SweepTest(in ISupportMappable supportA, in ISupportMappable supportB,
public static bool Sweep(in ISupportMappable supportA, in ISupportMappable supportB,
in JQuaternion orientationB, in JVector positionB, in JVector sweepB,
out JVector pointA, out JVector pointB, out JVector normal, out float fraction)
{
Expand All @@ -1136,6 +1136,6 @@ public static bool SweepTest(in ISupportMappable supportA, in ISupportMappable s
mkd.OrientationB = orientationB;

// ..perform toi calculation
return solver.SweepTest(ref mkd, sweepB, out pointA, out pointB, out normal, out fraction);
return solver.Sweep(ref mkd, sweepB, out pointA, out pointB, out normal, out fraction);
}
}
4 changes: 2 additions & 2 deletions src/Jitter2/World.Detect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private void Detect(IDynamicTreeProxy proxyA, IDynamicTreeProxy proxyB)

if (UseFullEPASolver)
{
bool success = NarrowPhase.GJKEPA(sA, sB, b1.Orientation, b2.Orientation, b1.Position, b2.Position,
bool success = NarrowPhase.Collision(sA, sB, b1.Orientation, b2.Orientation, b1.Position, b2.Position,
out pA, out pB, out normal, out penetration);

if (!success) return;
Expand All @@ -331,7 +331,7 @@ private void Detect(IDynamicTreeProxy proxyA, IDynamicTreeProxy proxyB)

if (dv.LengthSquared() < SpeculativeVelocityThreshold * SpeculativeVelocityThreshold) return;

bool success = NarrowPhase.SweepTest(sA, sB, b1.Orientation, b2.Orientation,
bool success = NarrowPhase.Sweep(sA, sB, b1.Orientation, b2.Orientation,
b1.Position, b2.Position,b1.Velocity, b2.Velocity,
out pA, out pB, out normal, out float toi);

Expand Down
6 changes: 3 additions & 3 deletions src/JitterTests/CollisionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void SweepTest()
var rot = JQuaternion.CreateRotationZ(MathF.PI / 4.0f);
var sweep = JVector.Normalize(new JVector(1, 1, 0));

bool hit = NarrowPhase.SweepTest(s1, s2, rot, rot,
bool hit = NarrowPhase.Sweep(s1, s2, rot, rot,
new JVector(1, 1, 3), new JVector(11, 11, 3),
sweep, -2.0f * sweep,
out JVector pA, out JVector pB, out JVector normal, out float fraction);
Expand Down Expand Up @@ -196,7 +196,7 @@ public void NormalDirection()

// -----------------------------------------------

NarrowPhase.GJKEPA(s1, s2, JQuaternion.Identity, JQuaternion.Identity, new JVector(-0.25f, 0, 0), new JVector(+0.25f, 0, 0),
NarrowPhase.Collision(s1, s2, JQuaternion.Identity, JQuaternion.Identity, new JVector(-0.25f, 0, 0), new JVector(+0.25f, 0, 0),
out pointA, out pointB, out normal, out penetration);

// pointA is on s1 and pointB is on s2
Expand Down Expand Up @@ -229,7 +229,7 @@ public void NormalDirection()

// -----------------------------------------------

NarrowPhase.GJKEPA(b1, b2, JQuaternion.Identity, JQuaternion.Identity, new JVector(-2.25f, 0, 0), new JVector(+2.25f, 0, 0),
NarrowPhase.Collision(b1, b2, JQuaternion.Identity, JQuaternion.Identity, new JVector(-2.25f, 0, 0), new JVector(+2.25f, 0, 0),
out pointA, out pointB, out normal, out penetration);

// the collision normal points from s2 to s1
Expand Down

0 comments on commit c3f720c

Please sign in to comment.