Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches
collision.h
1// SPDX-FileCopyrightText: 2026 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "base.h"
7#include "math_types.h"
8
9#include <stdbool.h>
10
11typedef struct b2SimplexCache b2SimplexCache;
12typedef struct b2Hull b2Hull;
13
23
26#define B2_MAX_POLYGON_VERTICES 8
27
40
54
73
76typedef struct b2CastOutput
77{
80
83
85 float fraction;
86
89
91 bool hit;
93
94#if defined( BOX2D_DOUBLE_PRECISION )
95
97typedef struct b2WorldCastOutput
98{
99 b2Vec2 normal;
100 b2Pos point;
101 float fraction;
102 int iterations;
103 bool hit;
105
106#else
107
110
111#endif
112
114typedef struct b2MassData
115{
117 float mass;
118
121
124} b2MassData;
125
127typedef struct b2Circle
128{
131
133 float radius;
134} b2Circle;
135
137typedef struct b2Capsule
138{
141
144
146 float radius;
147} b2Capsule;
148
171
173typedef struct b2Segment
174{
177
180} b2Segment;
181
199
201B2_API bool b2IsValidRay( const b2RayCastInput* input );
202
205B2_API b2Polygon b2MakePolygon( const b2Hull* hull, float radius );
206
209B2_API b2Polygon b2MakeOffsetPolygon( const b2Hull* hull, b2Vec2 position, b2Rot rotation );
210
214B2_API b2Polygon b2MakeOffsetRoundedPolygon( const b2Hull* hull, b2Vec2 position, b2Rot rotation,
215 float radius );
216
219B2_API b2Polygon b2MakeSquare( float halfWidth );
220
224B2_API b2Polygon b2MakeBox( float halfWidth, float halfHeight );
225
230B2_API b2Polygon b2MakeRoundedBox( float halfWidth, float halfHeight, float radius );
231
237B2_API b2Polygon b2MakeOffsetBox( float halfWidth, float halfHeight, b2Vec2 center,
238 b2Rot rotation );
239
246B2_API b2Polygon b2MakeOffsetRoundedBox( float halfWidth, float halfHeight, b2Vec2 center,
247 b2Rot rotation, float radius );
248
250B2_API b2Polygon b2TransformPolygon( b2Transform transform, const b2Polygon* polygon );
251
253B2_API b2MassData b2ComputeCircleMass( const b2Circle* shape, float density );
254
256B2_API b2MassData b2ComputeCapsuleMass( const b2Capsule* shape, float density );
257
259B2_API b2MassData b2ComputePolygonMass( const b2Polygon* shape, float density );
260
262B2_API b2AABB b2ComputeCircleBounds( const b2Circle* shape, b2WorldTransform transform );
263
265B2_API b2AABB b2ComputeCapsuleBounds( const b2Capsule* shape, b2WorldTransform transform );
266
268B2_API b2AABB b2ComputePolygonBounds( const b2Polygon* shape, b2WorldTransform transform );
269
271B2_API b2AABB b2ComputeSegmentBounds( const b2Segment* shape, b2WorldTransform transform );
272
274B2_API bool b2PointInCircle( const b2Circle* shape, b2Vec2 point );
275
277B2_API bool b2PointInCapsule( const b2Capsule* shape, b2Vec2 point );
278
280B2_API bool b2PointInPolygon( const b2Polygon* shape, b2Vec2 point );
281
283B2_API b2CastOutput b2CastRayCircle( const b2Circle* shape, const b2RayCastInput* input );
284
286B2_API b2CastOutput b2CastRayCapsule( const b2Capsule* shape, const b2RayCastInput* input );
287
290B2_API b2CastOutput b2CastRaySegment( const b2Segment* shape, const b2RayCastInput* input,
291 bool oneSided );
292
294B2_API b2CastOutput b2CastRayPolygon( const b2Polygon* shape, const b2RayCastInput* input );
295
297B2_API b2CastOutput b2CastShapeCircle( const b2Circle* shape, const b2ShapeCastInput* input );
298
300B2_API b2CastOutput b2CastShapeCapsule( const b2Capsule* shape, const b2ShapeCastInput* input );
301
303B2_API b2CastOutput b2CastShapeSegment( const b2Segment* shape, const b2ShapeCastInput* input );
304
306B2_API b2CastOutput b2CastShapePolygon( const b2Polygon* shape, const b2ShapeCastInput* input );
307
310typedef struct b2Hull
311{
314
316 int count;
317} b2Hull;
318
328B2_API b2Hull b2ComputeHull( const b2Vec2* points, int count );
329
335B2_API bool b2ValidateHull( const b2Hull* hull );
336
338
348
367
370 b2Vec2 q2 );
371
375typedef struct b2SimplexCache
376{
378 uint16_t count;
379
381 uint8_t indexA[3];
382
384 uint8_t indexB[3];
386
387static const b2SimplexCache b2_emptySimplexCache = B2_ZERO_INIT;
388
405
416
427
429typedef struct b2Simplex
430{
432 int count;
433} b2Simplex;
434
440 b2Simplex* simplexes, int simplexCapacity );
441
452
457
460B2_API b2ShapeProxy b2MakeProxy( const b2Vec2* points, int count, float radius );
461
463B2_API b2ShapeProxy b2MakeOffsetProxy( const b2Vec2* points, int count, float radius,
464 b2Vec2 position, b2Rot rotation );
465
477
479B2_API b2Transform b2GetSweepTransform( const b2Sweep* sweep, float time );
480
490
492typedef enum b2TOIState
493{
494 b2_toiStateUnknown,
495 b2_toiStateFailed,
496 b2_toiStateOverlapped,
497 b2_toiStateHit,
498 b2_toiStateSeparated
499} b2TOIState;
500
516
521
523
532
537typedef struct b2ManifoldPoint
538{
543
546
549
552
555
560
565
568
570 uint16_t id;
571
575
578typedef struct b2Manifold
579{
582
585
588
591
592} b2Manifold;
593
596{
599
602
604 uint16_t id;
606
620
622B2_API b2LocalManifold b2CollideCircles( const b2Circle* circleA, const b2Circle* circleB,
623 b2Transform xf );
624
627 const b2Circle* circleB, b2Transform xf );
628
631 const b2Circle* circleB, b2Transform xf );
632
635 const b2Circle* circleB, b2Transform xf );
636
638B2_API b2LocalManifold b2CollideCapsules( const b2Capsule* capsuleA, const b2Capsule* capsuleB,
639 b2Transform xf );
640
643 const b2Capsule* capsuleB, b2Transform xf );
644
647 const b2Capsule* capsuleB, b2Transform xf );
648
650B2_API b2LocalManifold b2CollidePolygons( const b2Polygon* polygonA, const b2Polygon* polygonB,
651 b2Transform xf );
652
655 const b2Polygon* polygonB, b2Transform xf );
656
659 const b2Circle* circleB, b2Transform xf );
660
663 const b2Capsule* capsuleB, b2Transform xf,
664 b2SimplexCache* cache );
665
668 const b2Polygon* polygonB, b2Transform xf,
669 b2SimplexCache* cache );
670
672
688
691
693typedef struct b2TreeStats
694{
697
701
703B2_API b2DynamicTree* b2CreateDynamicTree( int proxyCapacity );
704
707
709B2_API int b2CreateTreeProxy( b2DynamicTree* tree, b2AABB aabb, uint64_t categoryBits,
710 uint64_t userData );
711
713B2_API void b2DestroyTreeProxy( b2DynamicTree* tree, int proxyId );
714
716B2_API void b2DynamicTree_MoveProxy( b2DynamicTree* tree, int proxyId, b2AABB aabb );
717
719B2_API void b2DynamicTree_SetCategoryBits( b2DynamicTree* tree, int proxyId,
720 uint64_t categoryBits );
721
723B2_API uint64_t b2DynamicTree_GetCategoryBits( b2DynamicTree* tree, int proxyId );
724
727typedef bool b2TreeQueryCallbackFcn( int proxyId, uint64_t userData, void* context );
728
733 uint64_t maskBits, b2TreeQueryCallbackFcn* callback,
734 void* context );
735
740 b2TreeQueryCallbackFcn* callback, void* context );
741
747typedef float b2TreeRayCastCallbackFcn( const b2RayCastInput* input, int proxyId, uint64_t userData,
748 void* context );
749
763 uint64_t maskBits, b2TreeRayCastCallbackFcn* callback,
764 void* context );
765
778
784typedef float b2TreeBoxCastCallbackFcn( const b2BoxCastInput* input, int proxyId, uint64_t userData,
785 void* context );
786
797 uint64_t maskBits, b2TreeBoxCastCallbackFcn* callback,
798 void* context );
799
801B2_API int b2DynamicTree_GetHeight( const b2DynamicTree* tree );
802
804B2_API float b2DynamicTree_GetAreaRatio( const b2DynamicTree* tree );
805
808
811
813B2_API size_t b2DynamicTree_GetByteCount( const b2DynamicTree* tree );
814
816B2_API uint64_t b2DynamicTree_GetUserData( const b2DynamicTree* tree, int proxyId );
817
819B2_API b2AABB b2DynamicTree_GetProxyBounds( const b2DynamicTree* tree, int proxyId );
820
822B2_API void b2DynamicTree_Validate( const b2DynamicTree* tree );
823
825
831
834typedef struct b2PlaneResult
835{
838
841
843 bool hit;
845
848typedef struct b2CollisionPlane
849{
852
856
858 float push;
859
864
874
880B2_API b2PlaneSolverResult b2SolvePlanes( b2Vec2 targetDelta, b2CollisionPlane* planes, int count );
881
884B2_API b2Vec2 b2ClipVector( b2Vec2 vector, const b2CollisionPlane* planes, int count );
885
float push
The push on the mover determined by b2SolvePlanes. Usually in meters.
Definition collision.h:858
b2Vec2 point
The collision point on the shape.
Definition collision.h:840
bool clipVelocity
Indicates if b2ClipVector should clip against this plane.
Definition collision.h:862
b2Plane plane
The collision plane between the mover and a convex shape.
Definition collision.h:837
bool hit
Did the collision register a hit? If not this plane should be ignored.
Definition collision.h:843
b2Vec2 delta
The final relative translation.
Definition collision.h:869
float pushLimit
Setting this to FLT_MAX makes the plane as rigid as possible.
Definition collision.h:855
b2Plane plane
The collision plane between the mover and some shape.
Definition collision.h:851
int iterationCount
The number of iterations used by the plane solver. For diagnostics.
Definition collision.h:872
b2Vec2 b2ClipVector(b2Vec2 vector, const b2CollisionPlane *planes, int count)
Clips the velocity against the given collision planes.
b2PlaneSolverResult b2SolvePlanes(b2Vec2 targetDelta, b2CollisionPlane *planes, int count)
Solves the position of a mover that satisfies the given collision planes.
These are collision planes that can be fed to b2SolvePlanes.
Definition collision.h:849
These are the collision planes returned from b2World_CollideMover.
Definition collision.h:835
Result returned by b2SolvePlanes.
Definition collision.h:867
float separation
The separation of the contact point, negative if penetrating. May be positive or negative.
Definition collision.h:601
float normalImpulse
The impulse along the manifold normal vector.
Definition collision.h:551
float tangentImpulse
The friction impulse.
Definition collision.h:554
b2Vec2 point
Contact point in frame A.
Definition collision.h:598
b2Vec2 normal
The unit normal vector in world space, points from shape A to shape B.
Definition collision.h:581
b2LocalManifoldPoint points[2]
The manifold points, up to two are possible in 2D.
Definition collision.h:614
uint16_t id
Uniquely identifies a contact point between two shapes.
Definition collision.h:604
b2Vec2 anchorA
Location of the contact point relative to bodyA's center of mass in world space.
Definition collision.h:542
int pointCount
The number of contact points, will be 0, 1, or 2.
Definition collision.h:590
b2ManifoldPoint points[2]
The manifold points, up to two are possible in 2D.
Definition collision.h:587
float separation
The separation of the contact point, negative if penetrating.
Definition collision.h:548
uint16_t id
Uniquely identifies a contact point between two shapes.
Definition collision.h:570
b2Vec2 anchorB
Similar for body B.
Definition collision.h:545
int pointCount
The number of contact points, will be 0, 1, or 2.
Definition collision.h:617
float totalNormalImpulse
The total normal impulse applied across sub-stepping and restitution.
Definition collision.h:559
float baseSeparation
Cached separation used for contact recycling.
Definition collision.h:567
bool persisted
Did this contact point exist the previous step?
Definition collision.h:573
float normalVelocity
Relative normal velocity pre-solve.
Definition collision.h:564
float rollingImpulse
Angular impulse applied for rolling resistance. N * m * s = kg * m^2 / s.
Definition collision.h:584
b2Vec2 normal
The unit normal vector in frame A, points from shape A to shape B.
Definition collision.h:611
b2LocalManifold b2CollidePolygonAndCircle(const b2Polygon *polygonA, const b2Circle *circleB, b2Transform xf)
Compute the contact manifold between a polygon and a circle.
b2LocalManifold b2CollideSegmentAndCircle(const b2Segment *segmentA, const b2Circle *circleB, b2Transform xf)
Compute the contact manifold between a segment and a circle.
b2LocalManifold b2CollideChainSegmentAndCircle(const b2ChainSegment *segmentA, const b2Circle *circleB, b2Transform xf)
Compute the contact manifold between a chain segment and a circle.
b2LocalManifold b2CollideSegmentAndPolygon(const b2Segment *segmentA, const b2Polygon *polygonB, b2Transform xf)
Compute the contact manifold between a segment and a polygon.
b2LocalManifold b2CollidePolygonAndCapsule(const b2Polygon *polygonA, const b2Capsule *capsuleB, b2Transform xf)
Compute the contact manifold between a polygon and capsule.
b2LocalManifold b2CollidePolygons(const b2Polygon *polygonA, const b2Polygon *polygonB, b2Transform xf)
Compute the contact manifold between two polygons.
b2LocalManifold b2CollideCapsuleAndCircle(const b2Capsule *capsuleA, const b2Circle *circleB, b2Transform xf)
Compute the contact manifold between a capsule and circle.
b2LocalManifold b2CollideCircles(const b2Circle *circleA, const b2Circle *circleB, b2Transform xf)
Compute the contact manifold between two circles.
b2LocalManifold b2CollideSegmentAndCapsule(const b2Segment *segmentA, const b2Capsule *capsuleB, b2Transform xf)
Compute the contact manifold between a segment and a capsule.
b2LocalManifold b2CollideChainSegmentAndPolygon(const b2ChainSegment *segmentA, const b2Polygon *polygonB, b2Transform xf, b2SimplexCache *cache)
Compute the contact manifold between a chain segment and a rounded polygon.
b2LocalManifold b2CollideCapsules(const b2Capsule *capsuleA, const b2Capsule *capsuleB, b2Transform xf)
Compute the contact manifold between two capsules.
b2LocalManifold b2CollideChainSegmentAndCapsule(const b2ChainSegment *segmentA, const b2Capsule *capsuleB, b2Transform xf, b2SimplexCache *cache)
Compute the contact manifold between a chain segment and a capsule.
Contact manifold in local coordinates (frame A).
Definition collision.h:609
Contact manifold point in local coordinates (frame A).
Definition collision.h:596
A contact manifold describes the contact points between colliding shapes.
Definition collision.h:579
A manifold point is a contact point belonging to a contact manifold.
Definition collision.h:538
uint8_t indexB[3]
The cached simplex indices on shape B.
Definition collision.h:384
float fraction1
The barycentric coordinate on the first segment.
Definition collision.h:359
b2Vec2 normal
The hit normal.
Definition collision.h:511
float distanceSquared
The squared distance between the closest points.
Definition collision.h:365
int count
number of valid vertices
Definition collision.h:432
b2Transform transform
Transform of shape B in shape A's frame, the relative pose B in A (b2InvMulTransforms(worldA,...
Definition collision.h:400
float fraction
The sweep time of the collision.
Definition collision.h:514
b2Rot q2
Ending world rotation.
Definition collision.h:475
b2Vec2 c1
Starting center of mass world position.
Definition collision.h:472
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:446
float distance
The final distance, zero if overlapped.
Definition collision.h:412
b2Vec2 w
wB - wA
Definition collision.h:422
b2Vec2 wA
support point in proxyA
Definition collision.h:420
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:485
b2Transform transform
Transform of shape B in shape A's frame, the relative pose B in A.
Definition collision.h:447
b2Vec2 localCenter
Local center of mass position.
Definition collision.h:471
float maxFraction
The fraction of the translation to consider, typically 1.
Definition collision.h:449
b2Vec2 c2
Ending center of mass world position.
Definition collision.h:473
b2Vec2 point
The hit point.
Definition collision.h:508
b2Vec2 closest1
The closest point on the first segment.
Definition collision.h:353
bool canEncroach
Allows shapes with a radius to move slightly closer if already touching.
Definition collision.h:450
b2Vec2 wB
support point in proxyB
Definition collision.h:421
b2SimplexVertex v3
vertices
Definition collision.h:431
b2Vec2 normal
A to B normal in shape A's frame. Invalid if distance is zero.
Definition collision.h:411
b2Vec2 translationB
The translation of shape B, in A's frame.
Definition collision.h:448
b2Vec2 pointA
Closest point on shapeA, in shape A's frame.
Definition collision.h:409
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:484
int iterations
Number of GJK iterations used.
Definition collision.h:413
b2Rot q1
Starting world rotation.
Definition collision.h:474
float maxFraction
Defines the sweep interval [0, maxFraction].
Definition collision.h:488
uint16_t count
The number of stored simplex points.
Definition collision.h:378
uint8_t indexA[3]
The cached simplex indices on shape A.
Definition collision.h:381
b2Vec2 pointB
Closest point on shapeB, in shape A's frame.
Definition collision.h:410
float fraction2
The barycentric coordinate on the second segment.
Definition collision.h:362
int indexB
wB index
Definition collision.h:425
bool useRadii
Should the proxy radius be considered?
Definition collision.h:403
b2TOIState state
The type of result.
Definition collision.h:505
b2Vec2 closest2
The closest point on the second segment.
Definition collision.h:356
float a
barycentric coordinate for closest point
Definition collision.h:423
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:396
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:393
int simplexCount
The number of simplexes stored in the simplex array.
Definition collision.h:414
b2Sweep sweepA
The movement of shape A.
Definition collision.h:486
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:445
int indexA
wA index
Definition collision.h:424
b2Sweep sweepB
The movement of shape B.
Definition collision.h:487
b2DistanceOutput b2ComputeShapeDistance(const b2DistanceInput *input, b2SimplexCache *cache, b2Simplex *simplexes, int simplexCapacity)
Compute the closest points between two shapes represented as point clouds.
b2CastOutput b2CastShape(const b2ShapeCastPairInput *input)
Perform a linear shape cast of shape B moving and shape A fixed.
b2Transform b2GetSweepTransform(const b2Sweep *sweep, float time)
Evaluate the transform sweep at a specific time.
b2SegmentDistanceResult b2ComputeSegmentDistance(b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2)
Compute the distance between two line segments, clamping at the end points if needed.
b2TOIState
Describes the TOI output.
Definition collision.h:493
b2ShapeProxy b2MakeProxy(const b2Vec2 *points, int count, float radius)
Make a proxy for use in overlap, shape cast, and related functions.
b2TOIOutput b2ComputeTimeOfImpact(const b2TOIInput *input)
Compute the upper bound on time before two shapes penetrate.
b2ShapeProxy b2MakeOffsetProxy(const b2Vec2 *points, int count, float radius, b2Vec2 position, b2Rot rotation)
Make a proxy with a transform. This is a deep copy of the points.
Input for b2ComputeShapeDistance.
Definition collision.h:391
Output for b2ComputeShapeDistance.
Definition collision.h:408
Result of computing the distance between two line segments.
Definition collision.h:351
Input parameters for b2CastShape.
Definition collision.h:444
Simplex from the GJK algorithm.
Definition collision.h:430
Used to warm start the GJK simplex.
Definition collision.h:376
Simplex vertex for debugging the GJK algorithm.
Definition collision.h:419
This describes the motion of a body/shape for TOI computation.
Definition collision.h:470
Time of impact input.
Definition collision.h:483
Time of impact output.
Definition collision.h:503
b2Vec2 center2
Local center of the second semicircle.
Definition collision.h:143
int count
The number of points.
Definition collision.h:316
b2Vec2 centroid
The centroid of the polygon.
Definition collision.h:163
b2Vec2 normals[B2_MAX_POLYGON_VERTICES]
The outward normal vectors of the polygon sides.
Definition collision.h:160
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition collision.h:120
float radius
The external radius of the point cloud. May be zero.
Definition collision.h:52
b2Vec2 point1
The first point.
Definition collision.h:176
b2Vec2 normal
The surface normal at the hit point.
Definition collision.h:79
b2Vec2 points[B2_MAX_POLYGON_VERTICES]
The final points of the hull.
Definition collision.h:313
float mass
The mass of the shape, usually in kilograms.
Definition collision.h:117
b2Vec2 origin
Start point of the ray cast.
Definition collision.h:32
bool canEncroach
Allow shape cast to encroach when initially touching.
Definition collision.h:71
b2Vec2 point
The surface hit point.
Definition collision.h:82
int iterations
The number of iterations used.
Definition collision.h:88
bool hit
Did the cast hit?
Definition collision.h:91
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:67
b2ShapeProxy proxy
A generic shape.
Definition collision.h:61
int count
The number of points. Must be greater than 0.
Definition collision.h:49
float fraction
The fraction of the input translation at collision.
Definition collision.h:85
int chainId
The owning chain shape index (internal usage only).
Definition collision.h:197
float radius
The radius.
Definition collision.h:133
b2Vec2 center1
Local center of the first semicircle.
Definition collision.h:140
float radius
The external radius for rounded polygons.
Definition collision.h:166
b2Vec2 points[B2_MAX_POLYGON_VERTICES]
The point cloud.
Definition collision.h:46
b2Vec2 center
The local center.
Definition collision.h:130
b2Vec2 point2
The second point.
Definition collision.h:179
float radius
The radius of the semicircles.
Definition collision.h:146
b2Vec2 translation
The translation of the shape cast.
Definition collision.h:64
b2Vec2 translation
Translation of the ray cast.
Definition collision.h:35
b2Vec2 ghost2
The head ghost vertex.
Definition collision.h:194
b2Vec2 vertices[B2_MAX_POLYGON_VERTICES]
The polygon vertices.
Definition collision.h:157
b2Vec2 ghost1
The tail ghost vertex.
Definition collision.h:188
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:38
b2Segment segment
The line segment.
Definition collision.h:191
float rotationalInertia
The rotational inertia of the shape about the shape center.
Definition collision.h:123
int count
The number of polygon vertices.
Definition collision.h:169
b2Polygon b2MakeOffsetRoundedBox(float halfWidth, float halfHeight, b2Vec2 center, b2Rot rotation, float radius)
Make an offset rounded box, bypassing the need for a convex hull.
b2Polygon b2MakeSquare(float halfWidth)
Make a square polygon, bypassing the need for a convex hull.
b2AABB b2ComputeCircleBounds(const b2Circle *shape, b2WorldTransform transform)
Compute the bounding box of a transformed circle.
b2Polygon b2MakeOffsetPolygon(const b2Hull *hull, b2Vec2 position, b2Rot rotation)
Make an offset convex polygon from a convex hull.
b2MassData b2ComputePolygonMass(const b2Polygon *shape, float density)
Compute mass properties of a polygon.
b2AABB b2ComputePolygonBounds(const b2Polygon *shape, b2WorldTransform transform)
Compute the bounding box of a transformed polygon.
b2Polygon b2MakeOffsetRoundedPolygon(const b2Hull *hull, b2Vec2 position, b2Rot rotation, float radius)
Make an offset convex polygon from a convex hull with a radius.
b2CastOutput b2CastShapeCircle(const b2Circle *shape, const b2ShapeCastInput *input)
Shape cast versus a circle.
b2Polygon b2MakeOffsetBox(float halfWidth, float halfHeight, b2Vec2 center, b2Rot rotation)
Make an offset box, bypassing the need for a convex hull.
#define B2_MAX_POLYGON_VERTICES
The maximum number of vertices on a convex polygon.
Definition collision.h:26
bool b2PointInPolygon(const b2Polygon *shape, b2Vec2 point)
Test a point for overlap with a convex polygon in local space.
b2Polygon b2MakeRoundedBox(float halfWidth, float halfHeight, float radius)
Make a rounded box, bypassing the need for a convex hull.
b2CastOutput b2CastRayCapsule(const b2Capsule *shape, const b2RayCastInput *input)
Ray cast versus capsule shape in local space.
bool b2PointInCircle(const b2Circle *shape, b2Vec2 point)
Test a point for overlap with a circle in local space.
b2CastOutput b2CastRaySegment(const b2Segment *shape, const b2RayCastInput *input, bool oneSided)
Ray cast versus segment shape in local space.
b2AABB b2ComputeSegmentBounds(const b2Segment *shape, b2WorldTransform transform)
Compute the bounding box of a transformed line segment.
bool b2ValidateHull(const b2Hull *hull)
This determines if a hull is valid.
bool b2IsValidRay(const b2RayCastInput *input)
Validate ray cast input data (NaN, etc).
b2Polygon b2TransformPolygon(b2Transform transform, const b2Polygon *polygon)
Transform a polygon. This is useful for transferring a shape from one body to another.
b2CastOutput b2CastShapePolygon(const b2Polygon *shape, const b2ShapeCastInput *input)
Shape cast versus a convex polygon.
b2CastOutput b2WorldCastOutput
This is an alias in single precision.
Definition collision.h:109
b2Polygon b2MakePolygon(const b2Hull *hull, float radius)
Make a convex polygon from a convex hull.
b2CastOutput b2CastRayCircle(const b2Circle *shape, const b2RayCastInput *input)
Ray cast versus circle shape in local space.
b2MassData b2ComputeCapsuleMass(const b2Capsule *shape, float density)
Compute mass properties of a capsule.
b2Hull b2ComputeHull(const b2Vec2 *points, int count)
Compute the convex hull of a set of points.
b2AABB b2ComputeCapsuleBounds(const b2Capsule *shape, b2WorldTransform transform)
Compute the bounding box of a transformed capsule.
b2CastOutput b2CastRayPolygon(const b2Polygon *shape, const b2RayCastInput *input)
Ray cast versus polygon shape in local space.
b2CastOutput b2CastShapeCapsule(const b2Capsule *shape, const b2ShapeCastInput *input)
Shape cast versus a capsule.
b2Polygon b2MakeBox(float halfWidth, float halfHeight)
Make a box (rectangle) polygon, bypassing the need for a convex hull.
b2MassData b2ComputeCircleMass(const b2Circle *shape, float density)
Compute mass properties of a circle.
bool b2PointInCapsule(const b2Capsule *shape, b2Vec2 point)
Test a point for overlap with a capsule in local space.
b2CastOutput b2CastShapeSegment(const b2Segment *shape, const b2ShapeCastInput *input)
Shape cast versus a line segment.
A solid capsule can be viewed as two semicircles connected by a rectangle.
Definition collision.h:138
Low level ray cast or shape cast output data.
Definition collision.h:77
A line segment with one-sided collision.
Definition collision.h:186
A solid circle.
Definition collision.h:128
A convex hull.
Definition collision.h:311
This holds the mass data computed for a shape.
Definition collision.h:115
A solid convex polygon.
Definition collision.h:155
Low level ray cast input data.
Definition collision.h:30
A line segment with two-sided collision.
Definition collision.h:174
Low level shape cast input in generic form.
Definition collision.h:59
A distance proxy is used by the GJK algorithm.
Definition collision.h:44
b2Vec2 b2Pos
Alias in single precision.
Definition math_types.h:61
b2Transform b2WorldTransform
Alias in single precision.
Definition math_types.h:64
Axis-aligned bounding box.
Definition math_types.h:77
separation = dot(normal, point) - offset
Definition math_types.h:84
2D rotation This is similar to using a complex number for rotation
Definition math_types.h:29
A 2D rigid transform.
Definition math_types.h:36
2D vector This can be used to represent a point or free vector
Definition math_types.h:14
int leafVisits
Number of leaf nodes visited during the query.
Definition collision.h:699
b2Vec2 translation
The sweep translation.
Definition collision.h:773
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:776
b2AABB box
The AABB to cast, in the tree's frame.
Definition collision.h:770
int nodeVisits
Number of internal nodes visited during the query.
Definition collision.h:696
void b2DestroyDynamicTree(b2DynamicTree *tree)
Destroy the tree, freeing the node pool.
uint64_t b2DynamicTree_GetUserData(const b2DynamicTree *tree, int proxyId)
Get proxy user data.
float b2TreeBoxCastCallbackFcn(const b2BoxCastInput *input, int proxyId, uint64_t userData, void *context)
This function receives clipped AABB cast input for a proxy.
Definition collision.h:784
void b2DynamicTree_Validate(const b2DynamicTree *tree)
Validate the tree.
float b2DynamicTree_GetAreaRatio(const b2DynamicTree *tree)
Get the ratio of the sum of the internal node areas to the root area.
void b2DestroyTreeProxy(b2DynamicTree *tree, int proxyId)
Destroy a proxy. This asserts if the id is invalid.
b2AABB b2DynamicTree_GetRootBounds(const b2DynamicTree *tree)
Get the bounding box that contains the entire tree.
b2TreeStats b2DynamicTree_OverlapAABB(const b2DynamicTree *tree, b2AABB aabb, uint64_t maskBits, b2TreeQueryCallbackFcn *callback, void *context)
Query an AABB for overlapping proxies.
b2DynamicTree * b2CreateDynamicTree(int proxyCapacity)
Constructing the tree initializes the node pool.
bool b2TreeQueryCallbackFcn(int proxyId, uint64_t userData, void *context)
This function receives proxies found in the AABB query.
Definition collision.h:727
float b2TreeRayCastCallbackFcn(const b2RayCastInput *input, int proxyId, uint64_t userData, void *context)
This function receives clipped ray cast input for a proxy.
Definition collision.h:747
int b2DynamicTree_GetProxyCount(const b2DynamicTree *tree)
Get the number of proxies created.
b2TreeStats b2DynamicTree_CastBox(const b2DynamicTree *tree, const b2BoxCastInput *input, uint64_t maskBits, b2TreeBoxCastCallbackFcn *callback, void *context)
Cast a swept AABB through the tree.
void b2DynamicTree_MoveProxy(b2DynamicTree *tree, int proxyId, b2AABB aabb)
Move a proxy to a new AABB by removing and reinserting into the tree.
b2TreeStats b2DynamicTree_OverlapAABBAll(const b2DynamicTree *tree, b2AABB aabb, b2TreeQueryCallbackFcn *callback, void *context)
Query an AABB for overlapping proxies.
uint64_t b2DynamicTree_GetCategoryBits(b2DynamicTree *tree, int proxyId)
Get the category bits on a proxy.
b2AABB b2DynamicTree_GetProxyBounds(const b2DynamicTree *tree, int proxyId)
Get the AABB of a proxy.
int b2DynamicTree_GetHeight(const b2DynamicTree *tree)
Get the height of the binary tree.
size_t b2DynamicTree_GetByteCount(const b2DynamicTree *tree)
Get the number of bytes used by this tree.
b2TreeStats b2DynamicTree_CastRay(const b2DynamicTree *tree, const b2RayCastInput *input, uint64_t maskBits, b2TreeRayCastCallbackFcn *callback, void *context)
Ray cast against the proxies in the tree.
struct b2DynamicTree b2DynamicTree
Opaque dynamic tree. Details are internal.
Definition collision.h:690
int b2CreateTreeProxy(b2DynamicTree *tree, b2AABB aabb, uint64_t categoryBits, uint64_t userData)
Create a proxy. Provide an AABB and a userData value.
void b2DynamicTree_SetCategoryBits(b2DynamicTree *tree, int proxyId, uint64_t categoryBits)
Modify the category bits on a proxy.
Input for casting an AABB through a dynamic tree.
Definition collision.h:768
These are performance results returned by dynamic tree queries.
Definition collision.h:694