This is the body API. More...
Data Structures | |
| struct | b3MotionLocks |
| Motion locks to restrict the body movement. More... | |
| struct | b3BodyDef |
| A body definition holds all the data needed to construct a rigid body. More... | |
Enumerations | |
| enum | b3BodyType { b3_staticBody = 0 , b3_kinematicBody = 1 , b3_dynamicBody = 2 , b3_bodyTypeCount } |
| The body simulation type. More... | |
Functions | |
| b3BodyId | b3CreateBody (b3WorldId worldId, const b3BodyDef *def) |
| Create a rigid body given a definition. | |
| void | b3DestroyBody (b3BodyId bodyId) |
| Destroy a rigid body given an id. | |
| bool | b3Body_IsValid (b3BodyId id) |
| Body identifier validation. | |
| b3BodyType | b3Body_GetType (b3BodyId bodyId) |
| Get the body type: static, kinematic, or dynamic. | |
| void | b3Body_SetType (b3BodyId bodyId, b3BodyType type) |
| Change the body type. | |
| void | b3Body_SetName (b3BodyId bodyId, const char *name) |
| Set the body name. Up to B3_BODY_NAME_LENGTH characters including null termination. | |
| const char * | b3Body_GetName (b3BodyId bodyId) |
| Get the body name. | |
| void | b3Body_SetUserData (b3BodyId bodyId, void *userData) |
| Set the user data for a body. | |
| void * | b3Body_GetUserData (b3BodyId bodyId) |
| Get the user data stored in a body. | |
| b3Pos | b3Body_GetPosition (b3BodyId bodyId) |
| Get the world position of a body. This is the location of the body origin. | |
| b3Quat | b3Body_GetRotation (b3BodyId bodyId) |
| Get the world rotation of a body as a quaternion. | |
| b3WorldTransform | b3Body_GetTransform (b3BodyId bodyId) |
| Get the world transform of a body. | |
| void | b3Body_SetTransform (b3BodyId bodyId, b3Pos position, b3Quat rotation) |
| Set the world transform of a body. | |
| b3Vec3 | b3Body_GetLocalPoint (b3BodyId bodyId, b3Pos worldPoint) |
| Get a local point on a body given a world point. | |
| b3Pos | b3Body_GetWorldPoint (b3BodyId bodyId, b3Vec3 localPoint) |
| Get a world point on a body given a local point. | |
| b3Vec3 | b3Body_GetLocalVector (b3BodyId bodyId, b3Vec3 worldVector) |
| Get a local vector on a body given a world vector. | |
| b3Vec3 | b3Body_GetWorldVector (b3BodyId bodyId, b3Vec3 localVector) |
| Get a world vector on a body given a local vector. | |
| b3Vec3 | b3Body_GetLinearVelocity (b3BodyId bodyId) |
| Get the linear velocity of a body's center of mass. Usually in meters per second. | |
| b3Vec3 | b3Body_GetAngularVelocity (b3BodyId bodyId) |
| Get the angular velocity of a body in radians per second. | |
| void | b3Body_SetLinearVelocity (b3BodyId bodyId, b3Vec3 linearVelocity) |
| Set the linear velocity of a body. Usually in meters per second. | |
| void | b3Body_SetAngularVelocity (b3BodyId bodyId, b3Vec3 angularVelocity) |
| Set the angular velocity of a body in radians per second. | |
| void | b3Body_SetTargetTransform (b3BodyId bodyId, b3WorldTransform target, float timeStep, bool wake) |
| Set the velocity to reach the given transform after a given time step. | |
| b3Vec3 | b3Body_GetLocalPointVelocity (b3BodyId bodyId, b3Vec3 localPoint) |
| Get the linear velocity of a local point attached to a body. Usually in meters per second. | |
| b3Vec3 | b3Body_GetWorldPointVelocity (b3BodyId bodyId, b3Pos worldPoint) |
| Get the linear velocity of a world point attached to a body. Usually in meters per second. | |
| void | b3Body_ApplyForce (b3BodyId bodyId, b3Vec3 force, b3Pos point, bool wake) |
| Apply a force at a world point. | |
| void | b3Body_ApplyForceToCenter (b3BodyId bodyId, b3Vec3 force, bool wake) |
| Apply a force to the center of mass. | |
| void | b3Body_ApplyTorque (b3BodyId bodyId, b3Vec3 torque, bool wake) |
| Apply a torque. | |
| void | b3Body_ApplyLinearImpulse (b3BodyId bodyId, b3Vec3 impulse, b3Pos point, bool wake) |
| Apply an impulse at a point. | |
| void | b3Body_ApplyLinearImpulseToCenter (b3BodyId bodyId, b3Vec3 impulse, bool wake) |
| Apply an impulse to the center of mass. | |
| void | b3Body_ApplyAngularImpulse (b3BodyId bodyId, b3Vec3 impulse, bool wake) |
| Apply an angular impulse in world space. | |
| float | b3Body_GetMass (b3BodyId bodyId) |
| Get the mass of the body, usually in kilograms. | |
| b3Matrix3 | b3Body_GetLocalRotationalInertia (b3BodyId bodyId) |
| Get the rotational inertia of the body in local space, usually in kg*m^2. | |
| float | b3Body_GetInverseMass (b3BodyId bodyId) |
| Get the inverse mass of the body, usually in 1/kilograms. | |
| b3Matrix3 | b3Body_GetWorldInverseRotationalInertia (b3BodyId bodyId) |
| Get the inverse rotational inertia of the body in world space, usually in 1/kg*m^2. | |
| b3Vec3 | b3Body_GetLocalCenterOfMass (b3BodyId bodyId) |
| Get the center of mass position of the body in local space. | |
| b3Pos | b3Body_GetWorldCenterOfMass (b3BodyId bodyId) |
| Get the center of mass position of the body in world space. | |
| void | b3Body_SetMassData (b3BodyId bodyId, b3MassData massData) |
| Override the body's mass properties. | |
| b3MassData | b3Body_GetMassData (b3BodyId bodyId) |
| Get the mass data for a body. | |
| void | b3Body_ApplyMassFromShapes (b3BodyId bodyId) |
| This updates the mass properties to the sum of the mass properties of the shapes. | |
| void | b3Body_SetLinearDamping (b3BodyId bodyId, float linearDamping) |
| Adjust the linear damping. Normally this is set in b3BodyDef before creation. | |
| float | b3Body_GetLinearDamping (b3BodyId bodyId) |
| Get the current linear damping. | |
| void | b3Body_SetAngularDamping (b3BodyId bodyId, float angularDamping) |
| Adjust the angular damping. Normally this is set in b3BodyDef before creation. | |
| float | b3Body_GetAngularDamping (b3BodyId bodyId) |
| Get the current angular damping. | |
| void | b3Body_SetGravityScale (b3BodyId bodyId, float gravityScale) |
| Adjust the gravity scale. | |
| float | b3Body_GetGravityScale (b3BodyId bodyId) |
| Get the current gravity scale. | |
| bool | b3Body_IsAwake (b3BodyId bodyId) |
| void | b3Body_SetAwake (b3BodyId bodyId, bool awake) |
| Wake a body from sleep. | |
| void | b3Body_EnableSleep (b3BodyId bodyId, bool enableSleep) |
| Enable or disable sleeping for this body. If sleeping is disabled the body will wake. | |
| bool | b3Body_IsSleepEnabled (b3BodyId bodyId) |
| Returns true if sleeping is enabled for this body. | |
| void | b3Body_SetSleepThreshold (b3BodyId bodyId, float sleepThreshold) |
| Set the sleep threshold, usually in meters per second. | |
| float | b3Body_GetSleepThreshold (b3BodyId bodyId) |
| Get the sleep threshold, usually in meters per second. | |
| bool | b3Body_IsEnabled (b3BodyId bodyId) |
| Returns true if this body is enabled. | |
| void | b3Body_Disable (b3BodyId bodyId) |
| Disable a body by removing it completely from the simulation. This is expensive. | |
| void | b3Body_Enable (b3BodyId bodyId) |
| Enable a body by adding it to the simulation. This is expensive. | |
| void | b3Body_SetMotionLocks (b3BodyId bodyId, b3MotionLocks locks) |
| Set the motion locks on this body. | |
| b3MotionLocks | b3Body_GetMotionLocks (b3BodyId bodyId) |
| Get the motion locks for this body. | |
| void | b3Body_SetBullet (b3BodyId bodyId, bool flag) |
| Set this body to be a bullet. | |
| bool | b3Body_IsBullet (b3BodyId bodyId) |
| Is this body a bullet? | |
| void | b3Body_EnableContactRecycling (b3BodyId bodyId, bool flag) |
| Enable or disable contact recycling for this body. | |
| bool | b3Body_IsContactRecyclingEnabled (b3BodyId bodyId) |
| Is contact recycling enabled on this body? | |
| void | b3Body_EnableHitEvents (b3BodyId bodyId, bool enableHitEvents) |
| Enable/disable hit events on all shapes. | |
| b3WorldId | b3Body_GetWorld (b3BodyId bodyId) |
| Get the world that owns this body. | |
| int | b3Body_GetShapeCount (b3BodyId bodyId) |
| Get the number of shapes on this body. | |
| int | b3Body_GetShapes (b3BodyId bodyId, b3ShapeId *shapeArray, int capacity) |
| Get the shape ids for all shapes on this body, up to the provided capacity. | |
| int | b3Body_GetJointCount (b3BodyId bodyId) |
| Get the number of joints on this body. | |
| int | b3Body_GetJoints (b3BodyId bodyId, b3JointId *jointArray, int capacity) |
| Get the joint ids for all joints on this body, up to the provided capacity. | |
| int | b3Body_GetContactCapacity (b3BodyId bodyId) |
| Get the maximum capacity required for retrieving all the touching contacts on a body. | |
| int | b3Body_GetContactData (b3BodyId bodyId, b3ContactData *contactData, int capacity) |
| Get the touching contact data for a body. | |
| b3AABB | b3Body_ComputeAABB (b3BodyId bodyId) |
| Get the current world AABB that contains all the attached shapes. | |
| float | b3Body_GetClosestPoint (b3BodyId bodyId, b3Vec3 *result, b3Vec3 target) |
| Get the closest point on a body to a world target. | |
| b3BodyCastResult | b3Body_CastRay (b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, float maxFraction, b3WorldTransform bodyTransform) |
| Cast a ray at a specific body using a specified body transform. | |
| b3BodyCastResult | b3Body_CastShape (b3BodyId bodyId, b3Pos origin, const b3ShapeProxy *proxy, b3Vec3 translation, b3QueryFilter filter, float maxFraction, bool canEncroach, b3WorldTransform bodyTransform) |
| Cast a shape at a specific body using a specified body transform. | |
| bool | b3Body_OverlapShape (b3BodyId bodyId, b3Pos origin, const b3ShapeProxy *proxy, b3QueryFilter filter, b3WorldTransform bodyTransform) |
| Overlap a shape with a specific body using a specified body transform. | |
| int | b3Body_CollideMover (b3BodyId bodyId, b3BodyPlaneResult *bodyPlanes, int planeCapacity, b3Pos origin, const b3Capsule *mover, b3QueryFilter filter, b3WorldTransform bodyTransform) |
| Collide a character mover with a specific body using a specified body transform. | |
| b3BodyDef | b3DefaultBodyDef (void) |
| Use this to initialize your body definition. | |
This is the body API.
| struct b3MotionLocks |
Motion locks to restrict the body movement.
| struct b3BodyDef |
A body definition holds all the data needed to construct a rigid body.
You can safely re-use body definitions. Shapes are added to a body after construction. Body definitions are temporary objects used to bundle creation parameters. Must be initialized using b3DefaultBodyDef().

| Data Fields | ||
|---|---|---|
| bool | allowFastRotation |
This allows this body to bypass rotational speed limits. Should only be used for circular objects, like wheels. |
| float | angularDamping |
Angular damping is used to reduce the angular velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Angular damping can be used to slow down rotating bodies. |
| b3Vec3 | angularVelocity | The initial angular velocity of the body. Radians per second. |
| bool | enableContactRecycling |
Enable contact recycling. True by default. Leaving this enabled improves performance but may lead to ghost collision that should be avoided on characters. |
| bool | enableSleep | Set this flag to false if this body should never fall asleep. |
| float | gravityScale | Scale the gravity applied to this body. Non-dimensional. |
| int | internalValue | Used internally to detect a valid definition. DO NOT SET. |
| bool | isAwake | Is this body initially awake or sleeping? |
| bool | isBullet |
Treat this body as a high speed object that performs continuous collision detection against dynamic and kinematic bodies, but not other bullet bodies.
|
| bool | isEnabled | Used to disable a body. A disabled body does not move or collide. |
| float | linearDamping |
Linear damping is used to reduce the linear velocity. The damping parameter can be larger than 1 but the damping effect becomes sensitive to the time step when the damping parameter is large. Generally linear damping is undesirable because it makes objects move slowly as if they are floating. |
| b3Vec3 | linearVelocity | The initial linear velocity of the body's origin. Usually in meters per second. |
| b3MotionLocks | motionLocks | Motions locks to restrict linear and angular movement. |
| const char * | name | Optional body name for debugging. Up to B3_BODY_NAME_LENGTH characters (including null termination). |
| b3Pos | position |
The initial world position of the body. Bodies should be created with the desired position.
|
| b3Quat | rotation | The initial world rotation of the body. |
| float | sleepThreshold | Sleep speed threshold, default is 0.05 meters per second. |
| b3BodyType | type | The body type: static, kinematic, or dynamic. |
| void * | userData | Use this to store application specific body data. |
| enum b3BodyType |
The body simulation type.
Each body is one of these three types. The type determines how the body behaves in the simulation.
Apply an angular impulse in world space.
The impulse is ignored if the body is not awake. This optionally wakes the body.
| bodyId | The body id |
| impulse | the world angular impulse vector, usually in units of kg*m*m/s |
| wake | also wake up the body |
Apply a force at a world point.
If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This optionally wakes up the body. The force is ignored if the body is not awake.
| bodyId | The body id |
| force | The world force vector, usually in newtons (N) |
| point | The world position of the point of application |
| wake | Option to wake up the body |
Apply a force to the center of mass.
This optionally wakes up the body. The force is ignored if the body is not awake.
| bodyId | The body id |
| force | the world force vector, usually in newtons (N). |
| wake | also wake up the body |
Apply an impulse at a point.
This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This optionally wakes the body. The impulse is ignored if the body is not awake.
| bodyId | The body id |
| impulse | the world impulse vector, usually in N*s or kg*m/s. |
| point | the world position of the point of application. |
| wake | also wake up the body |
Apply an impulse to the center of mass.
This immediately modifies the velocity. The impulse is ignored if the body is not awake. This optionally wakes the body.
| bodyId | The body id |
| impulse | the world impulse vector, usually in N*s or kg*m/s. |
| wake | also wake up the body |
| void b3Body_ApplyMassFromShapes | ( | b3BodyId | bodyId | ) |
This updates the mass properties to the sum of the mass properties of the shapes.
This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass. You may also use this when automatic mass computation has been disabled. You should call this regardless of body type.
Apply a torque.
This affects the angular velocity without affecting the linear velocity. This optionally wakes the body. The torque is ignored if the body is not awake.
| bodyId | The body id |
| torque | the world torque vector, usually in N*m. |
| wake | also wake up the body |
Get the current world AABB that contains all the attached shapes.
Note that this may not encompass the body origin. If there are no shapes attached then the returned AABB is empty and centered on the body origin.
| void b3Body_EnableContactRecycling | ( | b3BodyId | bodyId, |
| bool | flag ) |
Enable or disable contact recycling for this body.
Contact recycling is a performance optimization that reuses contact manifolds when bodies move slightly. Disabling it can avoid ghost collisions on characters at the cost of higher per-step work. Existing contacts retain their prior setting; only contacts created after this call see the new value.
| void b3Body_EnableHitEvents | ( | b3BodyId | bodyId, |
| bool | enableHitEvents ) |
Enable/disable hit events on all shapes.
Get the joint ids for all joints on this body, up to the provided capacity.
Get the shape ids for all shapes on this body, up to the provided capacity.
| bool b3Body_IsAwake | ( | b3BodyId | bodyId | ) |
| bool b3Body_IsValid | ( | b3BodyId | id | ) |
Body identifier validation.
A valid body exists in a world and is non-null. This can be used to detect orphaned ids. Provides validation for up to 64K allocations.
| void b3Body_SetAwake | ( | b3BodyId | bodyId, |
| bool | awake ) |
Wake a body from sleep.
This wakes the entire island the body is touching.
| void b3Body_SetBullet | ( | b3BodyId | bodyId, |
| bool | flag ) |
Set this body to be a bullet.
A bullet does continuous collision detection against dynamic bodies (but not other bullets).
| void b3Body_SetGravityScale | ( | b3BodyId | bodyId, |
| float | gravityScale ) |
Adjust the gravity scale.
Normally this is set in b3BodyDef before creation.
| void b3Body_SetMassData | ( | b3BodyId | bodyId, |
| b3MassData | massData ) |
Override the body's mass properties.
Normally this is computed automatically using the shape geometry and density. This information is lost if a shape is added or removed or if the body type changes.
| void b3Body_SetTargetTransform | ( | b3BodyId | bodyId, |
| b3WorldTransform | target, | ||
| float | timeStep, | ||
| bool | wake ) |
Set the velocity to reach the given transform after a given time step.
The result will be close but maybe not exact. This is meant for kinematic bodies. The target is not applied if the velocity would be below the sleep threshold. This will optionally wake the body if asleep, but only if the movement is significant.
Set the world transform of a body.
This acts as a teleport and is fairly expensive.
| void b3Body_SetType | ( | b3BodyId | bodyId, |
| b3BodyType | type ) |
Change the body type.
This is an expensive operation. This automatically updates the mass properties regardless of the automatic mass setting.
Create a rigid body given a definition.
No reference to the definition is retained. So you can create the definition on the stack and pass it as a pointer.
| void b3DestroyBody | ( | b3BodyId | bodyId | ) |
Destroy a rigid body given an id.
This destroys all shapes and joints attached to the body. Do not keep references to the associated shapes and joints.