Box2D 3.1.0
A 2D physics engine for games
|
Functions for computing the distance between shapes. More...
Data Structures | |
struct | b2SegmentDistanceResult |
Result of computing the distance between two line segments. More... | |
struct | b2DistanceProxy |
A distance proxy is used by the GJK algorithm. It encapsulates any shape. More... | |
struct | b2DistanceCache |
Used to warm start b2Distance. More... | |
struct | b2DistanceInput |
Input for b2ShapeDistance. More... | |
struct | b2DistanceOutput |
Output for b2ShapeDistance. More... | |
struct | b2SimplexVertex |
Simplex vertex for debugging the GJK algorithm. More... | |
struct | b2Simplex |
Simplex from the GJK algorithm. More... | |
struct | b2ShapeCastPairInput |
Input parameters for b2ShapeCast. More... | |
struct | b2Sweep |
This describes the motion of a body/shape for TOI computation. More... | |
struct | b2TOIInput |
Input parameters for b2TimeOfImpact. More... | |
struct | b2TOIOutput |
Output parameters for b2TimeOfImpact. More... | |
Enumerations | |
enum | b2TOIState { b2_toiStateUnknown , b2_toiStateFailed , b2_toiStateOverlapped , b2_toiStateHit , b2_toiStateSeparated } |
Describes the TOI output. | |
Functions | |
b2SegmentDistanceResult | b2SegmentDistance (b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2) |
Compute the distance between two line segments, clamping at the end points if needed. | |
b2DistanceOutput | b2ShapeDistance (b2DistanceCache *cache, const b2DistanceInput *input, b2Simplex *simplexes, int simplexCapacity) |
Compute the closest points between two shapes represented as point clouds. | |
b2CastOutput | b2ShapeCast (const b2ShapeCastPairInput *input) |
Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction. | |
b2DistanceProxy | b2MakeProxy (const b2Vec2 *vertices, int32_t count, float radius) |
Make a proxy for use in GJK and related functions. | |
b2Transform | b2GetSweepTransform (const b2Sweep *sweep, float time) |
Evaluate the transform sweep at a specific time. | |
b2TOIOutput | b2TimeOfImpact (const b2TOIInput *input) |
Compute the upper bound on time before two shapes penetrate. | |
Functions for computing the distance between shapes.
These are advanced functions you can use to perform distance calculations. There are functions for computing the closest points between shapes, doing linear shape casts, and doing rotational shape casts. The latter is called time of impact (TOI).
struct b2SegmentDistanceResult |
Result of computing the distance between two line segments.
Data Fields | ||
---|---|---|
b2Vec2 | closest1 | The closest point on the first segment. |
b2Vec2 | closest2 | The closest point on the second segment. |
float | distanceSquared | The squared distance between the closest points. |
float | fraction1 | The barycentric coordinate on the first segment. |
float | fraction2 | The barycentric coordinate on the second segment. |
struct b2DistanceProxy |
A distance proxy is used by the GJK algorithm. It encapsulates any shape.
Data Fields | ||
---|---|---|
int32_t | count | The number of points. |
b2Vec2 | points[b2_maxPolygonVertices] | The point cloud. |
float | radius | The external radius of the point cloud. |
struct b2DistanceCache |
struct b2DistanceInput |
Input for b2ShapeDistance.
Data Fields | ||
---|---|---|
b2DistanceProxy | proxyA | The proxy for shape A. |
b2DistanceProxy | proxyB | The proxy for shape B. |
b2Transform | transformA | The world transform for shape A. |
b2Transform | transformB | The world transform for shape B. |
bool | useRadii | Should the proxy radius be considered? |
struct b2DistanceOutput |
Output for b2ShapeDistance.
Data Fields | ||
---|---|---|
float | distance | The final distance, zero if overlapped. |
int32_t | iterations | Number of GJK iterations used. |
b2Vec2 | pointA | Closest point on shapeA. |
b2Vec2 | pointB | Closest point on shapeB. |
int32_t | simplexCount | The number of simplexes stored in the simplex array. |
struct b2SimplexVertex |
struct b2Simplex |
Simplex from the GJK algorithm.
Data Fields | ||
---|---|---|
int32_t | count | number of valid vertices |
b2SimplexVertex | v1 | |
b2SimplexVertex | v2 | |
b2SimplexVertex | v3 | vertices |
struct b2ShapeCastPairInput |
Input parameters for b2ShapeCast.
Data Fields | ||
---|---|---|
float | maxFraction | The fraction of the translation to consider, typically 1. |
b2DistanceProxy | proxyA | The proxy for shape A. |
b2DistanceProxy | proxyB | The proxy for shape B. |
b2Transform | transformA | The world transform for shape A. |
b2Transform | transformB | The world transform for shape B. |
b2Vec2 | translationB | The translation of shape B. |
struct b2Sweep |
This describes the motion of a body/shape for TOI computation.
Shapes are defined with respect to the body origin, which may not coincide with the center of mass. However, to support dynamics we must interpolate the center of mass position.
Data Fields | ||
---|---|---|
b2Vec2 | c1 | Starting center of mass world position. |
b2Vec2 | c2 | Ending center of mass world position. |
b2Vec2 | localCenter | Local center of mass position. |
b2Rot | q1 | Starting world rotation. |
b2Rot | q2 | Ending world rotation. |
struct b2TOIInput |
Input parameters for b2TimeOfImpact.
Data Fields | ||
---|---|---|
b2DistanceProxy | proxyA | The proxy for shape A. |
b2DistanceProxy | proxyB | The proxy for shape B. |
b2Sweep | sweepA | The movement of shape A. |
b2Sweep | sweepB | The movement of shape B. |
float | tMax | Defines the sweep interval [0, tMax]. |
struct b2TOIOutput |
Output parameters for b2TimeOfImpact.
Data Fields | ||
---|---|---|
b2TOIState | state | The type of result. |
float | t | The time of the collision. |
b2DistanceOutput b2ShapeDistance | ( | b2DistanceCache * | cache, |
const b2DistanceInput * | input, | ||
b2Simplex * | simplexes, | ||
int | simplexCapacity ) |
Compute the closest points between two shapes represented as point clouds.
b2DistanceCache cache is input/output. On the first call set b2DistanceCache.count to zero. The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
b2TOIOutput b2TimeOfImpact | ( | const b2TOIInput * | input | ) |
Compute the upper bound on time before two shapes penetrate.
Time is represented as a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, non-tunneling collisions. If you change the time interval, you should call this function again.