Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches

Chain shapes allow you to create a polygonal chain that is resistant to ghost collisions. More...

Data Structures

struct  b2ChainDef
 Used to create a chain of line segments. More...

Functions

b2ChainId b2CreateChain (b2BodyId bodyId, const b2ChainDef *def)
 Create a chain shape.
void b2DestroyChain (b2ChainId chainId)
 Destroy a chain shape.
b2WorldId b2Chain_GetWorld (b2ChainId chainId)
 Get the world that owns this chain shape.
int b2Chain_GetSegmentCount (b2ChainId chainId)
 Get the number of segments on this chain.
int b2Chain_GetSegments (b2ChainId chainId, b2ShapeId *segmentArray, int capacity)
 Fill a user array with chain segment shape ids up to the specified capacity.
void b2Chain_SetAllSurfaceMaterials (b2ChainId chainId, const b2SurfaceMaterial *material)
 Set the chain material on all segments.
void b2Chain_SetSurfaceMaterial (b2ChainId chainId, const b2SurfaceMaterial *material, int segmentIndex)
 Set a chain material by segment index.
b2SurfaceMaterial b2Chain_GetSurfaceMaterial (b2ChainId chainId, int segmentIndex)
 Get a chain material by segment index.
bool b2Chain_IsValid (b2ChainId id)
 Chain identifier validation. Provides validation for up to 64K allocations.
b2ChainDef b2DefaultChainDef (void)
 Use this to initialize your chain definition.

Detailed Description

Chain shapes allow you to create a polygonal chain that is resistant to ghost collisions.

See https://box2d.org/posts/2020/06/ghost-collisions/


Data Structure Documentation

◆ b2ChainDef

struct b2ChainDef

Used to create a chain of line segments.

This is designed to eliminate ghost collisions with some limitations.

  • chains are one-sided
  • chains have no mass and should be used on static bodies
  • chains have a counter-clockwise winding order (normal points right of segment direction)
  • chains are either a loop or open
  • the distance between any two points must be greater than B2_LINEAR_SLOP
  • a chain shape should not self intersect (this is not validated)
  • an open chain shape needs a leading and trailing ghost point.
  • you may overlap two open chains using the ghost points to get smooth collision.
  • a chain shape creates multiple line segment shapes on the body https://en.wikipedia.org/wiki/Polygonal_chain Must be initialized using b2DefaultChainDef().
    Warning
    Do not use chain shapes unless you understand the limitations. This is an advanced feature.
Data Fields
bool enableSensorEvents Enable sensors to detect this chain. False by default.
b2Filter filter Contact filtering data.
b2Vec2 ghost1 Leading ghost point for an open chain.

Distance from first point must be greater than B2_LINEAR_SLOP. Ignored for loops.

b2Vec2 ghost2 Ending ghost point for an open chain.

Distance from last point must be greater than B2_LINEAR_SLOP. Ignored for loops.

int internalValue Used internally to detect a valid definition. DO NOT SET.
bool isLoop Indicates a closed chain formed by connecting the first and last point.
int materialCount The material count. Must be 1 or the segment count.
const b2SurfaceMaterial * materials One material for the whole chain or one for each segment. Cloned.
int pointCount The point count.

At least 2 for an open chain and at least 3 for a loop. segmentCount = isLoop ? pointCount : pointCount - 1

const b2Vec2 * points Array of chain points.

Each consecutive pair forms a segment. For a loop the last and first point form a segment. Cloned.

void * userData Use this to store application specific shape data.

Function Documentation

◆ b2Chain_GetSegments()

int b2Chain_GetSegments ( b2ChainId chainId,
b2ShapeId * segmentArray,
int capacity )

Fill a user array with chain segment shape ids up to the specified capacity.

Returns the actual number of segments returned.

◆ b2CreateChain()

b2ChainId b2CreateChain ( b2BodyId bodyId,
const b2ChainDef * def )

Create a chain shape.

See also
b2ChainDef for details