This is the body API. More...
Data Structures | |
struct | b2BodyDef |
A body definition holds all the data needed to construct a rigid body. More... | |
Enumerations | |
enum | b2BodyType { b2_staticBody = 0 , b2_kinematicBody = 1 , b2_dynamicBody = 2 , b2_bodyTypeCount } |
The body simulation type. More... | |
Functions | |
B2_API b2BodyId | b2CreateBody (b2WorldId worldId, const b2BodyDef *def) |
Create a rigid body given a definition. | |
B2_API void | b2DestroyBody (b2BodyId bodyId) |
Destroy a rigid body given an id. | |
B2_API bool | b2Body_IsValid (b2BodyId id) |
Body identifier validation. Can be used to detect orphaned ids. Provides validation for up to 64K allocations. | |
B2_API b2BodyType | b2Body_GetType (b2BodyId bodyId) |
Get the body type: static, kinematic, or dynamic. | |
B2_API void | b2Body_SetType (b2BodyId bodyId, b2BodyType type) |
Change the body type. | |
B2_API void | b2Body_SetName (b2BodyId bodyId, const char *name) |
Set the body name. Up to 31 characters excluding 0 termination. | |
B2_API const char * | b2Body_GetName (b2BodyId bodyId) |
Get the body name. May be null. | |
B2_API void | b2Body_SetUserData (b2BodyId bodyId, void *userData) |
Set the user data for a body. | |
B2_API void * | b2Body_GetUserData (b2BodyId bodyId) |
Get the user data stored in a body. | |
B2_API b2Vec2 | b2Body_GetPosition (b2BodyId bodyId) |
Get the world position of a body. This is the location of the body origin. | |
B2_API b2Rot | b2Body_GetRotation (b2BodyId bodyId) |
Get the world rotation of a body as a cosine/sine pair (complex number) | |
B2_API b2Transform | b2Body_GetTransform (b2BodyId bodyId) |
Get the world transform of a body. | |
B2_API void | b2Body_SetTransform (b2BodyId bodyId, b2Vec2 position, b2Rot rotation) |
Set the world transform of a body. | |
B2_API b2Vec2 | b2Body_GetLocalPoint (b2BodyId bodyId, b2Vec2 worldPoint) |
Get a local point on a body given a world point. | |
B2_API b2Vec2 | b2Body_GetWorldPoint (b2BodyId bodyId, b2Vec2 localPoint) |
Get a world point on a body given a local point. | |
B2_API b2Vec2 | b2Body_GetLocalVector (b2BodyId bodyId, b2Vec2 worldVector) |
Get a local vector on a body given a world vector. | |
B2_API b2Vec2 | b2Body_GetWorldVector (b2BodyId bodyId, b2Vec2 localVector) |
Get a world vector on a body given a local vector. | |
B2_API b2Vec2 | b2Body_GetLinearVelocity (b2BodyId bodyId) |
Get the linear velocity of a body's center of mass. Usually in meters per second. | |
B2_API float | b2Body_GetAngularVelocity (b2BodyId bodyId) |
Get the angular velocity of a body in radians per second. | |
B2_API void | b2Body_SetLinearVelocity (b2BodyId bodyId, b2Vec2 linearVelocity) |
Set the linear velocity of a body. Usually in meters per second. | |
B2_API void | b2Body_SetAngularVelocity (b2BodyId bodyId, float angularVelocity) |
Set the angular velocity of a body in radians per second. | |
B2_API void | b2Body_SetTargetTransform (b2BodyId bodyId, b2Transform target, float timeStep) |
Set the velocity to reach the given transform after a given time step. | |
B2_API b2Vec2 | b2Body_GetLocalPointVelocity (b2BodyId bodyId, b2Vec2 localPoint) |
Get the linear velocity of a local point attached to a body. Usually in meters per second. | |
B2_API b2Vec2 | b2Body_GetWorldPointVelocity (b2BodyId bodyId, b2Vec2 worldPoint) |
Get the linear velocity of a world point attached to a body. Usually in meters per second. | |
B2_API void | b2Body_ApplyForce (b2BodyId bodyId, b2Vec2 force, b2Vec2 point, bool wake) |
Apply a force at a world point. | |
B2_API void | b2Body_ApplyForceToCenter (b2BodyId bodyId, b2Vec2 force, bool wake) |
Apply a force to the center of mass. | |
B2_API void | b2Body_ApplyTorque (b2BodyId bodyId, float torque, bool wake) |
Apply a torque. | |
B2_API void | b2Body_ApplyLinearImpulse (b2BodyId bodyId, b2Vec2 impulse, b2Vec2 point, bool wake) |
Apply an impulse at a point. | |
B2_API void | b2Body_ApplyLinearImpulseToCenter (b2BodyId bodyId, b2Vec2 impulse, bool wake) |
Apply an impulse to the center of mass. | |
B2_API void | b2Body_ApplyAngularImpulse (b2BodyId bodyId, float impulse, bool wake) |
Apply an angular impulse. | |
B2_API float | b2Body_GetMass (b2BodyId bodyId) |
Get the mass of the body, usually in kilograms. | |
B2_API float | b2Body_GetRotationalInertia (b2BodyId bodyId) |
Get the rotational inertia of the body, usually in kg*m^2. | |
B2_API b2Vec2 | b2Body_GetLocalCenterOfMass (b2BodyId bodyId) |
Get the center of mass position of the body in local space. | |
B2_API b2Vec2 | b2Body_GetWorldCenterOfMass (b2BodyId bodyId) |
Get the center of mass position of the body in world space. | |
B2_API void | b2Body_SetMassData (b2BodyId bodyId, b2MassData massData) |
Override the body's mass properties. | |
B2_API b2MassData | b2Body_GetMassData (b2BodyId bodyId) |
Get the mass data for a body. | |
B2_API void | b2Body_ApplyMassFromShapes (b2BodyId bodyId) |
This update the mass properties to the sum of the mass properties of the shapes. | |
B2_API void | b2Body_SetLinearDamping (b2BodyId bodyId, float linearDamping) |
Adjust the linear damping. Normally this is set in b2BodyDef before creation. | |
B2_API float | b2Body_GetLinearDamping (b2BodyId bodyId) |
Get the current linear damping. | |
B2_API void | b2Body_SetAngularDamping (b2BodyId bodyId, float angularDamping) |
Adjust the angular damping. Normally this is set in b2BodyDef before creation. | |
B2_API float | b2Body_GetAngularDamping (b2BodyId bodyId) |
Get the current angular damping. | |
B2_API void | b2Body_SetGravityScale (b2BodyId bodyId, float gravityScale) |
Adjust the gravity scale. | |
B2_API float | b2Body_GetGravityScale (b2BodyId bodyId) |
Get the current gravity scale. | |
B2_API bool | b2Body_IsAwake (b2BodyId bodyId) |
B2_API void | b2Body_SetAwake (b2BodyId bodyId, bool awake) |
Wake a body from sleep. | |
B2_API void | b2Body_EnableSleep (b2BodyId bodyId, bool enableSleep) |
Enable or disable sleeping for this body. If sleeping is disabled the body will wake. | |
B2_API bool | b2Body_IsSleepEnabled (b2BodyId bodyId) |
Returns true if sleeping is enabled for this body. | |
B2_API void | b2Body_SetSleepThreshold (b2BodyId bodyId, float sleepThreshold) |
Set the sleep threshold, usually in meters per second. | |
B2_API float | b2Body_GetSleepThreshold (b2BodyId bodyId) |
Get the sleep threshold, usually in meters per second. | |
B2_API bool | b2Body_IsEnabled (b2BodyId bodyId) |
Returns true if this body is enabled. | |
B2_API void | b2Body_Disable (b2BodyId bodyId) |
Disable a body by removing it completely from the simulation. This is expensive. | |
B2_API void | b2Body_Enable (b2BodyId bodyId) |
Enable a body by adding it to the simulation. This is expensive. | |
B2_API void | b2Body_SetFixedRotation (b2BodyId bodyId, bool flag) |
Set this body to have fixed rotation. This causes the mass to be reset in all cases. | |
B2_API bool | b2Body_IsFixedRotation (b2BodyId bodyId) |
Does this body have fixed rotation? | |
B2_API void | b2Body_SetBullet (b2BodyId bodyId, bool flag) |
Set this body to be a bullet. | |
B2_API bool | b2Body_IsBullet (b2BodyId bodyId) |
Is this body a bullet? | |
B2_API void | b2Body_EnableContactEvents (b2BodyId bodyId, bool flag) |
Enable/disable contact events on all shapes. | |
B2_API void | b2Body_EnableHitEvents (b2BodyId bodyId, bool flag) |
Enable/disable hit events on all shapes. | |
B2_API b2WorldId | b2Body_GetWorld (b2BodyId bodyId) |
Get the world that owns this body. | |
B2_API int | b2Body_GetShapeCount (b2BodyId bodyId) |
Get the number of shapes on this body. | |
B2_API int | b2Body_GetShapes (b2BodyId bodyId, b2ShapeId *shapeArray, int capacity) |
Get the shape ids for all shapes on this body, up to the provided capacity. | |
B2_API int | b2Body_GetJointCount (b2BodyId bodyId) |
Get the number of joints on this body. | |
B2_API int | b2Body_GetJoints (b2BodyId bodyId, b2JointId *jointArray, int capacity) |
Get the joint ids for all joints on this body, up to the provided capacity. | |
B2_API int | b2Body_GetContactCapacity (b2BodyId bodyId) |
Get the maximum capacity required for retrieving all the touching contacts on a body. | |
B2_API int | b2Body_GetContactData (b2BodyId bodyId, b2ContactData *contactData, int capacity) |
Get the touching contact data for a body. | |
B2_API b2AABB | b2Body_ComputeAABB (b2BodyId bodyId) |
Get the current world AABB that contains all the attached shapes. | |
b2BodyDef | b2DefaultBodyDef (void) |
Use this to initialize your body definition. | |
This is the body API.
struct b2BodyDef |
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 b2DefaultBodyDef().
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 use slow down rotating bodies. |
float | angularVelocity | The initial angular velocity of the body. Radians per second. |
bool | enableSleep | Set this flag to false if this body should never fall asleep. |
bool | fixedRotation | Should this body be prevented from rotating? Useful for characters. |
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 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. |
b2Vec2 | linearVelocity | The initial linear velocity of the body's origin. Usually in meters per second. |
const char * | name | Optional body name for debugging. Up to 31 characters (excluding null termination) |
b2Vec2 | position |
The initial world position of the body. Bodies should be created with the desired position.
|
b2Rot | rotation | The initial world rotation of the body. Use b2MakeRot() if you have an angle. |
float | sleepThreshold | Sleep speed threshold, default is 0.05 meters per second. |
b2BodyType | type | The body type: static, kinematic, or dynamic. |
void * | userData | Use this to store application specific body data. |
enum b2BodyType |
The body simulation type.
Each body is one of these three types. The type determines how the body behaves in the simulation.
B2_API void b2Body_ApplyAngularImpulse | ( | b2BodyId | bodyId, |
float | impulse, | ||
bool | wake ) |
Apply an angular impulse.
The impulse is ignored if the body is not awake. This optionally wakes the body.
bodyId | The body id |
impulse | the angular impulse, 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 |
B2_API void b2Body_ApplyMassFromShapes | ( | b2BodyId | bodyId | ) |
This update 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. Note that sensor shapes may have mass.
B2_API void b2Body_ApplyTorque | ( | b2BodyId | bodyId, |
float | torque, | ||
bool | wake ) |
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 | about the z-axis (out of the screen), 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.
B2_API void b2Body_EnableContactEvents | ( | b2BodyId | bodyId, |
bool | flag ) |
Enable/disable contact events on all shapes.
B2_API void b2Body_EnableHitEvents | ( | b2BodyId | bodyId, |
bool | flag ) |
Enable/disable hit events on all shapes.
B2_API int b2Body_GetContactData | ( | b2BodyId | bodyId, |
b2ContactData * | contactData, | ||
int | capacity ) |
Get the touching contact data for a body.
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.
B2_API bool b2Body_IsAwake | ( | b2BodyId | bodyId | ) |
B2_API void b2Body_SetAwake | ( | b2BodyId | bodyId, |
bool | awake ) |
Wake a body from sleep.
This wakes the entire island the body is touching.
B2_API void b2Body_SetBullet | ( | b2BodyId | bodyId, |
bool | flag ) |
Set this body to be a bullet.
A bullet does continuous collision detection against dynamic bodies (but not other bullets).
B2_API void b2Body_SetGravityScale | ( | b2BodyId | bodyId, |
float | gravityScale ) |
Adjust the gravity scale.
Normally this is set in b2BodyDef before creation.
B2_API void b2Body_SetMassData | ( | b2BodyId | bodyId, |
b2MassData | 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.
B2_API void b2Body_SetTargetTransform | ( | b2BodyId | bodyId, |
b2Transform | target, | ||
float | timeStep ) |
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. This will automatically wake the body if asleep.
Set the world transform of a body.
This acts as a teleport and is fairly expensive.
B2_API void b2Body_SetType | ( | b2BodyId | bodyId, |
b2BodyType | 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.
B2_API void b2DestroyBody | ( | b2BodyId | 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.