This is the body API. More...
Data Structures | |
| struct | b2MotionLocks |
| Motion locks to restrict the body movement. More... | |
| struct | b2BodyDef |
| A body definition holds all the data needed to construct a rigid body. More... | |
Enumerations | |
| enum | b2BodyType |
| The body simulation type. More... | |
Functions | |
| b2BodyId | b2CreateBody (b2WorldId worldId, const b2BodyDef *def) |
| Create a rigid body given a definition. | |
| void | b2DestroyBody (b2BodyId bodyId) |
| Destroy a rigid body given an id. | |
| bool | b2Body_IsValid (b2BodyId id) |
| Body identifier validation. | |
| b2BodyType | b2Body_GetType (b2BodyId bodyId) |
| Get the body type: static, kinematic, or dynamic. | |
| void | b2Body_SetType (b2BodyId bodyId, b2BodyType type) |
| Change the body type. | |
| void | b2Body_SetName (b2BodyId bodyId, const char *name) |
| Set the body name. See B2_NAME_LENGTH. | |
| const char * | b2Body_GetName (b2BodyId bodyId) |
| Get the body name. | |
| void | b2Body_SetUserData (b2BodyId bodyId, void *userData) |
| Set the user data for a body. | |
| void * | b2Body_GetUserData (b2BodyId bodyId) |
| Get the user data stored in a body. | |
| b2Pos | b2Body_GetPosition (b2BodyId bodyId) |
| Get the world position of a body. This is the location of the body origin. | |
| b2Rot | b2Body_GetRotation (b2BodyId bodyId) |
| Get the world rotation of a body as a cosine/sine pair (complex number). | |
| b2WorldTransform | b2Body_GetTransform (b2BodyId bodyId) |
| Get the world transform of a body. | |
| void | b2Body_SetTransform (b2BodyId bodyId, b2Pos position, b2Rot rotation) |
| Set the world transform of a body. | |
| b2Vec2 | b2Body_GetLocalPoint (b2BodyId bodyId, b2Pos worldPoint) |
| Get a local point on a body given a world point. | |
| b2Pos | b2Body_GetWorldPoint (b2BodyId bodyId, b2Vec2 localPoint) |
| Get a world point on a body given a local point. | |
| b2Vec2 | b2Body_GetLocalVector (b2BodyId bodyId, b2Vec2 worldVector) |
| Get a local vector on a body given a world vector. | |
| b2Vec2 | b2Body_GetWorldVector (b2BodyId bodyId, b2Vec2 localVector) |
| Get a world vector on a body given a local vector. | |
| b2Vec2 | b2Body_GetLinearVelocity (b2BodyId bodyId) |
| Get the linear velocity of a body's center of mass. Usually in meters per second. | |
| float | b2Body_GetAngularVelocity (b2BodyId bodyId) |
| Get the angular velocity of a body in radians per second. | |
| void | b2Body_SetLinearVelocity (b2BodyId bodyId, b2Vec2 linearVelocity) |
| Set the linear velocity of a body. Usually in meters per second. | |
| void | b2Body_SetAngularVelocity (b2BodyId bodyId, float angularVelocity) |
| Set the angular velocity of a body in radians per second. | |
| void | b2Body_SetTargetTransform (b2BodyId bodyId, b2WorldTransform target, float timeStep, bool wake) |
| Set the velocity to reach the given transform after a given time step. | |
| b2Vec2 | b2Body_GetLocalPointVelocity (b2BodyId bodyId, b2Vec2 localPoint) |
| Get the linear velocity of a local point attached to a body. Usually in meters per second. | |
| b2Vec2 | b2Body_GetWorldPointVelocity (b2BodyId bodyId, b2Pos worldPoint) |
| Get the linear velocity of a world point attached to a body. Usually in meters per second. | |
| void | b2Body_ApplyForce (b2BodyId bodyId, b2Vec2 force, b2Pos point, bool wake) |
| Apply a force at a world point. | |
| void | b2Body_ApplyForceToCenter (b2BodyId bodyId, b2Vec2 force, bool wake) |
| Apply a force to the center of mass. | |
| void | b2Body_ApplyTorque (b2BodyId bodyId, float torque, bool wake) |
| Apply a torque. | |
| void | b2Body_ClearForces (b2BodyId bodyId) |
| Clear the force and torque on this body. | |
| void | b2Body_ApplyLinearImpulse (b2BodyId bodyId, b2Vec2 impulse, b2Pos point, bool wake) |
| Apply an impulse at a point. | |
| void | b2Body_ApplyLinearImpulseToCenter (b2BodyId bodyId, b2Vec2 impulse, bool wake) |
| Apply an impulse to the center of mass. | |
| void | b2Body_ApplyAngularImpulse (b2BodyId bodyId, float impulse, bool wake) |
| Apply an angular impulse. | |
| float | b2Body_GetMass (b2BodyId bodyId) |
| Get the mass of the body, usually in kilograms. | |
| float | b2Body_GetRotationalInertia (b2BodyId bodyId) |
| Get the rotational inertia of the body, usually in kg*m^2. | |
| b2Vec2 | b2Body_GetLocalCenter (b2BodyId bodyId) |
| Get the center of mass position of the body in local space. | |
| b2Pos | b2Body_GetWorldCenter (b2BodyId bodyId) |
| Get the center of mass position of the body in world space. | |
| void | b2Body_SetMassData (b2BodyId bodyId, b2MassData massData) |
| Override the body's mass properties. | |
| b2MassData | b2Body_GetMassData (b2BodyId bodyId) |
| Get the mass data for a body. | |
| void | b2Body_UpdateMassFromShapes (b2BodyId bodyId) |
| This updates the mass properties to the sum of the mass properties of the shapes. | |
| void | b2Body_SetLinearDamping (b2BodyId bodyId, float linearDamping) |
| Adjust the linear damping. Normally this is set in b2BodyDef before creation. | |
| float | b2Body_GetLinearDamping (b2BodyId bodyId) |
| Get the current linear damping. | |
| void | b2Body_SetAngularDamping (b2BodyId bodyId, float angularDamping) |
| Adjust the angular damping. Normally this is set in b2BodyDef before creation. | |
| float | b2Body_GetAngularDamping (b2BodyId bodyId) |
| Get the current angular damping. | |
| void | b2Body_SetGravityScale (b2BodyId bodyId, float gravityScale) |
| Adjust the gravity scale. | |
| float | b2Body_GetGravityScale (b2BodyId bodyId) |
| Get the current gravity scale. | |
| bool | b2Body_IsAwake (b2BodyId bodyId) |
| void | b2Body_SetAwake (b2BodyId bodyId, bool awake) |
| Wake a body from sleep. | |
| void | b2Body_WakeTouching (b2BodyId bodyId) |
| Wake bodies touching this body. Works for static bodies. | |
| void | b2Body_EnableSleeping (b2BodyId bodyId, bool enableSleep) |
| Enable or disable sleeping for this body. | |
| bool | b2Body_IsSleepingEnabled (b2BodyId bodyId) |
| Returns true if sleeping is enabled for this body. | |
| void | b2Body_SetSleepThreshold (b2BodyId bodyId, float sleepThreshold) |
| Set the sleep threshold, usually in meters per second. | |
| float | b2Body_GetSleepThreshold (b2BodyId bodyId) |
| Get the sleep threshold, usually in meters per second. | |
| void | b2Body_SetSafetyFactor (b2BodyId bodyId, float safetyFactor) |
| Set the continuous collision safety factor. | |
| float | b2Body_GetSafetyFactor (b2BodyId bodyId) |
| Get the continuous collision safety factor. Non-dimensional. | |
| bool | b2Body_IsEnabled (b2BodyId bodyId) |
| Returns true if this body is enabled. | |
| void | b2Body_Disable (b2BodyId bodyId) |
| Disable a body by removing it completely from the simulation. This is expensive. | |
| void | b2Body_Enable (b2BodyId bodyId) |
| Enable a body by adding it to the simulation. This is expensive. | |
| void | b2Body_SetMotionLocks (b2BodyId bodyId, b2MotionLocks locks) |
| Set the motion locks on this body. | |
| b2MotionLocks | b2Body_GetMotionLocks (b2BodyId bodyId) |
| Get the motion locks for this body. | |
| void | b2Body_SetBullet (b2BodyId bodyId, bool flag) |
| Set this body to be a bullet. | |
| bool | b2Body_IsBullet (b2BodyId bodyId) |
| Is this body a bullet? | |
| void | b2Body_EnableContactRecycling (b2BodyId bodyId, bool flag) |
| Enable or disable contact recycling for this body. | |
| bool | b2Body_IsContactRecyclingEnabled (b2BodyId bodyId) |
| Is contact recycling enabled on this body? | |
| void | b2Body_EnableContactEvents (b2BodyId bodyId, bool flag) |
| Enable/disable contact events on all shapes. | |
| void | b2Body_EnableHitEvents (b2BodyId bodyId, bool flag) |
| Enable/disable hit events on all shapes. | |
| b2WorldId | b2Body_GetWorld (b2BodyId bodyId) |
| Get the world that owns this body. | |
| int | b2Body_GetShapeCount (b2BodyId bodyId) |
| Get the number of shapes on this body. | |
| int | b2Body_GetShapes (b2BodyId bodyId, b2ShapeId *shapeArray, int capacity) |
| Get the shape ids for all shapes on this body, up to the provided capacity. | |
| int | b2Body_GetJointCount (b2BodyId bodyId) |
| Get the number of joints on this body. | |
| int | b2Body_GetJoints (b2BodyId bodyId, b2JointId *jointArray, int capacity) |
| Get the joint ids for all joints on this body, up to the provided capacity. | |
| int | b2Body_GetContactCapacity (b2BodyId bodyId) |
| Get the maximum capacity required for retrieving all the touching contacts on a body. | |
| int | b2Body_GetContactData (b2BodyId bodyId, b2ContactData *contactData, int capacity) |
| Get the touching contact data for a body. | |
| b2AABB | b2Body_ComputeBounds (b2BodyId bodyId) |
| Get the current world AABB that contains all the attached shapes. | |
| float | b2Body_GetMinExtent (b2BodyId bodyId) |
| The minimum distance from any point on the body shapes to the center of mass. | |
| float | b2Body_GetMaxExtent (b2BodyId bodyId) |
| The maximum distance from any point on the body shapes to the center of mass. | |
| float | b2Body_GetMaxExtentFromOrigin (b2BodyId bodyId) |
| The maximum distance from any point on the body shapes to the body origin. Conservative. | |
| b2BodyDef | b2DefaultBodyDef (void) |
| Use this to initialize your body definition. | |
This is the body API.
| struct b2MotionLocks |
| 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 used to slow down rotating bodies. |
| float | 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 collisions 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 dynamic 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. |
| b2Vec2 | linearVelocity | The initial linear velocity of the body's origin. Usually in meters per second. |
| b2MotionLocks | motionLocks |
Motion locks to restrict linear and angular movement. Caution: may lead to softer constraints along the locked direction |
| const char * | name | Optional body name for debugging. Up to B2_NAME_LENGTH characters. |
| b2Pos | 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 | safetyFactor |
Continuous collision safety factor. The solver only uses continuous collision if there is a risk of tunneling. If the body is moving fast enough to risk tunneling then it is considered a "fast body". This improves performance and prevents movement hitches. If a body moving N meters risks tunneling, then the body will be considered fast if it moves more than a safetyFactor times N meters over one full time step. Non-dimensional. Recommended range [0.01, 0.5]. Default is 0.5 for high performance with low tunneling risk. |
| 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.
| 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 |
| 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 |
| void b2Body_ClearForces | ( | b2BodyId | bodyId | ) |
Clear the force and torque on this body.
Forces and torques are automatically cleared after each world step. So this only needs to be called if the application wants to remove the effect of previous calls to apply forces and torques before the world step is called.
| bodyId | The body id |
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 b2Body_EnableContactEvents | ( | b2BodyId | bodyId, |
| bool | flag ) |
Enable/disable contact events on all shapes.
| void b2Body_EnableContactRecycling | ( | b2BodyId | 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 b2Body_EnableHitEvents | ( | b2BodyId | bodyId, |
| bool | flag ) |
Enable/disable hit events on all shapes.
| void b2Body_EnableSleeping | ( | b2BodyId | bodyId, |
| bool | enableSleep ) |
Enable or disable sleeping for this body.
If sleeping is disabled the body will wake (and the entire island).
| 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.
| bool b2Body_IsAwake | ( | b2BodyId | bodyId | ) |
| bool b2Body_IsValid | ( | b2BodyId | 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 b2Body_SetAwake | ( | b2BodyId | bodyId, |
| bool | awake ) |
Wake a body from sleep.
This wakes the entire island the body is touching.
| void b2Body_SetBullet | ( | b2BodyId | bodyId, |
| bool | flag ) |
Set this body to be a bullet.
A bullet does continuous collision detection against dynamic and kinematic bodies (but not other bullets). This only works on dynamic bodies.
| void b2Body_SetGravityScale | ( | b2BodyId | bodyId, |
| float | gravityScale ) |
Adjust the gravity scale.
Normally this is set in b2BodyDef before creation.
| 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. If motion locks are used to fix rotation then the rotational inertia value is ignored and rotational inertia remains fixed at zero.
| void b2Body_SetMotionLocks | ( | b2BodyId | bodyId, |
| b2MotionLocks | locks ) |
Set the motion locks on this body.
This causes mass properties to be recomputed because fixed rotation sets the rotational inertia to zero.
| void b2Body_SetSafetyFactor | ( | b2BodyId | bodyId, |
| float | safetyFactor ) |
Set the continuous collision safety factor.
Smaller is safer but can lead to hitching. Recommended range [0.01, 0.5]. Non-dimensional.
| void b2Body_SetTargetTransform | ( | b2BodyId | bodyId, |
| b2WorldTransform | target, | ||
| float | timeStep, | ||
| bool | wake ) |
Set the velocity to reach the given transform after a given time step.
The result will be close but may not be exact. This is meant for kinematic bodies. The target is not applied if the velocity would be below the sleep threshold and the body is currently asleep.
| bodyId | The body id |
| target | The target transform for the body |
| timeStep | The time step of the next call to b2World_Step |
| wake | Option to wake the body or not |
Set the world transform of a body.
This acts as a teleport and is fairly expensive.
| 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.
| void b2Body_UpdateMassFromShapes | ( | b2BodyId | 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 b2Body_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.
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 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.