Class NarrowPhase
Tests convex shapes for overlap, distance, ray hits, and swept collisions.
public static class NarrowPhase
- Inheritance
-
NarrowPhase
- Inherited Members
Remarks
Shapes are supplied through ISupportMappable. Queries may run on separate threads if the supplied shapes can be read concurrently and are not modified during the queries.
Methods
Collision<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float)
Calculates contact points and signed penetration for two convex shapes, including separated shapes. All output coordinates are in world space.
public static bool Collision<Ta, Tb>(in Ta supportA, in Tb 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) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationAJQuaternionThe orientation of shape A in world space.
orientationBJQuaternionThe orientation of shape B in world space.
positionAJVectorThe position of shape A in world space.
positionBJVectorThe position of shape B in world space.
pointAJVectorFor the overlapping case: the deepest point on shape A inside shape B; for the separated case: the closest point on shape A to shape B.
pointBJVectorFor the overlapping case: the deepest point on shape B inside shape A; for the separated case: the closest point on shape B to shape A.
normalJVectorThe unit collision normal, pointing from shape A toward shape B. The signed penetration is its dot product with pointA - pointB. Moving shape B by penetration times the normal makes the shapes touch, both when they overlap and when they are separated. It remains defined when the points coincide.
penetrationfloatSigned penetration depth: positive for overlap, negative for separation.
Returns
- bool
trueif collision information was calculated, including for separated shapes;falseif the search failed. Only use the outputs when the result istrue.
Type Parameters
TaTb
Collision<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JVector, out JVector, out JVector, out JVector, out float)
Calculates contact points and signed penetration for two convex shapes, including separated shapes. Shape A is at the origin with identity orientation; all coordinates use its local frame.
public static bool Collision<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationB, in JVector positionB, out JVector pointA, out JVector pointB, out JVector normal, out float penetration) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationBJQuaternionThe orientation of shape B.
positionBJVectorThe position of shape B.
pointAJVectorFor the overlapping case: the deepest point on shape A inside shape B; for the separated case: the closest point on shape A to shape B.
pointBJVectorFor the overlapping case: the deepest point on shape B inside shape A; for the separated case: the closest point on shape B to shape A.
normalJVectorThe unit collision normal, pointing from shape A toward shape B. The signed penetration is its dot product with pointA - pointB. Moving shape B by penetration times the normal makes the shapes touch, both when they overlap and when they are separated. It remains defined when the points coincide.
penetrationfloatSigned penetration depth: positive for overlap, negative for separation.
Returns
- bool
trueif collision information was calculated, including for separated shapes;falseif the search failed. Only use the outputs when the result istrue.
Type Parameters
TaTb
Distance<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float)
Calculates the distance and closest points between separated shapes in world space.
public static bool Distance<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationA, in JQuaternion orientationB, in JVector positionA, in JVector positionB, out JVector pointA, out JVector pointB, out JVector normal, out float distance) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationAJQuaternionThe orientation of shape A in world space.
orientationBJQuaternionThe orientation of shape B in world space.
positionAJVectorThe position of shape A in world space.
positionBJVectorThe position of shape B in world space.
pointAJVectorClosest point on shape A. Undefined for the overlapping case.
pointBJVectorClosest point on shape B. Undefined for the overlapping case.
normalJVectorUnit direction from shape A toward shape B. Undefined for the overlapping case.
distancefloatThe distance between the separating shapes. Zero if shapes overlap.
Returns
- bool
Returns true if the shapes do not overlap and distance information can be provided.
Type Parameters
TaTb
Distance<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JVector, out JVector, out JVector, out JVector, out float)
Calculates the distance and closest points between separated shapes. Shape A is at the origin with identity orientation; all coordinates use its local frame.
public static bool Distance<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationB, in JVector positionB, out JVector pointA, out JVector pointB, out JVector normal, out float distance) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationBJQuaternionThe orientation of shape B in shape A's local frame.
positionBJVectorThe position of shape B in shape A's local frame.
pointAJVectorClosest point on shape A. Undefined for the overlapping case.
pointBJVectorClosest point on shape B. Undefined for the overlapping case.
normalJVectorUnit direction from shape A toward shape B. Undefined for the overlapping case.
distancefloatThe distance between the separating shapes. Zero if shapes overlap.
Returns
- bool
Returns true if the shapes do not overlap and distance information can be provided.
Type Parameters
TaTb
MprEpa<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float, float)
Tests overlap and returns contact points, a normal, and estimated penetration in world space.
Uses MPR, with EPA refinement for penetrations exceeding epaThreshold.
public static bool MprEpa<Ta, Tb>(in Ta supportA, in Tb 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, float epaThreshold = 0.02) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationAJQuaternionThe orientation of shape A in world space.
orientationBJQuaternionThe orientation of shape B in world space.
positionAJVectorThe position of shape A in world space.
positionBJVectorThe position of shape B in world space.
pointAJVectorThe deepest point on shape A that is inside shape B.
pointBJVectorThe deepest point on shape B that is inside shape A.
normalJVectorUnit normal pointing from shape A toward shape B. Moving shape B along it separates the shapes. Remains defined when the points coincide.
penetrationfloatThe penetration depth.
epaThresholdfloatPenetration depth threshold above which MPR results are refined with EPA.
Returns
- bool
Returns true if the shapes overlap (collide), and false otherwise.
Type Parameters
TaTb
MprEpa<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JVector, out JVector, out JVector, out JVector, out float, float)
Tests overlap and returns contact points, a normal, and estimated penetration.
Shape A is at the origin with identity orientation; all coordinates use its local frame.
Uses MPR, with EPA refinement for penetrations exceeding epaThreshold.
public static bool MprEpa<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationB, in JVector positionB, out JVector pointA, out JVector pointB, out JVector normal, out float penetration, float epaThreshold = 0.02) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationBJQuaternionThe orientation of shape B.
positionBJVectorThe position of shape B.
pointAJVectorThe deepest point on shape A that is inside shape B.
pointBJVectorThe deepest point on shape B that is inside shape A.
normalJVectorUnit normal pointing from shape A toward shape B. Moving shape B along it separates the shapes. Remains defined when the points coincide.
penetrationfloatThe penetration depth.
epaThresholdfloatPenetration depth threshold above which MPR results are refined with EPA.
Returns
- bool
Returns true if the shapes overlap (collide), and false otherwise.
Type Parameters
TaTb
Overlap<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector)
Performs an overlap test.
public static bool Overlap<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationA, in JQuaternion orientationB, in JVector positionA, in JVector positionB) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationAJQuaternionThe orientation of shape A in world space.
orientationBJQuaternionThe orientation of shape B in world space.
positionAJVectorThe position of shape A in world space.
positionBJVectorThe position of shape B in world space.
Returns
- bool
trueif the shapes overlap; otherwise,false.
Type Parameters
TaTb
Overlap<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JVector)
Tests whether two convex shapes overlap. Shape A is at the origin with identity orientation.
public static bool Overlap<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationB, in JVector positionB) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaThe support function of shape A.
supportBTbThe support function of shape B.
orientationBJQuaternionThe orientation of shape B in shape A's local frame.
positionBJVectorThe position of shape B in shape A's local frame.
Returns
- bool
trueif the shapes overlap; otherwise,false.
Type Parameters
TaTb
PointTest<Ta>(in Ta, in JMatrix, in JVector, in JVector)
Check if a point is inside a shape.
public static bool PointTest<Ta>(in Ta support, in JMatrix orientation, in JVector position, in JVector point) where Ta : ISupportMappable
Parameters
supportTaSupport map representing the shape.
orientationJMatrixOrientation of the shape.
positionJVectorPosition of the shape.
pointJVectorPoint to check.
Returns
- bool
Returns true if the point is contained within the shape, false otherwise.
Type Parameters
Ta
PointTest<Ta>(in Ta, in JVector)
Check if a point is inside a shape.
public static bool PointTest<Ta>(in Ta support, in JVector point) where Ta : ISupportMappable
Parameters
supportTaSupport map representing the shape.
pointJVectorPoint to check.
Returns
- bool
Returns true if the point is contained within the shape, false otherwise.
Type Parameters
Ta
RayCast<Ta>(in Ta, in JQuaternion, in JVector, in JVector, in JVector, out float, out JVector)
Performs a ray cast against a shape.
public static bool RayCast<Ta>(in Ta support, in JQuaternion orientation, in JVector position, in JVector origin, in JVector direction, out float lambda, out JVector normal) where Ta : ISupportMappable
Parameters
supportTaThe support function of the shape.
orientationJQuaternionThe orientation of the shape in world space.
positionJVectorThe position of the shape in world space.
originJVectorThe origin of the ray.
directionJVectorThe direction of the ray; normalization is not necessary.
lambdafloatSpecifies the hit point of the ray, calculated as 'origin + lambda * direction'. Zero if the origin is inside the shape, PositiveInfinity if the ray does not hit.
normalJVectorThe normalized normal vector perpendicular to the surface, pointing outwards. Zero if the ray does not hit or the ray origin is inside the shape.
Returns
- bool
Returns true if the ray intersects with the shape; otherwise, false.
Type Parameters
Ta
RayCast<Ta>(in Ta, in JVector, in JVector, out float, out JVector)
Performs a ray cast against a shape.
public static bool RayCast<Ta>(in Ta support, in JVector origin, in JVector direction, out float lambda, out JVector normal) where Ta : ISupportMappable
Parameters
supportTaThe support function of the shape.
originJVectorThe origin of the ray.
directionJVectorThe direction of the ray; normalization is not necessary.
lambdafloatSpecifies the hit point of the ray, calculated as 'origin + lambda * direction'. Zero if the origin is inside the shape, PositiveInfinity if the ray does not hit.
normalJVectorThe normalized normal vector perpendicular to the surface, pointing outwards. Zero if the ray does not hit or the ray origin is inside the shape.
Returns
- bool
Returns true if the ray intersects with the shape; otherwise, false.
Type Parameters
Ta
Sweep<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, in JVector, in JVector, out JVector, out JVector, out JVector, out float)
Calculates the time of impact and the collision points in world space for two shapes with linear velocities
sweepA and sweepB.
public static bool Sweep<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationA, in JQuaternion orientationB, in JVector positionA, in JVector positionB, in JVector sweepA, in JVector sweepB, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaShape A.
supportBTbShape B.
orientationAJQuaternionOrientation of shape A in world space.
orientationBJQuaternionOrientation of shape B in world space.
positionAJVectorPosition of shape A in world space.
positionBJVectorPosition of shape B in world space.
sweepAJVectorLinear velocity of shape A.
sweepBJVectorLinear velocity of shape B.
pointAJVectorCollision point on shape A in world space at the sweep origin.
pointBJVectorCollision point on shape B in world space at the sweep origin.
normalJVectorNormalized collision normal in world space (points from A to B). Zero if the shapes already overlap or do not hit.
lambdafloatTime of impact. PositiveInfinity if no hit is detected, zero if shapes overlap.
Returns
- bool
True if the shapes will hit or already overlap, false otherwise.
Type Parameters
TaTb
Sweep<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, in JVector, in JVector, in JVector, in JVector, in float, in float, out JVector, out JVector, out JVector, out float)
Calculates the time of impact for two translating and rotating convex shapes.
public static bool Sweep<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationA, in JQuaternion orientationB, in JVector positionA, in JVector positionB, in JVector sweepA, in JVector sweepB, in JVector sweepAngularA, in JVector sweepAngularB, in float extentA, in float extentB, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaShape A.
supportBTbShape B.
orientationAJQuaternionInitial orientation of shape A in world space.
orientationBJQuaternionInitial orientation of shape B in world space.
positionAJVectorInitial position of shape A in world space.
positionBJVectorInitial position of shape B in world space.
sweepAJVectorLinear velocity of shape A.
sweepBJVectorLinear velocity of shape B.
sweepAngularAJVectorWorld-space angular velocity of shape A.
sweepAngularBJVectorWorld-space angular velocity of shape B.
extentAfloatRadius enclosing shape A about its rotation origin, including any local offset.
extentBfloatRadius enclosing shape B about its rotation origin, including any local offset.
pointAJVectorCollision point on shape A in world space at the sweep origin.
pointBJVectorCollision point on shape B in world space at the sweep origin.
normalJVectorUnit normal from A to B at impact. Zero for initial overlap or an unsuccessful search.
lambdafloatTime of impact in seconds; zero for initial overlap, infinity for an unsuccessful search.
Returns
- bool
True if an impact is found. False if the shapes miss or the search fails.
Type Parameters
TaTb
Remarks
Prefer the overload with a maximum time and a NarrowPhase.SweepStatus result when sweeping a simulation step. An unbounded search may fail to finish, especially when both shapes rotate without relative translation.
Sweep<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JQuaternion, in JVector, in JVector, in JVector, in JVector, in JVector, in JVector, in float, in float, float, out JVector, out JVector, out JVector, out float)
Searches for the first impact of two translating and rotating convex shapes between zero and
maximumTime seconds, including both endpoints.
public static NarrowPhase.SweepStatus Sweep<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationA, in JQuaternion orientationB, in JVector positionA, in JVector positionB, in JVector sweepA, in JVector sweepB, in JVector sweepAngularA, in JVector sweepAngularB, in float extentA, in float extentB, float maximumTime, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaShape A.
supportBTbShape B.
orientationAJQuaternionInitial orientation of shape A in world space.
orientationBJQuaternionInitial orientation of shape B in world space.
positionAJVectorInitial position of shape A in world space.
positionBJVectorInitial position of shape B in world space.
sweepAJVectorLinear velocity of shape A.
sweepBJVectorLinear velocity of shape B.
sweepAngularAJVectorWorld-space angular velocity of shape A.
sweepAngularBJVectorWorld-space angular velocity of shape B.
extentAfloatRadius enclosing shape A about its rotation origin, including any local offset.
extentBfloatRadius enclosing shape B about its rotation origin, including any local offset.
maximumTimefloatNonnegative last time to search. Positive infinity requests an unbounded search.
pointAJVectorCollision point on shape A in world space at the sweep origin. Zero unless a hit is found.
pointBJVectorCollision point on shape B in world space at the sweep origin. Zero unless a hit is found.
normalJVectorUnit normal from A to B at impact. Zero for initial overlap or an unsuccessful search.
lambdafloatTime of impact in seconds; zero for initial overlap, infinity unless a hit is found.
Returns
- NarrowPhase.SweepStatus
Whether an impact was found, separation was proven, or the search could not finish.
Type Parameters
TaTb
Remarks
Includes impacts occurring between separated endpoint poses. A hit is reported within a distance tolerance of 0.0001. Iteration exhaustion is reported as Failed rather than a collision or a proven miss.
Sweep<Ta, Tb>(in Ta, in Tb, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float)
Performs a sweep test where shape A is fixed at the origin with identity orientation and zero velocity.
public static bool Sweep<Ta, Tb>(in Ta supportA, in Tb supportB, in JQuaternion orientationB, in JVector positionB, in JVector sweepB, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where Ta : ISupportMappable where Tb : ISupportMappable
Parameters
supportATaShape A (fixed at the origin, identity orientation).
supportBTbShape B.
orientationBJQuaternionOrientation of shape B in world space.
positionBJVectorPosition of shape B in world space.
sweepBJVectorLinear velocity of shape B.
pointAJVectorCollision point on shape A in world space at the sweep origin.
pointBJVectorCollision point on shape B in world space at the sweep origin.
normalJVectorNormalized collision normal in world space (points from A to B). Zero if the shapes already overlap or do not hit.
lambdafloatTime of impact. PositiveInfinity if no hit is detected, zero if shapes overlap.
Returns
- bool
True if the shapes hit or already overlap, false otherwise.
Type Parameters
TaTb