Box2D 3.1.0
A 2D physics engine for games
Loading...
Searching...
No Matches
collision.h
1// SPDX-FileCopyrightText: 2023 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "base.h"
7#include "math_functions.h"
8
9#include <stdbool.h>
10
11typedef struct b2Circle b2Circle;
12typedef struct b2Capsule b2Capsule;
13typedef struct b2DistanceCache b2DistanceCache;
14typedef struct b2Polygon b2Polygon;
15typedef struct b2Segment b2Segment;
16typedef struct b2ChainSegment b2ChainSegment;
17
18typedef struct b2Hull b2Hull;
19
30#define b2_maxPolygonVertices 8
31
44
65
67typedef struct b2CastOutput
68{
71
74
76 float fraction;
77
79 int32_t iterations;
80
82 bool hit;
84
86typedef struct b2MassData
87{
89 float mass;
90
93
97
99typedef struct b2Circle
100{
103
105 float radius;
106} b2Circle;
107
110typedef struct b2Capsule
111{
114
117
119 float radius;
120} b2Capsule;
121
145
147typedef struct b2Segment
148{
151
154} b2Segment;
155
173
175B2_API bool b2IsValidRay( const b2RayCastInput* input );
176
179B2_API b2Polygon b2MakePolygon( const b2Hull* hull, float radius );
180
183B2_API b2Polygon b2MakeOffsetPolygon( const b2Hull* hull, float radius, b2Transform transform );
184
186B2_API b2Polygon b2MakeSquare( float h );
187
189B2_API b2Polygon b2MakeBox( float hx, float hy );
190
192B2_API b2Polygon b2MakeRoundedBox( float hx, float hy, float radius );
193
195B2_API b2Polygon b2MakeOffsetBox( float hx, float hy, b2Vec2 center, b2Rot rotation );
196
198B2_API b2Polygon b2TransformPolygon( b2Transform transform, const b2Polygon* polygon );
199
201B2_API b2MassData b2ComputeCircleMass( const b2Circle* shape, float density );
202
204B2_API b2MassData b2ComputeCapsuleMass( const b2Capsule* shape, float density );
205
207B2_API b2MassData b2ComputePolygonMass( const b2Polygon* shape, float density );
208
210B2_API b2AABB b2ComputeCircleAABB( const b2Circle* shape, b2Transform transform );
211
213B2_API b2AABB b2ComputeCapsuleAABB( const b2Capsule* shape, b2Transform transform );
214
216B2_API b2AABB b2ComputePolygonAABB( const b2Polygon* shape, b2Transform transform );
217
219B2_API b2AABB b2ComputeSegmentAABB( const b2Segment* shape, b2Transform transform );
220
222B2_API bool b2PointInCircle( b2Vec2 point, const b2Circle* shape );
223
225B2_API bool b2PointInCapsule( b2Vec2 point, const b2Capsule* shape );
226
228B2_API bool b2PointInPolygon( b2Vec2 point, const b2Polygon* shape );
229
231B2_API b2CastOutput b2RayCastCircle( const b2RayCastInput* input, const b2Circle* shape );
232
234B2_API b2CastOutput b2RayCastCapsule( const b2RayCastInput* input, const b2Capsule* shape );
235
238B2_API b2CastOutput b2RayCastSegment( const b2RayCastInput* input, const b2Segment* shape, bool oneSided );
239
241B2_API b2CastOutput b2RayCastPolygon( const b2RayCastInput* input, const b2Polygon* shape );
242
244B2_API b2CastOutput b2ShapeCastCircle( const b2ShapeCastInput* input, const b2Circle* shape );
245
247B2_API b2CastOutput b2ShapeCastCapsule( const b2ShapeCastInput* input, const b2Capsule* shape );
248
250B2_API b2CastOutput b2ShapeCastSegment( const b2ShapeCastInput* input, const b2Segment* shape );
251
253B2_API b2CastOutput b2ShapeCastPolygon( const b2ShapeCastInput* input, const b2Polygon* shape );
254
257typedef struct b2Hull
258{
261
263 int32_t count;
264} b2Hull;
265
274B2_API b2Hull b2ComputeHull( const b2Vec2* points, int32_t count );
275
280B2_API bool b2ValidateHull( const b2Hull* hull );
281
312
315
328
331typedef struct b2DistanceCache
332{
334 uint16_t count;
335
337 uint8_t indexA[3];
338
340 uint8_t indexB[3];
342
343static const b2DistanceCache b2_emptyDistanceCache = B2_ZERO_INIT;
344
363
373
375typedef struct b2SimplexVertex
376{
380 float a;
381 int32_t indexA;
382 int32_t indexB;
384
386typedef struct b2Simplex
387{
389 int32_t count;
390} b2Simplex;
391
396 int simplexCapacity );
397
408
411
413B2_API b2DistanceProxy b2MakeProxy( const b2Vec2* vertices, int32_t count, float radius );
414
426
428B2_API b2Transform b2GetSweepTransform( const b2Sweep* sweep, float time );
429
439
441typedef enum b2TOIState
442{
443 b2_toiStateUnknown,
444 b2_toiStateFailed,
445 b2_toiStateOverlapped,
446 b2_toiStateHit,
447 b2_toiStateSeparated
448} b2TOIState;
449
451typedef struct b2TOIOutput
452{
454 float t;
456
461B2_API b2TOIOutput b2TimeOfImpact( const b2TOIInput* input );
462
474typedef struct b2ManifoldPoint
475{
479
483
486
489
492
495
499
503
505 uint16_t id;
506
510
512typedef struct b2Manifold
513{
516
519
521 int32_t pointCount;
522} b2Manifold;
523
525B2_API b2Manifold b2CollideCircles( const b2Circle* circleA, b2Transform xfA, const b2Circle* circleB, b2Transform xfB );
526
528B2_API b2Manifold b2CollideCapsuleAndCircle( const b2Capsule* capsuleA, b2Transform xfA, const b2Circle* circleB,
529 b2Transform xfB );
530
532B2_API b2Manifold b2CollideSegmentAndCircle( const b2Segment* segmentA, b2Transform xfA, const b2Circle* circleB,
533 b2Transform xfB );
534
536B2_API b2Manifold b2CollidePolygonAndCircle( const b2Polygon* polygonA, b2Transform xfA, const b2Circle* circleB,
537 b2Transform xfB );
538
540B2_API b2Manifold b2CollideCapsules( const b2Capsule* capsuleA, b2Transform xfA, const b2Capsule* capsuleB, b2Transform xfB );
541
543B2_API b2Manifold b2CollideSegmentAndCapsule( const b2Segment* segmentA, b2Transform xfA, const b2Capsule* capsuleB,
544 b2Transform xfB );
545
547B2_API b2Manifold b2CollidePolygonAndCapsule( const b2Polygon* polygonA, b2Transform xfA, const b2Capsule* capsuleB,
548 b2Transform xfB );
549
551B2_API b2Manifold b2CollidePolygons( const b2Polygon* polygonA, b2Transform xfA, const b2Polygon* polygonB, b2Transform xfB );
552
554B2_API b2Manifold b2CollideSegmentAndPolygon( const b2Segment* segmentA, b2Transform xfA, const b2Polygon* polygonB,
555 b2Transform xfB );
556
559 const b2Circle* circleB, b2Transform xfB );
560
563 const b2Capsule* capsuleB, b2Transform xfB, b2DistanceCache* cache );
564
567 const b2Polygon* polygonB, b2Transform xfB, b2DistanceCache* cache );
568
592#define b2_defaultCategoryBits ( 1 )
593
596#define b2_defaultMaskBits ( UINT64_MAX )
597
599typedef struct b2TreeNode
600{
603
605 uint64_t categoryBits; // 8
606
607 union
608 {
610 int32_t parent;
611
613 int32_t next;
614 }; // 4
615
617 int32_t child1; // 4
618
620 int32_t child2; // 4
621
623 // todo could be union with child index
624 int32_t userData; // 4
625
627 int16_t height; // 2
628
630 bool enlarged; // 1
631
633 char pad[5];
634} b2TreeNode;
635
638typedef struct b2DynamicTree
639{
642
644 int32_t root;
645
647 int32_t nodeCount;
648
651
653 int32_t freeList;
654
656 int32_t proxyCount;
657
659 int32_t* leafIndices;
660
663
666
668 int32_t* binIndices;
669
673
676
679
681B2_API int32_t b2DynamicTree_CreateProxy( b2DynamicTree* tree, b2AABB aabb, uint64_t categoryBits, int32_t userData );
682
684B2_API void b2DynamicTree_DestroyProxy( b2DynamicTree* tree, int32_t proxyId );
685
687B2_API void b2DynamicTree_MoveProxy( b2DynamicTree* tree, int32_t proxyId, b2AABB aabb );
688
690B2_API void b2DynamicTree_EnlargeProxy( b2DynamicTree* tree, int32_t proxyId, b2AABB aabb );
691
694typedef bool b2TreeQueryCallbackFcn( int32_t proxyId, int32_t userData, void* context );
695
697B2_API void b2DynamicTree_Query( const b2DynamicTree* tree, b2AABB aabb, uint64_t maskBits, b2TreeQueryCallbackFcn* callback,
698 void* context );
699
705typedef float b2TreeRayCastCallbackFcn( const b2RayCastInput* input, int32_t proxyId, int32_t userData, void* context );
706
718B2_API void b2DynamicTree_RayCast( const b2DynamicTree* tree, const b2RayCastInput* input, uint64_t maskBits,
719 b2TreeRayCastCallbackFcn* callback, void* context );
720
726typedef float b2TreeShapeCastCallbackFcn( const b2ShapeCastInput* input, int32_t proxyId, int32_t userData, void* context );
727
738B2_API void b2DynamicTree_ShapeCast( const b2DynamicTree* tree, const b2ShapeCastInput* input, uint64_t maskBits,
739 b2TreeShapeCastCallbackFcn* callback, void* context );
740
742B2_API void b2DynamicTree_Validate( const b2DynamicTree* tree );
743
746B2_API int b2DynamicTree_GetHeight( const b2DynamicTree* tree );
747
750
752B2_API float b2DynamicTree_GetAreaRatio( const b2DynamicTree* tree );
753
756
759
761B2_API int b2DynamicTree_Rebuild( b2DynamicTree* tree, bool fullBuild );
762
767B2_API void b2DynamicTree_ShiftOrigin( b2DynamicTree* tree, b2Vec2 newOrigin );
768
771
774B2_INLINE int32_t b2DynamicTree_GetUserData( const b2DynamicTree* tree, int32_t proxyId )
775{
776 return tree->nodes[proxyId].userData;
777}
778
780B2_INLINE b2AABB b2DynamicTree_GetAABB( const b2DynamicTree* tree, int32_t proxyId )
781{
782 return tree->nodes[proxyId].aabb;
783}
784
float normalImpulse
The impulse along the manifold normal vector.
Definition collision.h:491
float maxNormalImpulse
The maximum normal impulse applied during sub-stepping todo not sure this is needed.
Definition collision.h:498
float tangentImpulse
The friction impulse.
Definition collision.h:494
b2Vec2 point
Location of the contact point in world space.
Definition collision.h:478
b2Vec2 normal
The unit normal vector in world space, points from shape A to bodyB.
Definition collision.h:518
b2Vec2 anchorA
Location of the contact point relative to bodyA's origin in world space.
Definition collision.h:482
b2ManifoldPoint points[2]
The manifold points, up to two are possible in 2D.
Definition collision.h:515
int32_t pointCount
The number of contacts points, will be 0, 1, or 2.
Definition collision.h:521
float separation
The separation of the contact point, negative if penetrating.
Definition collision.h:488
uint16_t id
Uniquely identifies a contact point between two shapes.
Definition collision.h:505
b2Vec2 anchorB
Location of the contact point relative to bodyB's origin in world space.
Definition collision.h:485
bool persisted
Did this contact point exist the previous step?
Definition collision.h:508
float normalVelocity
Relative normal velocity pre-solve.
Definition collision.h:502
b2Manifold b2CollideSegmentAndCircle(const b2Segment *segmentA, b2Transform xfA, const b2Circle *circleB, b2Transform xfB)
Compute the contact manifold between an segment and a circle.
b2Manifold b2CollideChainSegmentAndPolygon(const b2ChainSegment *segmentA, b2Transform xfA, const b2Polygon *polygonB, b2Transform xfB, b2DistanceCache *cache)
Compute the contact manifold between a chain segment and a rounded polygon.
b2Manifold b2CollideCapsules(const b2Capsule *capsuleA, b2Transform xfA, const b2Capsule *capsuleB, b2Transform xfB)
Compute the contact manifold between a capsule and circle.
b2Manifold b2CollideChainSegmentAndCircle(const b2ChainSegment *segmentA, b2Transform xfA, const b2Circle *circleB, b2Transform xfB)
Compute the contact manifold between a chain segment and a circle.
b2Manifold b2CollideSegmentAndPolygon(const b2Segment *segmentA, b2Transform xfA, const b2Polygon *polygonB, b2Transform xfB)
Compute the contact manifold between an segment and a polygon.
b2Manifold b2CollidePolygonAndCircle(const b2Polygon *polygonA, b2Transform xfA, const b2Circle *circleB, b2Transform xfB)
Compute the contact manifold between a polygon and a circle.
b2Manifold b2CollideSegmentAndCapsule(const b2Segment *segmentA, b2Transform xfA, const b2Capsule *capsuleB, b2Transform xfB)
Compute the contact manifold between an segment and a capsule.
b2Manifold b2CollidePolygonAndCapsule(const b2Polygon *polygonA, b2Transform xfA, const b2Capsule *capsuleB, b2Transform xfB)
Compute the contact manifold between a polygon and capsule.
b2Manifold b2CollideCircles(const b2Circle *circleA, b2Transform xfA, const b2Circle *circleB, b2Transform xfB)
Compute the contact manifold between two circles.
b2Manifold b2CollideCapsuleAndCircle(const b2Capsule *capsuleA, b2Transform xfA, const b2Circle *circleB, b2Transform xfB)
Compute the contact manifold between a capsule and circle.
b2Manifold b2CollidePolygons(const b2Polygon *polygonA, b2Transform xfA, const b2Polygon *polygonB, b2Transform xfB)
Compute the contact manifold between two polygons.
b2Manifold b2CollideChainSegmentAndCapsule(const b2ChainSegment *segmentA, b2Transform xfA, const b2Capsule *capsuleB, b2Transform xfB, b2DistanceCache *cache)
Compute the contact manifold between a chain segment and a capsule.
A contact manifold describes the contact points between colliding shapes.
Definition collision.h:513
A manifold point is a contact point belonging to a contact manifold.
Definition collision.h:475
b2Transform transformA
The world transform for shape A.
Definition collision.h:355
float fraction1
The barycentric coordinate on the first segment.
Definition collision.h:304
float distanceSquared
The squared distance between the closest points.
Definition collision.h:310
b2DistanceProxy proxyA
The proxy for shape A.
Definition collision.h:401
float t
The time of the collision.
Definition collision.h:454
uint16_t count
The number of stored simplex points.
Definition collision.h:334
b2Rot q2
Ending world rotation.
Definition collision.h:424
int32_t count
number of valid vertices
Definition collision.h:389
uint8_t indexB[3]
The cached simplex indices on shape B.
Definition collision.h:340
int32_t count
The number of points.
Definition collision.h:323
b2Vec2 c1
Starting center of mass world position.
Definition collision.h:421
int32_t indexB
wB index
Definition collision.h:382
float distance
The final distance, zero if overlapped.
Definition collision.h:369
b2Vec2 w
wB - wA
Definition collision.h:379
b2Vec2 wA
support point in proxyA
Definition collision.h:377
b2Transform transformB
The world transform for shape B.
Definition collision.h:358
b2Vec2 localCenter
Local center of mass position.
Definition collision.h:420
float maxFraction
The fraction of the translation to consider, typically 1.
Definition collision.h:406
b2Vec2 c2
Ending center of mass world position.
Definition collision.h:422
b2DistanceProxy proxyA
The proxy for shape A.
Definition collision.h:433
b2Transform transformA
The world transform for shape A.
Definition collision.h:403
b2Vec2 closest1
The closest point on the first segment.
Definition collision.h:298
int32_t iterations
Number of GJK iterations used.
Definition collision.h:370
b2Vec2 wB
support point in proxyB
Definition collision.h:378
b2SimplexVertex v3
vertices
Definition collision.h:388
b2Vec2 translationB
The translation of shape B.
Definition collision.h:405
b2Vec2 pointA
Closest point on shapeA.
Definition collision.h:367
b2DistanceProxy proxyB
The proxy for shape B.
Definition collision.h:434
b2DistanceProxy proxyA
The proxy for shape A.
Definition collision.h:349
b2Transform transformB
The world transform for shape B.
Definition collision.h:404
uint8_t indexA[3]
The cached simplex indices on shape A.
Definition collision.h:337
b2Rot q1
Starting world rotation.
Definition collision.h:423
float tMax
Defines the sweep interval [0, tMax].
Definition collision.h:437
b2Vec2 points[b2_maxPolygonVertices]
The point cloud.
Definition collision.h:320
b2DistanceProxy proxyB
The proxy for shape B.
Definition collision.h:402
b2Vec2 pointB
Closest point on shapeB.
Definition collision.h:368
float fraction2
The barycentric coordinate on the second segment.
Definition collision.h:307
float radius
The external radius of the point cloud.
Definition collision.h:326
bool useRadii
Should the proxy radius be considered?
Definition collision.h:361
b2TOIState state
The type of result.
Definition collision.h:453
b2Vec2 closest2
The closest point on the second segment.
Definition collision.h:301
b2DistanceProxy proxyB
The proxy for shape B.
Definition collision.h:352
float a
barycentric coordinate for closest point
Definition collision.h:380
b2Sweep sweepA
The movement of shape A.
Definition collision.h:435
b2Sweep sweepB
The movement of shape B.
Definition collision.h:436
int32_t simplexCount
The number of simplexes stored in the simplex array.
Definition collision.h:371
int32_t indexA
wA index
Definition collision.h:381
b2SegmentDistanceResult b2SegmentDistance(b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2)
Compute the distance between two line segments, clamping at the end points if needed.
b2TOIOutput b2TimeOfImpact(const b2TOIInput *input)
Compute the upper bound on time before two shapes penetrate.
b2Transform b2GetSweepTransform(const b2Sweep *sweep, float time)
Evaluate the transform sweep at a specific time.
b2TOIState
Describes the TOI output.
Definition collision.h:442
b2CastOutput b2ShapeCast(const b2ShapeCastPairInput *input)
Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point,...
b2DistanceProxy b2MakeProxy(const b2Vec2 *vertices, int32_t count, float radius)
Make a proxy for use in GJK and related functions.
b2DistanceOutput b2ShapeDistance(b2DistanceCache *cache, const b2DistanceInput *input, b2Simplex *simplexes, int simplexCapacity)
Compute the closest points between two shapes represented as point clouds.
Used to warm start b2Distance.
Definition collision.h:332
Input for b2ShapeDistance.
Definition collision.h:347
Output for b2ShapeDistance.
Definition collision.h:366
A distance proxy is used by the GJK algorithm. It encapsulates any shape.
Definition collision.h:318
Result of computing the distance between two line segments.
Definition collision.h:296
Input parameters for b2ShapeCast.
Definition collision.h:400
Simplex from the GJK algorithm.
Definition collision.h:387
Simplex vertex for debugging the GJK algorithm.
Definition collision.h:376
This describes the motion of a body/shape for TOI computation.
Definition collision.h:419
Input parameters for b2TimeOfImpact.
Definition collision.h:432
Output parameters for b2TimeOfImpact.
Definition collision.h:452
b2Vec2 center2
Local center of the second semicircle.
Definition collision.h:116
b2Vec2 centroid
The centroid of the polygon.
Definition collision.h:137
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition collision.h:92
b2Vec2 point1
The first point.
Definition collision.h:150
b2Vec2 normal
The surface normal at the hit point.
Definition collision.h:70
float mass
The mass of the shape, usually in kilograms.
Definition collision.h:89
b2Vec2 origin
Start point of the ray cast.
Definition collision.h:36
int32_t chainId
The owning chain shape index (internal usage only)
Definition collision.h:171
b2Vec2 vertices[b2_maxPolygonVertices]
The polygon vertices.
Definition collision.h:131
b2Vec2 point
The surface hit point.
Definition collision.h:73
float radius
The radius around the point cloud.
Definition collision.h:57
bool hit
Did the cast hit?
Definition collision.h:82
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:63
b2Vec2 points[b2_maxPolygonVertices]
A point cloud to cast.
Definition collision.h:51
int32_t iterations
The number of iterations used.
Definition collision.h:79
float fraction
The fraction of the input translation at collision.
Definition collision.h:76
int32_t count
The number of points.
Definition collision.h:263
int32_t count
The number of polygon vertices.
Definition collision.h:143
float radius
The radius.
Definition collision.h:105
b2Vec2 center1
Local center of the first semicircle.
Definition collision.h:113
float radius
The external radius for rounded polygons.
Definition collision.h:140
b2Vec2 points[b2_maxPolygonVertices]
The final points of the hull.
Definition collision.h:260
b2Vec2 center
The local center.
Definition collision.h:102
b2Vec2 point2
The second point.
Definition collision.h:153
float radius
The radius of the semicircles.
Definition collision.h:119
int32_t count
The number of points.
Definition collision.h:54
b2Vec2 translation
The translation of the shape cast.
Definition collision.h:60
b2Vec2 translation
Translation of the ray cast.
Definition collision.h:39
b2Vec2 ghost2
The head ghost vertex.
Definition collision.h:168
b2Vec2 ghost1
The tail ghost vertex.
Definition collision.h:162
b2Vec2 normals[b2_maxPolygonVertices]
The outward normal vectors of the polygon sides.
Definition collision.h:134
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:42
b2Segment segment
The line segment.
Definition collision.h:165
float rotationalInertia
The rotational inertia of the shape about the local origin.
Definition collision.h:95
#define b2_maxPolygonVertices
The maximum number of vertices on a convex polygon.
Definition collision.h:30
b2MassData b2ComputePolygonMass(const b2Polygon *shape, float density)
Compute mass properties of a polygon.
b2Polygon b2MakeOffsetBox(float hx, float hy, b2Vec2 center, b2Rot rotation)
Make an offset box, bypassing the need for a convex hull.
b2CastOutput b2ShapeCastSegment(const b2ShapeCastInput *input, const b2Segment *shape)
Shape cast versus a line segment. Initial overlap is treated as a miss.
b2Polygon b2MakeSquare(float h)
Make a square polygon, bypassing the need for a convex hull.
b2CastOutput b2ShapeCastPolygon(const b2ShapeCastInput *input, const b2Polygon *shape)
Shape cast versus a convex polygon. Initial overlap is treated as a miss.
b2CastOutput b2ShapeCastCapsule(const b2ShapeCastInput *input, const b2Capsule *shape)
Shape cast versus a capsule. Initial overlap is treated as a miss.
b2CastOutput b2RayCastPolygon(const b2RayCastInput *input, const b2Polygon *shape)
Ray cast versus polygon in shape local space. Initial overlap is treated as a miss.
b2CastOutput b2RayCastCircle(const b2RayCastInput *input, const b2Circle *shape)
Ray cast versus circle in shape local space. Initial overlap is treated as a miss.
b2CastOutput b2ShapeCastCircle(const b2ShapeCastInput *input, const b2Circle *shape)
Shape cast versus a circle. Initial overlap is treated as a miss.
bool b2PointInCapsule(b2Vec2 point, const b2Capsule *shape)
Test a point for overlap with a capsule in local space.
b2AABB b2ComputeCircleAABB(const b2Circle *shape, b2Transform transform)
Compute the bounding box of a transformed circle.
bool b2ValidateHull(const b2Hull *hull)
This determines if a hull is valid.
b2CastOutput b2RayCastCapsule(const b2RayCastInput *input, const b2Capsule *shape)
Ray cast versus capsule in shape local space. Initial overlap is treated as a miss.
b2Hull b2ComputeHull(const b2Vec2 *points, int32_t count)
Compute the convex hull of a set of points.
b2AABB b2ComputePolygonAABB(const b2Polygon *shape, b2Transform transform)
Compute the bounding box of a transformed polygon.
bool b2PointInPolygon(b2Vec2 point, const b2Polygon *shape)
Test a point for overlap with a convex polygon in local space.
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.
b2Polygon b2MakeBox(float hx, float hy)
Make a box (rectangle) polygon, bypassing the need for a convex hull.
bool b2PointInCircle(b2Vec2 point, const b2Circle *shape)
Test a point for overlap with a circle in local space.
b2CastOutput b2RayCastSegment(const b2RayCastInput *input, const b2Segment *shape, bool oneSided)
Ray cast versus segment in shape local space.
b2Polygon b2MakePolygon(const b2Hull *hull, float radius)
Make a convex polygon from a convex hull.
b2Polygon b2MakeOffsetPolygon(const b2Hull *hull, float radius, b2Transform transform)
Make an offset convex polygon from a convex hull.
b2AABB b2ComputeSegmentAABB(const b2Segment *shape, b2Transform transform)
Compute the bounding box of a transformed line segment.
b2MassData b2ComputeCapsuleMass(const b2Capsule *shape, float density)
Compute mass properties of a capsule.
b2AABB b2ComputeCapsuleAABB(const b2Capsule *shape, b2Transform transform)
Compute the bounding box of a transformed capsule.
b2MassData b2ComputeCircleMass(const b2Circle *shape, float density)
Compute mass properties of a circle.
b2Polygon b2MakeRoundedBox(float hx, float hy, float radius)
Make a rounded box, bypassing the need for a convex hull.
A solid capsule can be viewed as two semicircles connected by a rectangle.
Definition collision.h:111
Low level ray-cast or shape-cast output data.
Definition collision.h:68
A line segment with one-sided collision.
Definition collision.h:160
A solid circle.
Definition collision.h:100
A convex hull.
Definition collision.h:258
This holds the mass data computed for a shape.
Definition collision.h:87
A solid convex polygon.
Definition collision.h:129
Low level ray-cast input data.
Definition collision.h:34
A line segment with two-sided collision.
Definition collision.h:148
Low level shape cast input in generic form.
Definition collision.h:49
Axis-aligned bounding box.
Definition math_functions.h:53
2D rotation This is similar to using a complex number for rotation
Definition math_functions.h:32
A 2D rigid transform.
Definition math_functions.h:39
2D vector This can be used to represent a point or free vector
Definition math_functions.h:24
b2AABB * leafBoxes
Leaf bounding boxes for rebuild.
Definition collision.h:662
int32_t child1
Child 1 index.
Definition collision.h:617
b2Vec2 * leafCenters
Leaf bounding box centers for rebuild.
Definition collision.h:665
b2TreeNode * nodes
The tree nodes.
Definition collision.h:641
uint64_t categoryBits
Category bits for collision filtering.
Definition collision.h:605
int32_t child2
Child 2 index.
Definition collision.h:620
int32_t rebuildCapacity
Allocated space for rebuilding.
Definition collision.h:671
int32_t proxyCount
Number of proxies created.
Definition collision.h:656
int32_t userData
User data.
Definition collision.h:624
b2AABB aabb
The node bounding box.
Definition collision.h:602
char pad[5]
Padding for clarity.
Definition collision.h:633
int16_t height
Leaf = 0, free node = -1.
Definition collision.h:627
bool enlarged
Has the AABB been enlarged?
Definition collision.h:630
int32_t freeList
Node free list.
Definition collision.h:653
int32_t * binIndices
Bins for sorting during rebuild.
Definition collision.h:668
int32_t nodeCapacity
The allocated node space.
Definition collision.h:650
int32_t nodeCount
The number of nodes.
Definition collision.h:647
int32_t root
The root index.
Definition collision.h:644
int32_t * leafIndices
Leaf indices for rebuild.
Definition collision.h:659
b2AABB b2DynamicTree_GetAABB(const b2DynamicTree *tree, int32_t proxyId)
Get the AABB of a proxy.
Definition collision.h:780
void b2DynamicTree_MoveProxy(b2DynamicTree *tree, int32_t proxyId, b2AABB aabb)
Move a proxy to a new AABB by removing and reinserting into the tree.
int b2DynamicTree_Rebuild(b2DynamicTree *tree, bool fullBuild)
Rebuild the tree while retaining subtrees that haven't changed. Returns the number of boxes sorted.
void b2DynamicTree_RayCast(const b2DynamicTree *tree, const b2RayCastInput *input, uint64_t maskBits, b2TreeRayCastCallbackFcn *callback, void *context)
Ray-cast against the proxies in the tree.
void b2DynamicTree_Destroy(b2DynamicTree *tree)
Destroy the tree, freeing the node pool.
void b2DynamicTree_ShapeCast(const b2DynamicTree *tree, const b2ShapeCastInput *input, uint64_t maskBits, b2TreeShapeCastCallbackFcn *callback, void *context)
Ray-cast against the proxies in the tree.
void b2DynamicTree_Validate(const b2DynamicTree *tree)
Validate this tree. For testing.
void b2DynamicTree_DestroyProxy(b2DynamicTree *tree, int32_t proxyId)
Destroy a proxy. This asserts if the id is invalid.
float b2DynamicTree_GetAreaRatio(const b2DynamicTree *tree)
Get the ratio of the sum of the node areas to the root area.
float b2TreeRayCastCallbackFcn(const b2RayCastInput *input, int32_t proxyId, int32_t userData, void *context)
This function receives clipped raycast input for a proxy.
Definition collision.h:705
void b2DynamicTree_EnlargeProxy(b2DynamicTree *tree, int32_t proxyId, b2AABB aabb)
Enlarge a proxy and enlarge ancestors as necessary.
float b2TreeShapeCastCallbackFcn(const b2ShapeCastInput *input, int32_t proxyId, int32_t userData, void *context)
This function receives clipped ray-cast input for a proxy.
Definition collision.h:726
int b2DynamicTree_GetProxyCount(const b2DynamicTree *tree)
Get the number of proxies created.
int b2DynamicTree_GetMaxBalance(const b2DynamicTree *tree)
Get the maximum balance of the tree. The balance is the difference in height of the two children of a...
int32_t b2DynamicTree_CreateProxy(b2DynamicTree *tree, b2AABB aabb, uint64_t categoryBits, int32_t userData)
Create a proxy. Provide an AABB and a userData value.
b2DynamicTree b2DynamicTree_Create(void)
Constructing the tree initializes the node pool.
int b2DynamicTree_GetHeight(const b2DynamicTree *tree)
Compute the height of the binary tree in O(N) time.
void b2DynamicTree_ShiftOrigin(b2DynamicTree *tree, b2Vec2 newOrigin)
Shift the world origin.
int32_t b2DynamicTree_GetUserData(const b2DynamicTree *tree, int32_t proxyId)
Get proxy user data.
Definition collision.h:774
int b2DynamicTree_GetByteCount(const b2DynamicTree *tree)
Get the number of bytes used by this tree.
bool b2TreeQueryCallbackFcn(int32_t proxyId, int32_t userData, void *context)
This function receives proxies found in the AABB query.
Definition collision.h:694
void b2DynamicTree_Query(const b2DynamicTree *tree, b2AABB aabb, uint64_t maskBits, b2TreeQueryCallbackFcn *callback, void *context)
Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the ...
void b2DynamicTree_RebuildBottomUp(b2DynamicTree *tree)
Build an optimal tree. Very expensive. For testing.
The dynamic tree structure.
Definition collision.h:639
A node in the dynamic tree. This is private data placed here for performance reasons.
Definition collision.h:600