Skip to content

Commit

Permalink
Feeding a better initial penetration axis to GJK to improve performan…
Browse files Browse the repository at this point in the history
…ce (#41)
  • Loading branch information
jrouwe committed Feb 5, 2022
1 parent 0e3f28e commit 6aa0465
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Jolt/Physics/Collision/CollideConvexVsTriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ void CollideConvexVsTriangles::Collide(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2,
TriangleConvexSupport triangle(v0, v1, v2);

// Perform collision detection
Vec3 penetration_axis = Vec3::sAxisX(), point1, point2;
// Note: As we don't remember the penetration axis from the last iteration, and it is likely that the shape (A) we're colliding the triangle (B) against is in front of the triangle,
// and the penetration axis is the shortest distance along to push B out of collision, we use the inverse of the triangle normal as an initial penetration axis. This has been seen
// to improve performance by approx. 5% over using a fixed axis like (1, 0, 0).
Vec3 penetration_axis = -triangle_normal, point1, point2;
EPAPenetrationDepth pen_depth;
EPAPenetrationDepth::EStatus status;

Expand Down
5 changes: 4 additions & 1 deletion Jolt/Physics/Collision/Shape/ConvexShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ void ConvexShape::sCollideConvexVsConvex(const Shape *inShape1, const Shape *inS
if (!OrientedBox(transform_2_to_1, shape2_bbox).Overlaps(shape1_bbox))
return;

Vec3 penetration_axis = Vec3::sAxisX(), point1, point2;
// Note: As we don't remember the penetration axis from the last iteration, and it is likely that shape2 is pushed out of
// collision relative to shape1 by comparing their COM's, we use that as an initial penetration axis: shape2.com - shape1.com
// This has been seen to improve performance by approx. 1% over using a fixed axis like (1, 0, 0).
Vec3 penetration_axis = transform_2_to_1.GetTranslation(), point1, point2;
EPAPenetrationDepth pen_depth;
EPAPenetrationDepth::EStatus status;

Expand Down

0 comments on commit 6aa0465

Please sign in to comment.