Geometry types and algorithms. More...
Data Structures | |
| struct | b2RayCastInput |
| Low level ray cast input data. More... | |
| struct | b2ShapeProxy |
| A distance proxy is used by the GJK algorithm. More... | |
| struct | b2ShapeCastInput |
| Low level shape cast input in generic form. More... | |
| struct | b2CastOutput |
| Low level ray cast or shape cast 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 two-sided collision. More... | |
| struct | b2ChainSegment |
| A line segment with one-sided collision. More... | |
| struct | b2Hull |
| A convex hull. More... | |
Macros | |
| #define | B2_MAX_POLYGON_VERTICES 8 |
| The maximum number of vertices on a convex polygon. | |
Typedefs | |
| typedef b2CastOutput | b2WorldCastOutput |
| This is an alias in single precision. | |
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. | |
| b2Polygon | b2MakeOffsetPolygon (const b2Hull *hull, b2Vec2 position, b2Rot rotation) |
| Make an offset convex polygon from a convex hull. | |
| b2Polygon | b2MakeOffsetRoundedPolygon (const b2Hull *hull, b2Vec2 position, b2Rot rotation, float radius) |
| Make an offset convex polygon from a convex hull with a radius. | |
| b2Polygon | b2MakeSquare (float halfWidth) |
| Make a square polygon, bypassing the need for a convex hull. | |
| b2Polygon | b2MakeBox (float halfWidth, float halfHeight) |
| Make a box (rectangle) polygon, bypassing the need for a convex hull. | |
| b2Polygon | b2MakeRoundedBox (float halfWidth, float halfHeight, float radius) |
| Make a rounded box, bypassing the need for a convex hull. | |
| b2Polygon | b2MakeOffsetBox (float halfWidth, float halfHeight, b2Vec2 center, b2Rot rotation) |
| Make an offset box, bypassing the need for a convex hull. | |
| 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 | 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, b2WorldTransform transform) |
| Compute the bounding box of a transformed circle. | |
| b2AABB | b2ComputeCapsuleAABB (const b2Capsule *shape, b2WorldTransform transform) |
| Compute the bounding box of a transformed capsule. | |
| b2AABB | b2ComputePolygonAABB (const b2Polygon *shape, b2WorldTransform transform) |
| Compute the bounding box of a transformed polygon. | |
| b2AABB | b2ComputeSegmentAABB (const b2Segment *shape, b2WorldTransform transform) |
| Compute the bounding box of a transformed line segment. | |
| bool | b2PointInCircle (const b2Circle *shape, b2Vec2 point) |
| Test a point for overlap with a circle in local space. | |
| bool | b2PointInCapsule (const b2Capsule *shape, b2Vec2 point) |
| Test a point for overlap with a capsule in local space. | |
| bool | b2PointInPolygon (const b2Polygon *shape, b2Vec2 point) |
| Test a point for overlap with a convex polygon in local space. | |
| b2CastOutput | b2CastRayCircle (const b2Circle *shape, const b2RayCastInput *input) |
| Ray cast versus circle shape in local space. | |
| b2CastOutput | b2CastRayCapsule (const b2Capsule *shape, const b2RayCastInput *input) |
| Ray cast versus capsule shape in local space. | |
| b2CastOutput | b2CastRaySegment (const b2Segment *shape, const b2RayCastInput *input, bool oneSided) |
| Ray cast versus segment shape in local space. | |
| b2CastOutput | b2CastRayPolygon (const b2Polygon *shape, const b2RayCastInput *input) |
| Ray cast versus polygon shape in local space. | |
| b2CastOutput | b2CastShapeCircle (const b2Circle *shape, const b2ShapeCastInput *input) |
| Shape cast versus a circle. | |
| b2CastOutput | b2CastShapeCapsule (const b2Capsule *shape, const b2ShapeCastInput *input) |
| Shape cast versus a capsule. | |
| b2CastOutput | b2CastShapeSegment (const b2Segment *shape, const b2ShapeCastInput *input) |
| Shape cast versus a line segment. | |
| b2CastOutput | b2CastShapePolygon (const b2Polygon *shape, const b2ShapeCastInput *input) |
| Shape cast versus a convex polygon. | |
| b2Hull | b2ComputeHull (const b2Vec2 *points, int 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. Functions should take the shape as the first argument to assist editor auto-complete.
| struct b2RayCastInput |
| struct b2ShapeProxy |
A distance proxy is used by the GJK algorithm.
It encapsulates any shape. You can provide between 1 and B2_MAX_POLYGON_VERTICES points and a radius.
| Data Fields | ||
|---|---|---|
| int | count | The number of points. Must be greater than 0. |
| b2Vec2 | points[B2_MAX_POLYGON_VERTICES] | The point cloud. |
| float | radius | The external radius of the point cloud. May be zero. |
| struct b2ShapeCastInput |
Low level shape cast input in generic form.
This allows casting an arbitrary point cloud wrapped with a radius. For example, a circle is a single point with a non-zero radius. A capsule is two points with a non-zero radius. A box is four points with a zero radius.
| Data Fields | ||
|---|---|---|
| bool | canEncroach |
Allow shape cast to encroach when initially touching. This only works if the radius is greater than zero. |
| float | maxFraction | The maximum fraction of the translation to consider, typically 1. |
| b2ShapeProxy | proxy | A generic shape. |
| b2Vec2 | translation | The translation of the shape cast. |
| struct b2CastOutput |
Low level ray cast or shape cast output data.
The hit point is in the local or relative frame of the input. Returns a zero fraction and normal in the case of initial overlap.
| Data Fields | ||
|---|---|---|
| float | fraction | The fraction of the input translation at collision. |
| bool | hit | Did the cast hit? |
| int | 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 | mass | The mass of the shape, usually in kilograms. |
| float | rotationalInertia | The rotational inertia of the shape about the shape center. |
| struct b2Circle |
A solid circle.
| Data Fields | ||
|---|---|---|
| b2Vec2 | center | The local center. |
| float | radius | The radius. |
| 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_MAX_POLYGON_VERTICES. In most cases you should not need many vertices for a convex polygon.
| Data Fields | ||
|---|---|---|
| b2Vec2 | centroid | The centroid of the polygon. |
| int | count | The number of polygon vertices. |
| b2Vec2 | normals[B2_MAX_POLYGON_VERTICES] | The outward normal vectors of the polygon sides. |
| float | radius | The external radius for rounded polygons. |
| b2Vec2 | vertices[B2_MAX_POLYGON_VERTICES] | The polygon vertices. |
| struct b2Segment |
| struct b2ChainSegment |
A line segment with one-sided collision.
Only collides on the right side. Several of these are generated for a chain shape. ghost1 -> point1 -> point2 -> ghost2
| Data Fields | ||
|---|---|---|
| int | 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 | ||
|---|---|---|
| int | count | The number of points. |
| b2Vec2 | points[B2_MAX_POLYGON_VERTICES] | The final points of the hull. |
| #define B2_MAX_POLYGON_VERTICES 8 |
The maximum number of vertices on a convex polygon.
Changing this affects performance even if you don't use more vertices.
| b2CastOutput b2CastRaySegment | ( | const b2Segment * | shape, |
| const b2RayCastInput * | input, | ||
| bool | oneSided ) |
Ray cast versus segment shape in local space.
Optionally treat the segment as one-sided with hits from the left side being treated as a miss.
Compute the convex hull of a set of points.
Returns an empty hull if it fails. Some failure cases:
This welds close points and removes collinear points.
| b2Polygon b2MakeBox | ( | float | halfWidth, |
| float | halfHeight ) |
Make a box (rectangle) polygon, bypassing the need for a convex hull.
| halfWidth | the half-width (x-axis) |
| halfHeight | the half-height (y-axis) |
Make an offset box, bypassing the need for a convex hull.
| halfWidth | the half-width (x-axis) |
| halfHeight | the half-height (y-axis) |
| center | the local center of the box |
| rotation | the local rotation of the box |
Make an offset convex polygon from a convex hull.
This will assert if the hull is not valid.
| b2Polygon b2MakeOffsetRoundedBox | ( | float | halfWidth, |
| float | halfHeight, | ||
| b2Vec2 | center, | ||
| b2Rot | rotation, | ||
| float | radius ) |
Make an offset rounded box, bypassing the need for a convex hull.
| halfWidth | the half-width (x-axis) |
| halfHeight | the half-height (y-axis) |
| center | the local center of the box |
| rotation | the local rotation of the box |
| radius | the radius of the rounded extension |
| b2Polygon b2MakeOffsetRoundedPolygon | ( | const b2Hull * | hull, |
| b2Vec2 | position, | ||
| b2Rot | rotation, | ||
| float | radius ) |
Make an offset convex polygon from a convex hull with a radius.
This will assert if the hull is not valid.
Make a convex polygon from a convex hull.
This will assert if the hull is not valid.
| b2Polygon b2MakeRoundedBox | ( | float | halfWidth, |
| float | halfHeight, | ||
| float | radius ) |
Make a rounded box, bypassing the need for a convex hull.
| halfWidth | the half-width (x-axis) |
| halfHeight | the half-height (y-axis) |
| radius | the radius of the rounded extension |
| b2Polygon b2MakeSquare | ( | float | halfWidth | ) |
Make a square polygon, bypassing the need for a convex hull.
| halfWidth | the half-width |
| bool b2ValidateHull | ( | const b2Hull * | hull | ) |
This determines if a hull is valid.
Checks for:
This is expensive and should not be called at runtime.