7#include "math_functions.h"
24#define B2_MAX_POLYGON_VERTICES 8
413 int simplexCapacity );
467 b2_toiStateOverlapped,
float push
The push on the mover determined by b2SolvePlanes. Usually in meters.
Definition collision.h:804
bool clipVelocity
Indicates if b2ClipVector should clip against this plane. Should be false for soft collision.
Definition collision.h:807
b2Plane plane
The collision plane between the mover and a convex shape.
Definition collision.h:786
bool hit
Did the collision register a hit? If not this plane should be ignored.
Definition collision.h:789
float pushLimit
Setting this to FLT_MAX makes the plane as rigid as possible.
Definition collision.h:801
b2Vec2 position
The final position of the mover.
Definition collision.h:814
b2Plane plane
The collision plane between the mover and some shape.
Definition collision.h:797
int iterationCount
The number of iterations used by the plane solver. For diagnostics.
Definition collision.h:817
b2Vec2 b2ClipVector(b2Vec2 vector, const b2CollisionPlane *planes, int count)
Clips the velocity against the given collision planes.
b2PlaneSolverResult b2SolvePlanes(b2Vec2 position, 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:795
These are the collision planes returned from b2World_CollideMover.
Definition collision.h:784
Result returned by b2SolvePlanes.
Definition collision.h:812
float normalImpulse
The impulse along the manifold normal vector.
Definition collision.h:516
float tangentImpulse
The friction impulse.
Definition collision.h:519
b2Vec2 point
Location of the contact point in world space.
Definition collision.h:502
b2Vec2 normal
The unit normal vector in world space, points from shape A to bodyB.
Definition collision.h:541
b2Vec2 anchorA
Location of the contact point relative to shapeA's origin in world space.
Definition collision.h:506
int pointCount
The number of contacts points, will be 0, 1, or 2.
Definition collision.h:550
b2ManifoldPoint points[2]
The manifold points, up to two are possible in 2D.
Definition collision.h:547
float separation
The separation of the contact point, negative if penetrating.
Definition collision.h:513
uint16_t id
Uniquely identifies a contact point between two shapes.
Definition collision.h:530
b2Vec2 anchorB
Location of the contact point relative to shapeB's origin in world space.
Definition collision.h:510
float totalNormalImpulse
The total normal impulse applied across sub-stepping and restitution.
Definition collision.h:523
bool persisted
Did this contact point exist the previous step?
Definition collision.h:533
float normalVelocity
Relative normal velocity pre-solve.
Definition collision.h:527
float rollingImpulse
Angular impulse applied for rolling resistance. N * m * s = kg * m^2 / s.
Definition collision.h:544
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, b2SimplexCache *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, b2SimplexCache *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:539
A manifold point is a contact point belonging to a contact manifold.
Definition collision.h:499
uint8_t indexB[3]
The cached simplex indices on shape B.
Definition collision.h:356
b2Transform transformA
The world transform for shape A.
Definition collision.h:371
float fraction1
The barycentric coordinate on the first segment.
Definition collision.h:331
float distanceSquared
The squared distance between the closest points.
Definition collision.h:337
int count
number of valid vertices
Definition collision.h:406
float fraction
The sweep time of the collision.
Definition collision.h:476
b2Rot q2
Ending world rotation.
Definition collision.h:446
b2Vec2 c1
Starting center of mass world position.
Definition collision.h:443
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:419
float distance
The final distance, zero if overlapped.
Definition collision.h:386
b2Vec2 w
wB - wA
Definition collision.h:396
b2Vec2 wA
support point in proxyA
Definition collision.h:394
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:456
b2Transform transformB
The world transform for shape B.
Definition collision.h:374
b2Vec2 localCenter
Local center of mass position.
Definition collision.h:442
float maxFraction
The fraction of the translation to consider, typically 1.
Definition collision.h:423
b2Vec2 c2
Ending center of mass world position.
Definition collision.h:444
b2Transform transformA
The world transform for shape A.
Definition collision.h:420
b2Vec2 closest1
The closest point on the first segment.
Definition collision.h:325
bool canEncroach
Allows shapes with a radius to move slightly closer if already touching.
Definition collision.h:424
b2Vec2 wB
support point in proxyB
Definition collision.h:395
b2SimplexVertex v3
vertices
Definition collision.h:405
b2Vec2 normal
Normal vector that points from A to B.
Definition collision.h:385
b2Vec2 translationB
The translation of shape B.
Definition collision.h:422
b2Vec2 pointA
Closest point on shapeA.
Definition collision.h:383
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:455
b2Transform transformB
The world transform for shape B.
Definition collision.h:421
int iterations
Number of GJK iterations used.
Definition collision.h:387
b2Rot q1
Starting world rotation.
Definition collision.h:445
float maxFraction
Defines the sweep interval [0, maxFraction].
Definition collision.h:459
uint16_t count
The number of stored simplex points.
Definition collision.h:350
uint8_t indexA[3]
The cached simplex indices on shape A.
Definition collision.h:353
b2Vec2 pointB
Closest point on shapeB.
Definition collision.h:384
float fraction2
The barycentric coordinate on the second segment.
Definition collision.h:334
int indexB
wB index
Definition collision.h:399
bool useRadii
Should the proxy radius be considered?
Definition collision.h:377
b2TOIState state
The type of result.
Definition collision.h:475
b2Vec2 closest2
The closest point on the second segment.
Definition collision.h:328
float a
barycentric coordinate for closest point
Definition collision.h:397
b2ShapeProxy proxyB
The proxy for shape B.
Definition collision.h:368
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:365
int simplexCount
The number of simplexes stored in the simplex array.
Definition collision.h:388
b2Sweep sweepA
The movement of shape A.
Definition collision.h:457
b2ShapeProxy proxyA
The proxy for shape A.
Definition collision.h:418
int indexA
wA index
Definition collision.h:398
b2Sweep sweepB
The movement of shape B.
Definition collision.h:458
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.
b2DistanceOutput b2ShapeDistance(const b2DistanceInput *input, b2SimplexCache *cache, b2Simplex *simplexes, int simplexCapacity)
Compute the closest points between two shapes represented as point clouds.
b2Transform b2GetSweepTransform(const b2Sweep *sweep, float time)
Evaluate the transform sweep at a specific time.
b2TOIState
Describes the TOI output.
Definition collision.h:464
b2ShapeProxy b2MakeProxy(const b2Vec2 *points, int count, float radius)
Make a proxy for use in overlap, shape cast, and related functions. This is a deep copy of the points...
b2CastOutput b2ShapeCast(const b2ShapeCastPairInput *input)
Perform a linear shape cast of shape B moving and shape A fixed.
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.
Output for b2ShapeDistance.
Definition collision.h:382
Result of computing the distance between two line segments.
Definition collision.h:323
Simplex from the GJK algorithm.
Definition collision.h:404
Used to warm start the GJK simplex.
Definition collision.h:348
Simplex vertex for debugging the GJK algorithm.
Definition collision.h:393
This describes the motion of a body/shape for TOI computation.
Definition collision.h:441
Output parameters for b2TimeOfImpact.
Definition collision.h:474
b2Vec2 center2
Local center of the second semicircle.
Definition collision.h:121
int count
The number of points.
Definition collision.h:290
b2Vec2 centroid
The centroid of the polygon.
Definition collision.h:142
b2Vec2 normals[B2_MAX_POLYGON_VERTICES]
The outward normal vectors of the polygon sides.
Definition collision.h:139
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition collision.h:97
float radius
The external radius of the point cloud. May be zero.
Definition collision.h:50
b2Vec2 point1
The first point.
Definition collision.h:155
b2Vec2 normal
The surface normal at the hit point.
Definition collision.h:75
b2Vec2 points[B2_MAX_POLYGON_VERTICES]
The final points of the hull.
Definition collision.h:287
float mass
The mass of the shape, usually in kilograms.
Definition collision.h:94
b2Vec2 origin
Start point of the ray cast.
Definition collision.h:30
bool canEncroach
Allow shape cast to encroach when initially touching. This only works if the radius is greater than z...
Definition collision.h:68
b2Vec2 point
The surface hit point.
Definition collision.h:78
int iterations
The number of iterations used.
Definition collision.h:84
bool hit
Did the cast hit?
Definition collision.h:87
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:65
b2ShapeProxy proxy
A generic shape.
Definition collision.h:59
int count
The number of points. Must be greater than 0.
Definition collision.h:47
float fraction
The fraction of the input translation at collision.
Definition collision.h:81
int chainId
The owning chain shape index (internal usage only)
Definition collision.h:176
float radius
The radius.
Definition collision.h:110
b2Vec2 center1
Local center of the first semicircle.
Definition collision.h:118
float radius
The external radius for rounded polygons.
Definition collision.h:145
b2Vec2 points[B2_MAX_POLYGON_VERTICES]
The point cloud.
Definition collision.h:44
b2Vec2 center
The local center.
Definition collision.h:107
b2Vec2 point2
The second point.
Definition collision.h:158
float radius
The radius of the semicircles.
Definition collision.h:124
b2Vec2 translation
The translation of the shape cast.
Definition collision.h:62
b2Vec2 translation
Translation of the ray cast.
Definition collision.h:33
b2Vec2 ghost2
The head ghost vertex.
Definition collision.h:173
b2Vec2 vertices[B2_MAX_POLYGON_VERTICES]
The polygon vertices.
Definition collision.h:136
b2Vec2 ghost1
The tail ghost vertex.
Definition collision.h:167
float maxFraction
The maximum fraction of the translation to consider, typically 1.
Definition collision.h:36
b2Segment segment
The line segment.
Definition collision.h:170
float rotationalInertia
The rotational inertia of the shape about the local origin.
Definition collision.h:100
int count
The number of polygon vertices.
Definition collision.h:148
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.
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.
b2CastOutput b2ShapeCastSegment(const b2ShapeCastInput *input, const b2Segment *shape)
Shape cast versus a line segment. Initial overlap is treated as a miss.
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.
b2Polygon b2MakeOffsetRoundedPolygon(const b2Hull *hull, b2Vec2 position, b2Rot rotation, float radius)
Make an offset convex polygon from a convex hull.
b2CastOutput b2RayCastPolygon(const b2RayCastInput *input, const b2Polygon *shape)
Ray cast versus polygon shape in local space. Initial overlap is treated as a miss.
b2CastOutput b2RayCastCircle(const b2RayCastInput *input, const b2Circle *shape)
Ray cast versus circle shape in 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.
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:24
b2Polygon b2MakeRoundedBox(float halfWidth, float halfHeight, float radius)
Make a rounded box, bypassing the need for a convex hull.
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 shape in local space. Initial overlap is treated as a miss.
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.
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 shape in local space.
b2Polygon b2MakePolygon(const b2Hull *hull, float radius)
Make a 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.
b2Hull b2ComputeHull(const b2Vec2 *points, int count)
Compute the convex hull of a set of points.
b2AABB b2ComputeCapsuleAABB(const b2Capsule *shape, b2Transform transform)
Compute the bounding box of a transformed 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.
A solid capsule can be viewed as two semicircles connected by a rectangle.
Definition collision.h:116
Low level ray cast or shape-cast output data.
Definition collision.h:73
A line segment with one-sided collision.
Definition collision.h:165
A solid circle.
Definition collision.h:105
A convex hull.
Definition collision.h:285
This holds the mass data computed for a shape.
Definition collision.h:92
A solid convex polygon.
Definition collision.h:134
A line segment with two-sided collision.
Definition collision.h:153
A distance proxy is used by the GJK algorithm.
Definition collision.h:42
Axis-aligned bounding box.
Definition math_functions.h:59
separation = dot(normal, point) - offset
Definition math_functions.h:66
2D rotation This is similar to using a complex number for rotation
Definition math_functions.h:38
2D vector This can be used to represent a point or free vector
Definition math_functions.h:21
b2AABB * leafBoxes
Leaf bounding boxes for rebuild.
Definition collision.h:645
int rebuildCapacity
Allocated space for rebuilding.
Definition collision.h:654
b2Vec2 * leafCenters
Leaf bounding box centers for rebuild.
Definition collision.h:648
int freeList
Node free list.
Definition collision.h:636
int leafVisits
Number of leaf nodes visited during the query.
Definition collision.h:664
int root
The root index.
Definition collision.h:627
int proxyCount
Number of proxies created.
Definition collision.h:639
int nodeCapacity
The allocated node space.
Definition collision.h:633
int * leafIndices
Leaf indices for rebuild.
Definition collision.h:642
int * binIndices
Bins for sorting during rebuild.
Definition collision.h:651
int nodeCount
The number of nodes.
Definition collision.h:630
int nodeVisits
Number of internal nodes visited during the query.
Definition collision.h:661
struct b2TreeNode * nodes
The tree nodes.
Definition collision.h:624
uint64_t b2DynamicTree_GetUserData(const b2DynamicTree *tree, int proxyId)
Get proxy user data.
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_Destroy(b2DynamicTree *tree)
Destroy the tree, freeing the node pool.
void b2DynamicTree_Validate(const b2DynamicTree *tree)
Validate this tree. For testing.
float b2DynamicTree_GetAreaRatio(const b2DynamicTree *tree)
Get the ratio of the sum of the node areas to the root area.
void b2DynamicTree_DestroyProxy(b2DynamicTree *tree, int proxyId)
Destroy a proxy. This asserts if the id is invalid.
b2TreeStats b2DynamicTree_ShapeCast(const b2DynamicTree *tree, const b2ShapeCastInput *input, uint64_t maskBits, b2TreeShapeCastCallbackFcn *callback, void *context)
Ray cast against the proxies in the tree.
b2AABB b2DynamicTree_GetRootBounds(const b2DynamicTree *tree)
Get the bounding box that contains the entire tree.
bool b2TreeQueryCallbackFcn(int proxyId, uint64_t userData, void *context)
This function receives proxies found in the AABB query.
Definition collision.h:693
float b2TreeShapeCastCallbackFcn(const b2ShapeCastInput *input, int proxyId, uint64_t userData, void *context)
This function receives clipped ray cast input for a proxy.
Definition collision.h:728
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:705
int b2DynamicTree_GetProxyCount(const b2DynamicTree *tree)
Get the number of proxies created.
void b2DynamicTree_MoveProxy(b2DynamicTree *tree, int proxyId, b2AABB aabb)
Move a proxy to a new AABB by removing and reinserting into the tree.
uint64_t b2DynamicTree_GetCategoryBits(b2DynamicTree *tree, int proxyId)
Get the category bits on a proxy.
int b2DynamicTree_CreateProxy(b2DynamicTree *tree, b2AABB aabb, uint64_t categoryBits, uint64_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)
Get the height of the binary tree.
void b2DynamicTree_ValidateNoEnlarged(const b2DynamicTree *tree)
Validate this tree has no enlarged AABBs. For testing.
b2AABB b2DynamicTree_GetAABB(const b2DynamicTree *tree, int proxyId)
Get the AABB of a proxy.
void b2DynamicTree_EnlargeProxy(b2DynamicTree *tree, int proxyId, b2AABB aabb)
Enlarge a proxy and enlarge ancestors as necessary.
b2TreeStats b2DynamicTree_RayCast(const b2DynamicTree *tree, const b2RayCastInput *input, uint64_t maskBits, b2TreeRayCastCallbackFcn *callback, void *context)
Ray cast against the proxies in the tree.
int b2DynamicTree_GetByteCount(const b2DynamicTree *tree)
Get the number of bytes used by this tree.
void b2DynamicTree_SetCategoryBits(b2DynamicTree *tree, int proxyId, uint64_t categoryBits)
Modify the category bits on a proxy. This is an expensive operation.
b2TreeStats b2DynamicTree_Query(const b2DynamicTree *tree, b2AABB aabb, uint64_t maskBits, b2TreeQueryCallbackFcn *callback, void *context)
Query an AABB for overlapping proxies.
The dynamic tree structure.
Definition collision.h:622
These are performance results returned by dynamic tree queries.
Definition collision.h:659