Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
GJKClosestPoint Class Reference

#include <GJKClosestPoint.h>

Inheritance diagram for GJKClosestPoint:
NonCopyable

Public Member Functions

template<typename A , typename B >
bool Intersects (const A &inA, const B &inB, float inTolerance, Vec3 &ioV)
 
template<typename A , typename B >
float GetClosestPoints (const A &inA, const B &inB, float inTolerance, float inMaxDistSq, Vec3 &ioV, Vec3 &outPointA, Vec3 &outPointB)
 
void GetClosestPointsSimplex (Vec3 *outY, Vec3 *outP, Vec3 *outQ, uint &outNumPoints) const
 
template<typename A >
bool CastRay (Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inTolerance, const A &inA, float &ioLambda)
 
template<typename A , typename B >
bool CastShape (Mat44Arg inStart, Vec3Arg inDirection, float inTolerance, const A &inA, const B &inB, float &ioLambda)
 
template<typename A , typename B >
bool CastShape (Mat44Arg inStart, Vec3Arg inDirection, float inTolerance, const A &inA, const B &inB, float inConvexRadiusA, float inConvexRadiusB, float &ioLambda, Vec3 &outPointA, Vec3 &outPointB, Vec3 &outSeparatingAxis)
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Detailed Description

Convex vs convex collision detection Based on: A Fast and Robust GJK Implementation for Collision Detection of Convex Objects - Gino van den Bergen

Member Function Documentation

◆ CastRay()

template<typename A >
bool GJKClosestPoint::CastRay ( Vec3Arg  inRayOrigin,
Vec3Arg  inRayDirection,
float  inTolerance,
const A &  inA,
float &  ioLambda 
)
inline

Test if a ray inRayOrigin + lambda * inRayDirection for lambda e [0, ioLambda> intersects inA

Code based upon: Ray Casting against General Convex Objects with Application to Continuous Collision Detection - Gino van den Bergen

Parameters
inRayOriginOrigin of the ray
inRayDirectionDirection of the ray (ioLambda * inDirection determines length)
inToleranceThe minimal distance between the ray and A before it is considered colliding
inAA convex object that has the GetSupport(Vec3) function
ioLambdaThe max fraction along the ray, on output updated with the actual collision fraction.
Returns
true if a hit was found, ioLambda is the solution for lambda.

◆ CastShape() [1/2]

template<typename A , typename B >
bool GJKClosestPoint::CastShape ( Mat44Arg  inStart,
Vec3Arg  inDirection,
float  inTolerance,
const A &  inA,
const B &  inB,
float &  ioLambda 
)
inline

Test if a cast shape inA moving from inStart to lambda * inStart.GetTranslation() + inDirection where lambda e [0, ioLambda> intersects inB

Parameters
inStartStart position and orientation of the convex object
inDirectionDirection of the sweep (ioLambda * inDirection determines length)
inToleranceThe minimal distance between A and B before they are considered colliding
inAThe convex object A, must support the GetSupport(Vec3) function.
inBThe convex object B, must support the GetSupport(Vec3) function.
ioLambdaThe max fraction along the sweep, on output updated with the actual collision fraction.
Returns
true if a hit was found, ioLambda is the solution for lambda.

◆ CastShape() [2/2]

template<typename A , typename B >
bool GJKClosestPoint::CastShape ( Mat44Arg  inStart,
Vec3Arg  inDirection,
float  inTolerance,
const A &  inA,
const B &  inB,
float  inConvexRadiusA,
float  inConvexRadiusB,
float &  ioLambda,
Vec3 outPointA,
Vec3 outPointB,
Vec3 outSeparatingAxis 
)
inline

Test if a cast shape inA moving from inStart to lambda * inStart.GetTranslation() + inDirection where lambda e [0, ioLambda> intersects inB

Parameters
inStartStart position and orientation of the convex object
inDirectionDirection of the sweep (ioLambda * inDirection determines length)
inToleranceThe minimal distance between A and B before they are considered colliding
inAThe convex object A, must support the GetSupport(Vec3) function.
inBThe convex object B, must support the GetSupport(Vec3) function.
inConvexRadiusAThe convex radius of A, this will be added on all sides to pad A.
inConvexRadiusBThe convex radius of B, this will be added on all sides to pad B.
ioLambdaThe max fraction along the sweep, on output updated with the actual collision fraction.
outPointAis the contact point on A (if outSeparatingAxis is near zero, this may not be not the deepest point)
outPointBis the contact point on B (if outSeparatingAxis is near zero, this may not be not the deepest point)
outSeparatingAxisOn return this will contain a vector that points from A to B along the smallest distance of separation. The length of this vector indicates the separation of A and B without their convex radius. If it is near zero, the direction may not be accurate as the bodies may overlap when lambda = 0.
Returns
true if a hit was found, ioLambda is the solution for lambda and outPoint and outSeparatingAxis are valid.

◆ GetClosestPoints()

template<typename A , typename B >
float GJKClosestPoint::GetClosestPoints ( const A &  inA,
const B &  inB,
float  inTolerance,
float  inMaxDistSq,
Vec3 ioV,
Vec3 outPointA,
Vec3 outPointB 
)
inline

Get closest points between inA and inB

Parameters
inAThe convex object A, must support the GetSupport(Vec3) function.
inBThe convex object B, must support the GetSupport(Vec3) function.
inToleranceThe minimal distance between A and B before the objects are considered colliding and processing is terminated.
inMaxDistSqThe maximum squared distance between A and B before the objects are considered infinitely far away and processing is terminated.
ioVInitial guess for the separating axis. Start with any non-zero vector if you don't know. If return value is 0, ioV = (0, 0, 0). If the return value is bigger than 0 but smaller than FLT_MAX, ioV will be the separating axis in the direction from A to B and its length the squared distance between A and B. If the return value is FLT_MAX, ioV will be the separating axis in the direction from A to B and the magnitude of the vector is meaningless.
outPointA,outPointBIf the return value is 0 the points are invalid. If the return value is bigger than 0 but smaller than FLT_MAX these will contain the closest point on A and B. If the return value is FLT_MAX the points are invalid.
Returns
The squared distance between A and B or FLT_MAX when they are further away than inMaxDistSq.

◆ GetClosestPointsSimplex()

void GJKClosestPoint::GetClosestPointsSimplex ( Vec3 outY,
Vec3 outP,
Vec3 outQ,
uint outNumPoints 
) const
inline

Get the resulting simplex after the GetClosestPoints algorithm finishes. If it returned a squared distance of 0, the origin will be contained in the simplex.

◆ Intersects()

template<typename A , typename B >
bool GJKClosestPoint::Intersects ( const A &  inA,
const B &  inB,
float  inTolerance,
Vec3 ioV 
)
inline

Test if inA and inB intersect

Parameters
inAThe convex object A, must support the GetSupport(Vec3) function.
inBThe convex object B, must support the GetSupport(Vec3) function.
inToleranceMinimal distance between objects when the objects are considered to be colliding
ioVis used as initial separating axis (provide a zero vector if you don't know yet)
Returns
True if they intersect (in which case ioV = (0, 0, 0)). False if they don't intersect in which case ioV is a separating axis in the direction from A to B (magnitude is meaningless)

The documentation for this class was generated from the following file: