Box2D 3.0.0
A 2D physics engine for games

Data Structures  
struct  b2RayCastInput 
Low level raycast input data. More...  
struct  b2ShapeCastInput 
Low level shape cast input in generic form. More...  
struct  b2CastOutput 
Low level raycast or shapecast output data. More...  
struct  b2MassData 
This holds the mass data computed for a shape. More...  
struct  b2Circle 
A solid circle. More...  
struct  b2Capsule 
A solid capsule can be viewed as two semicircles connected by a rectangle. More...  
struct  b2Polygon 
A solid convex polygon. More...  
struct  b2Segment 
A line segment with twosided collision. More...  
struct  b2SmoothSegment 
A smooth line segment with onesided collision. More...  
struct  b2Hull 
A convex hull. Used to create convex polygons. More...  
Macros  
#define  b2_maxPolygonVertices 8 
The maximum number of vertices on a convex polygon.  
Functions  
bool  b2IsValidRay (const b2RayCastInput *input) 
Validate ray cast input data (NaN, etc)  
b2Polygon  b2MakePolygon (const b2Hull *hull, float radius) 
Make a convex polygon from a convex hull. This will assert if the hull is not valid.  
b2Polygon  b2MakeOffsetPolygon (const b2Hull *hull, float radius, b2Transform transform) 
Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.  
b2Polygon  b2MakeSquare (float h) 
Make a square polygon, bypassing the need for a convex hull.  
b2Polygon  b2MakeBox (float hx, float hy) 
Make a box (rectangle) polygon, bypassing the need for a convex hull.  
b2Polygon  b2MakeRoundedBox (float hx, float hy, float radius) 
Make a rounded box, bypassing the need for a convex hull.  
b2Polygon  b2MakeOffsetBox (float hx, float hy, b2Vec2 center, float angle) 
Make an offset box, bypassing the need for a convex hull.  
b2Polygon  b2TransformPolygon (b2Transform transform, const b2Polygon *polygon) 
Transform a polygon. This is useful for transferring a shape from one body to another.  
b2MassData  b2ComputeCircleMass (const b2Circle *shape, float density) 
Compute mass properties of a circle.  
b2MassData  b2ComputeCapsuleMass (const b2Capsule *shape, float density) 
Compute mass properties of a capsule.  
b2MassData  b2ComputePolygonMass (const b2Polygon *shape, float density) 
Compute mass properties of a polygon.  
b2AABB  b2ComputeCircleAABB (const b2Circle *shape, b2Transform transform) 
Compute the bounding box of a transformed circle.  
b2AABB  b2ComputeCapsuleAABB (const b2Capsule *shape, b2Transform transform) 
Compute the bounding box of a transformed capsule.  
b2AABB  b2ComputePolygonAABB (const b2Polygon *shape, b2Transform transform) 
Compute the bounding box of a transformed polygon.  
b2AABB  b2ComputeSegmentAABB (const b2Segment *shape, b2Transform transform) 
Compute the bounding box of a transformed line segment.  
bool  b2PointInCircle (b2Vec2 point, const b2Circle *shape) 
Test a point for overlap with a circle in local space.  
bool  b2PointInCapsule (b2Vec2 point, const b2Capsule *shape) 
Test a point for overlap with a capsule in local space.  
bool  b2PointInPolygon (b2Vec2 point, const b2Polygon *shape) 
Test a point for overlap with a convex polygon in local space.  
b2CastOutput  b2RayCastCircle (const b2RayCastInput *input, const b2Circle *shape) 
Ray cast versus circle in shape local space. Initial overlap is treated as a miss.  
b2CastOutput  b2RayCastCapsule (const b2RayCastInput *input, const b2Capsule *shape) 
Ray cast versus capsule in shape local space. Initial overlap is treated as a miss.  
b2CastOutput  b2RayCastSegment (const b2RayCastInput *input, const b2Segment *shape, bool oneSided) 
Ray cast versus segment in shape local space.  
b2CastOutput  b2RayCastPolygon (const b2RayCastInput *input, const b2Polygon *shape) 
Ray cast versus polygon 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.  
b2CastOutput  b2ShapeCastCapsule (const b2ShapeCastInput *input, const b2Capsule *shape) 
Shape cast versus a capsule. Initial overlap is treated as a miss.  
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.  
b2Hull  b2ComputeHull (const b2Vec2 *points, int32_t count) 
Compute the convex hull of a set of points.  
bool  b2ValidateHull (const b2Hull *hull) 
This determines if a hull is valid.  
Geometry types and algorithms
Definitions of circles, capsules, segments, and polygons. Various algorithms to compute hulls, mass properties, and so on.
struct b2RayCastInput 
struct b2ShapeCastInput 
Low level shape cast input in generic form.
This allows casting an arbitrary point cloud wrap with a radius. For example, a circle is a single point with a nonzero radius. A capsule is two points with a nonzero radius. A box is four points with a zero radius.
Data Fields  

int32_t  count  The number of points. 
float  maxFraction  The maximum fraction of the translation to consider, typically 1. 
b2Vec2  points[b2_maxPolygonVertices]  A point cloud to cast. 
float  radius  The radius around the point cloud. 
b2Vec2  translation  The translation of the shape cast. 
struct b2CastOutput 
Low level raycast or shapecast output data.
Data Fields  

float  fraction  The fraction of the input translation at collision. 
bool  hit  Did the cast hit? 
int32_t  iterations  The number of iterations used. 
b2Vec2  normal  The surface normal at the hit point. 
b2Vec2  point  The surface hit point. 
struct b2MassData 
This holds the mass data computed for a shape.
Data Fields  

b2Vec2  center  The position of the shape's centroid relative to the shape's origin. 
float  I  The rotational inertia of the shape about the local origin. 
float  mass  The mass of the shape, usually in kilograms. 
struct b2Circle 
struct b2Capsule 
struct b2Polygon 
A solid convex polygon.
It is assumed that the interior of the polygon is to the left of each edge. Polygons have a maximum number of vertices equal to b2_maxPolygonVertices. In most cases you should not need many vertices for a convex polygon.
Data Fields  

b2Vec2  centroid  The centroid of the polygon. 
int32_t  count  The number of polygon vertices. 
b2Vec2  normals[b2_maxPolygonVertices]  The outward normal vectors of the polygon sides. 
float  radius  The external radius for rounded polygons. 
b2Vec2  vertices[b2_maxPolygonVertices]  The polygon vertices. 
struct b2Segment 
struct b2SmoothSegment 
A smooth line segment with onesided collision.
Only collides on the right side. Several of these are generated for a chain shape. ghost1 > point1 > point2 > ghost2
Data Fields  

int32_t  chainId  The owning chain shape index (internal usage only) 
b2Vec2  ghost1  The tail ghost vertex. 
b2Vec2  ghost2  The head ghost vertex. 
b2Segment  segment  The line segment. 
struct b2Hull 
A convex hull. Used to create convex polygons.
Data Fields  

int32_t  count  The number of points. 
b2Vec2  points[b2_maxPolygonVertices]  The final points of the hull. 
#define b2_maxPolygonVertices 8 
The maximum number of vertices on a convex polygon.
Changing this affects performance even if you don't use more vertices.
Compute the convex hull of a set of points.
Returns an empty hull if it fails. Some failure cases:
b2CastOutput b2RayCastSegment  (  const b2RayCastInput *  input, 
const b2Segment *  shape,  
bool  oneSided ) 
Ray cast versus segment in shape local space.
Optionally treat the segment as onesided with hits from the left side being treated as a miss.
bool b2ValidateHull  (  const b2Hull *  hull  ) 
This determines if a hull is valid.
Checks for: