7#include "math_functions.h"
30#define b2_maxPolygonVertices 8
396 int simplexCapacity );
445 b2_toiStateOverlapped,
592#define b2_defaultCategoryBits ( 1 )
596#define b2_defaultMaskBits ( UINT64_MAX )
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
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
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
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
A line segment with two-sided collision.
Definition collision.h:148
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
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