Functions to create, destroy, and access. More...
Data Structures | |
struct | b2Filter |
This is used to filter collision on shapes. More... | |
struct | b2QueryFilter |
The query filter is used to filter collisions between queries and shapes. More... | |
struct | b2SurfaceMaterial |
Surface materials allow chain shapes to have per segment surface properties. More... | |
struct | b2ShapeDef |
Used to create a shape. More... | |
struct | b2ChainDef |
Used to create a chain of line segments. More... | |
Enumerations | |
enum | b2ShapeType { b2_circleShape , b2_capsuleShape , b2_segmentShape , b2_polygonShape , b2_chainSegmentShape , b2_shapeTypeCount } |
Shape type. More... | |
Functions | |
B2_API b2ShapeId | b2CreateCircleShape (b2BodyId bodyId, const b2ShapeDef *def, const b2Circle *circle) |
Create a circle shape and attach it to a body. | |
B2_API b2ShapeId | b2CreateSegmentShape (b2BodyId bodyId, const b2ShapeDef *def, const b2Segment *segment) |
Create a line segment shape and attach it to a body. | |
B2_API b2ShapeId | b2CreateCapsuleShape (b2BodyId bodyId, const b2ShapeDef *def, const b2Capsule *capsule) |
Create a capsule shape and attach it to a body. | |
B2_API b2ShapeId | b2CreatePolygonShape (b2BodyId bodyId, const b2ShapeDef *def, const b2Polygon *polygon) |
Create a polygon shape and attach it to a body. | |
B2_API void | b2DestroyShape (b2ShapeId shapeId, bool updateBodyMass) |
Destroy a shape. | |
B2_API bool | b2Shape_IsValid (b2ShapeId id) |
Shape identifier validation. Provides validation for up to 64K allocations. | |
B2_API b2ShapeType | b2Shape_GetType (b2ShapeId shapeId) |
Get the type of a shape. | |
B2_API b2BodyId | b2Shape_GetBody (b2ShapeId shapeId) |
Get the id of the body that a shape is attached to. | |
B2_API b2WorldId | b2Shape_GetWorld (b2ShapeId shapeId) |
Get the world that owns this shape. | |
B2_API bool | b2Shape_IsSensor (b2ShapeId shapeId) |
Returns true if the shape is a sensor. | |
B2_API void | b2Shape_SetUserData (b2ShapeId shapeId, void *userData) |
Set the user data for a shape. | |
B2_API void * | b2Shape_GetUserData (b2ShapeId shapeId) |
Get the user data for a shape. | |
B2_API void | b2Shape_SetDensity (b2ShapeId shapeId, float density, bool updateBodyMass) |
Set the mass density of a shape, usually in kg/m^2. | |
B2_API float | b2Shape_GetDensity (b2ShapeId shapeId) |
Get the density of a shape, usually in kg/m^2. | |
B2_API void | b2Shape_SetFriction (b2ShapeId shapeId, float friction) |
Set the friction on a shape. | |
B2_API float | b2Shape_GetFriction (b2ShapeId shapeId) |
Get the friction of a shape. | |
B2_API void | b2Shape_SetRestitution (b2ShapeId shapeId, float restitution) |
Set the shape restitution (bounciness) | |
B2_API float | b2Shape_GetRestitution (b2ShapeId shapeId) |
Get the shape restitution. | |
B2_API void | b2Shape_SetMaterial (b2ShapeId shapeId, int material) |
Set the shape material identifier. | |
B2_API int | b2Shape_GetMaterial (b2ShapeId shapeId) |
Get the shape material identifier. | |
B2_API b2Filter | b2Shape_GetFilter (b2ShapeId shapeId) |
Get the shape filter. | |
B2_API void | b2Shape_SetFilter (b2ShapeId shapeId, b2Filter filter) |
Set the current filter. | |
B2_API void | b2Shape_EnableSensorEvents (b2ShapeId shapeId, bool flag) |
Enable sensor events for this shape. | |
B2_API bool | b2Shape_AreSensorEventsEnabled (b2ShapeId shapeId) |
Returns true if sensor events are enabled. | |
B2_API void | b2Shape_EnableContactEvents (b2ShapeId shapeId, bool flag) |
Enable contact events for this shape. | |
B2_API bool | b2Shape_AreContactEventsEnabled (b2ShapeId shapeId) |
Returns true if contact events are enabled. | |
B2_API void | b2Shape_EnablePreSolveEvents (b2ShapeId shapeId, bool flag) |
Enable pre-solve contact events for this shape. | |
B2_API bool | b2Shape_ArePreSolveEventsEnabled (b2ShapeId shapeId) |
Returns true if pre-solve events are enabled. | |
B2_API void | b2Shape_EnableHitEvents (b2ShapeId shapeId, bool flag) |
Enable contact hit events for this shape. | |
B2_API bool | b2Shape_AreHitEventsEnabled (b2ShapeId shapeId) |
Returns true if hit events are enabled. | |
B2_API bool | b2Shape_TestPoint (b2ShapeId shapeId, b2Vec2 point) |
Test a point for overlap with a shape. | |
B2_API b2CastOutput | b2Shape_RayCast (b2ShapeId shapeId, const b2RayCastInput *input) |
Ray cast a shape directly. | |
B2_API b2Circle | b2Shape_GetCircle (b2ShapeId shapeId) |
Get a copy of the shape's circle. Asserts the type is correct. | |
B2_API b2Segment | b2Shape_GetSegment (b2ShapeId shapeId) |
Get a copy of the shape's line segment. Asserts the type is correct. | |
B2_API b2ChainSegment | b2Shape_GetChainSegment (b2ShapeId shapeId) |
Get a copy of the shape's chain segment. | |
B2_API b2Capsule | b2Shape_GetCapsule (b2ShapeId shapeId) |
Get a copy of the shape's capsule. Asserts the type is correct. | |
B2_API b2Polygon | b2Shape_GetPolygon (b2ShapeId shapeId) |
Get a copy of the shape's convex polygon. Asserts the type is correct. | |
B2_API void | b2Shape_SetCircle (b2ShapeId shapeId, const b2Circle *circle) |
Allows you to change a shape to be a circle or update the current circle. | |
B2_API void | b2Shape_SetCapsule (b2ShapeId shapeId, const b2Capsule *capsule) |
Allows you to change a shape to be a capsule or update the current capsule. | |
B2_API void | b2Shape_SetSegment (b2ShapeId shapeId, const b2Segment *segment) |
Allows you to change a shape to be a segment or update the current segment. | |
B2_API void | b2Shape_SetPolygon (b2ShapeId shapeId, const b2Polygon *polygon) |
Allows you to change a shape to be a polygon or update the current polygon. | |
B2_API b2ChainId | b2Shape_GetParentChain (b2ShapeId shapeId) |
Get the parent chain id if the shape type is a chain segment, otherwise returns b2_nullChainId. | |
B2_API int | b2Shape_GetContactCapacity (b2ShapeId shapeId) |
Get the maximum capacity required for retrieving all the touching contacts on a shape. | |
B2_API int | b2Shape_GetContactData (b2ShapeId shapeId, b2ContactData *contactData, int capacity) |
Get the touching contact data for a shape. | |
B2_API int | b2Shape_GetSensorCapacity (b2ShapeId shapeId) |
Get the maximum capacity required for retrieving all the overlapped shapes on a sensor shape. | |
B2_API int | b2Shape_GetSensorOverlaps (b2ShapeId shapeId, b2ShapeId *overlaps, int capacity) |
Get the overlapped shapes for a sensor shape. | |
B2_API b2AABB | b2Shape_GetAABB (b2ShapeId shapeId) |
Get the current world AABB. | |
B2_API b2MassData | b2Shape_GetMassData (b2ShapeId shapeId) |
Get the mass data for a shape. | |
B2_API b2Vec2 | b2Shape_GetClosestPoint (b2ShapeId shapeId, b2Vec2 target) |
Get the closest point on a shape to a target point. | |
B2_API b2ChainId | b2CreateChain (b2BodyId bodyId, const b2ChainDef *def) |
Chain Shape. | |
B2_API void | b2DestroyChain (b2ChainId chainId) |
Destroy a chain shape. | |
B2_API b2WorldId | b2Chain_GetWorld (b2ChainId chainId) |
Get the world that owns this chain shape. | |
B2_API int | b2Chain_GetSegmentCount (b2ChainId chainId) |
Get the number of segments on this chain. | |
B2_API int | b2Chain_GetSegments (b2ChainId chainId, b2ShapeId *segmentArray, int capacity) |
Fill a user array with chain segment shape ids up to the specified capacity. | |
B2_API void | b2Chain_SetFriction (b2ChainId chainId, float friction) |
Set the chain friction. | |
B2_API float | b2Chain_GetFriction (b2ChainId chainId) |
Get the chain friction. | |
B2_API void | b2Chain_SetRestitution (b2ChainId chainId, float restitution) |
Set the chain restitution (bounciness) | |
B2_API float | b2Chain_GetRestitution (b2ChainId chainId) |
Get the chain restitution. | |
B2_API void | b2Chain_SetMaterial (b2ChainId chainId, int material) |
Set the chain material. | |
B2_API int | b2Chain_GetMaterial (b2ChainId chainId) |
Get the chain material. | |
B2_API bool | b2Chain_IsValid (b2ChainId id) |
Chain identifier validation. Provides validation for up to 64K allocations. | |
b2Filter | b2DefaultFilter (void) |
Use this to initialize your filter. | |
b2QueryFilter | b2DefaultQueryFilter (void) |
Use this to initialize your query filter. | |
b2SurfaceMaterial | b2DefaultSurfaceMaterial (void) |
Use this to initialize your surface material. | |
b2ShapeDef | b2DefaultShapeDef (void) |
Use this to initialize your shape definition. | |
b2ChainDef | b2DefaultChainDef (void) |
Use this to initialize your chain definition. | |
Functions to create, destroy, and access.
Shapes bind raw geometry to bodies and hold material properties including friction and restitution.
struct b2Filter |
This is used to filter collision on shapes.
It affects shape-vs-shape collision and shape-versus-query collision (such as b2World_CastRay).
Data Fields | ||
---|---|---|
uint64_t | categoryBits |
The collision category bits. Normally you would just set one bit. The category bits should represent your application object types. For example: enum MyCategories
{
Static = 0x00000001,
Dynamic = 0x00000002,
Debris = 0x00000004,
Player = 0x00000008,
// etc
};
|
int | groupIndex |
Collision groups allow a certain group of objects to never collide (negative) or always collide (positive). A group index of zero has no effect. Non-zero group filtering always wins against the mask bits. For example, you may want ragdolls to collide with other ragdolls but you don't want ragdoll self-collision. In this case you would give each ragdoll a unique negative group index and apply that group index to all shapes on the ragdoll. |
uint64_t | maskBits |
The collision mask bits. This states the categories that this shape would accept for collision. For example, you may want your player to only collide with static objects and other players. maskBits = Static | Player;
|
struct b2QueryFilter |
The query filter is used to filter collisions between queries and shapes.
For example, you may want a ray-cast representing a projectile to hit players and the static environment but not debris.
struct b2SurfaceMaterial |
Surface materials allow chain shapes to have per segment surface properties.
struct b2ShapeDef |
Used to create a shape.
This is a temporary object used to bundle shape creation parameters. You may use the same shape definition to create multiple shapes. Must be initialized using b2DefaultShapeDef().
Data Fields | ||
---|---|---|
float | density |
The density, usually in kg/m^2. This is not part of the surface material because this is for the interior, which may have other considerations, such as being hollow. For example a wood barrel may be hollow or full of water. |
bool | enableContactEvents | Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default. |
bool | enableHitEvents | Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default. |
bool | enablePreSolveEvents |
Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive and must be carefully handled due to threading. Ignored for sensors. |
bool | enableSensorEvents | Enable sensor events for this shape. This applies to sensors and non-sensors. False by default, even for sensors. |
b2Filter | filter | Collision filtering data. |
int | internalValue | Used internally to detect a valid definition. DO NOT SET. |
bool | invokeContactCreation |
When shapes are created they will scan the environment for collision the next time step. This can significantly slow down static body creation when there are many static shapes. This is flag is ignored for dynamic and kinematic shapes which always invoke contact creation. |
bool | isSensor |
A sensor shape generates overlap events but never generates a collision response. Sensors do not have continuous collision. Instead, use a ray or shape cast for those scenarios. Sensors still contribute to the body mass if they have non-zero density.
|
b2SurfaceMaterial | material | The surface material for this shape. |
bool | updateBodyMass | Should the body update the mass properties when this shape is created. Default is true. |
void * | userData | Use this to store application specific shape data. |
struct b2ChainDef |
Used to create a chain of line segments.
This is designed to eliminate ghost collisions with some limitations.
Data Fields | ||
---|---|---|
int | count | The point count, must be 4 or more. |
bool | enableSensorEvents | Enable sensors to detect this chain. False by default. |
b2Filter | filter | Contact filtering data. |
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 points. |
int | materialCount |
The material count. Must be 1 or count. This allows you to provide one material for all segments or a unique material per segment. |
const b2SurfaceMaterial * | materials | Surface materials for each segment. These are cloned. |
const b2Vec2 * | points | An array of at least 4 points. These are cloned and may be temporary. |
void * | userData | Use this to store application specific shape data. |
enum b2ShapeType |
Fill a user array with chain segment shape ids up to the specified capacity.
Returns the actual number of segments returned.
B2_API void b2Chain_SetFriction | ( | b2ChainId | chainId, |
float | friction ) |
Set the chain friction.
B2_API void b2Chain_SetMaterial | ( | b2ChainId | chainId, |
int | material ) |
Set the chain material.
B2_API void b2Chain_SetRestitution | ( | b2ChainId | chainId, |
float | restitution ) |
Set the chain restitution (bounciness)
B2_API b2ShapeId b2CreateCapsuleShape | ( | b2BodyId | bodyId, |
const b2ShapeDef * | def, | ||
const b2Capsule * | capsule ) |
Create a capsule shape and attach it to a body.
The shape definition and geometry are fully cloned. Contacts are not created until the next time step.
B2_API b2ChainId b2CreateChain | ( | b2BodyId | bodyId, |
const b2ChainDef * | def ) |
B2_API b2ShapeId b2CreateCircleShape | ( | b2BodyId | bodyId, |
const b2ShapeDef * | def, | ||
const b2Circle * | circle ) |
Create a circle shape and attach it to a body.
The shape definition and geometry are fully cloned. Contacts are not created until the next time step.
B2_API b2ShapeId b2CreatePolygonShape | ( | b2BodyId | bodyId, |
const b2ShapeDef * | def, | ||
const b2Polygon * | polygon ) |
Create a polygon shape and attach it to a body.
The shape definition and geometry are fully cloned. Contacts are not created until the next time step.
B2_API b2ShapeId b2CreateSegmentShape | ( | b2BodyId | bodyId, |
const b2ShapeDef * | def, | ||
const b2Segment * | segment ) |
Create a line segment shape and attach it to a body.
The shape definition and geometry are fully cloned. Contacts are not created until the next time step.
B2_API void b2DestroyShape | ( | b2ShapeId | shapeId, |
bool | updateBodyMass ) |
Destroy a shape.
You may defer the body mass update which can improve performance if several shapes on a body are destroyed at once.
B2_API void b2Shape_EnableContactEvents | ( | b2ShapeId | shapeId, |
bool | flag ) |
Enable contact events for this shape.
Only applies to kinematic and dynamic bodies. Ignored for sensors.
B2_API void b2Shape_EnableHitEvents | ( | b2ShapeId | shapeId, |
bool | flag ) |
B2_API void b2Shape_EnablePreSolveEvents | ( | b2ShapeId | shapeId, |
bool | flag ) |
Enable pre-solve contact events for this shape.
Only applies to dynamic bodies. These are expensive and must be carefully handled due to multithreading. Ignored for sensors.
B2_API void b2Shape_EnableSensorEvents | ( | b2ShapeId | shapeId, |
bool | flag ) |
Enable sensor events for this shape.
B2_API b2ChainSegment b2Shape_GetChainSegment | ( | b2ShapeId | shapeId | ) |
Get a copy of the shape's chain segment.
These come from chain shapes. Asserts the type is correct.
Get the closest point on a shape to a target point.
Target and result are in world space. todo need sample
B2_API int b2Shape_GetContactData | ( | b2ShapeId | shapeId, |
b2ContactData * | contactData, | ||
int | capacity ) |
Get the touching contact data for a shape.
The provided shapeId will be either shapeIdA or shapeIdB on the contact data.
B2_API int b2Shape_GetSensorCapacity | ( | b2ShapeId | shapeId | ) |
Get the maximum capacity required for retrieving all the overlapped shapes on a sensor shape.
This returns 0 if the provided shape is not a sensor.
shapeId | the id of a sensor shape |
Get the overlapped shapes for a sensor shape.
shapeId | the id of a sensor shape |
overlaps | a user allocated array that is filled with the overlapping shapes |
capacity | the capacity of overlappedShapes |
B2_API void * b2Shape_GetUserData | ( | b2ShapeId | shapeId | ) |
Get the user data for a shape.
This is useful when you get a shape id from an event or query.
B2_API bool b2Shape_IsSensor | ( | b2ShapeId | shapeId | ) |
Returns true if the shape is a sensor.
It is not possible to change a shape from sensor to solid dynamically because this breaks the contract for sensor events.
Allows you to change a shape to be a capsule or update the current capsule.
This does not modify the mass properties.
Allows you to change a shape to be a circle or update the current circle.
This does not modify the mass properties.
B2_API void b2Shape_SetDensity | ( | b2ShapeId | shapeId, |
float | density, | ||
bool | updateBodyMass ) |
Set the mass density of a shape, usually in kg/m^2.
This will optionally update the mass properties on the parent body.
Set the current filter.
This is almost as expensive as recreating the shape. This may cause contacts to be immediately destroyed. However contacts are not created until the next world step. Sensor overlap state is also not updated until the next world step.
B2_API void b2Shape_SetFriction | ( | b2ShapeId | shapeId, |
float | friction ) |
Set the friction on a shape.
B2_API void b2Shape_SetMaterial | ( | b2ShapeId | shapeId, |
int | material ) |
Set the shape material identifier.
Allows you to change a shape to be a polygon or update the current polygon.
This does not modify the mass properties.
B2_API void b2Shape_SetRestitution | ( | b2ShapeId | shapeId, |
float | restitution ) |
Set the shape restitution (bounciness)