Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Friends | List of all members
b2Body Class Reference

A rigid body. These are created via b2World::CreateBody. More...

`#include <b2Body.h>`

## Public Member Functions
b2Fixture * | CreateFixture (const b2FixtureDef *def)
b2Fixture * | CreateFixture (const b2Shape *shape, float32 density)
void | DestroyFixture (b2Fixture *fixture)
void | SetTransform (const b2Vec2 &position, float32 angle)
const b2Transform & | GetTransform () const
const b2Vec2 & | GetPosition () const
float32 | GetAngle () const
const b2Vec2 & | GetWorldCenter () const
| Get the world position of the center of mass. More...
const b2Vec2 & | GetLocalCenter () const
| Get the local position of the center of mass. More...
void | SetLinearVelocity (const b2Vec2 &v)
const b2Vec2 & | GetLinearVelocity () const
void | SetAngularVelocity (float32 omega)
float32 | GetAngularVelocity () const
void | ApplyForce (const b2Vec2 &force, const b2Vec2 &point, bool wake)
void | ApplyForceToCenter (const b2Vec2 &force, bool wake)
void | ApplyTorque (float32 torque, bool wake)
void | ApplyLinearImpulse (const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
void | ApplyAngularImpulse (float32 impulse, bool wake)
float32 | GetMass () const
float32 | GetInertia () const
void | GetMassData (b2MassData *data) const
void | SetMassData (const b2MassData *data)
void | ResetMassData ()
b2Vec2 | GetWorldPoint (const b2Vec2 &localPoint) const
b2Vec2 | GetWorldVector (const b2Vec2 &localVector) const
b2Vec2 | GetLocalPoint (const b2Vec2 &worldPoint) const
b2Vec2 | GetLocalVector (const b2Vec2 &worldVector) const
b2Vec2 | GetLinearVelocityFromWorldPoint (const b2Vec2 &worldPoint) const
b2Vec2 | GetLinearVelocityFromLocalPoint (const b2Vec2 &localPoint) const
float32 | GetLinearDamping () const
| Get the linear damping of the body. More...
void | SetLinearDamping (float32 linearDamping)
| Set the linear damping of the body. More...
float32 | GetAngularDamping () const
| Get the angular damping of the body. More...
void | SetAngularDamping (float32 angularDamping)
| Set the angular damping of the body. More...
float32 | GetGravityScale () const
| Get the gravity scale of the body. More...
void | SetGravityScale (float32 scale)
| Set the gravity scale of the body. More...
void | SetType (b2BodyType type)
| Set the type of this body. This may alter the mass and velocity. More...
b2BodyType | GetType () const
| Get the type of this body. More...
void | SetBullet (bool flag)
| Should this body be treated like a bullet for continuous collision detection? More...
bool | IsBullet () const
| Is this body treated like a bullet for continuous collision detection? More...
void | SetSleepingAllowed (bool flag)
bool | IsSleepingAllowed () const
| Is this body allowed to sleep. More...
void | SetAwake (bool flag)
bool | IsAwake () const
void | SetActive (bool flag)
bool | IsActive () const
| Get the active state of the body. More...
void | SetFixedRotation (bool flag)
bool | IsFixedRotation () const
| Does this body have fixed rotation? More...
b2Fixture * | GetFixtureList ()
| Get the list of all fixtures attached to this body. More...
const b2Fixture * | GetFixtureList () const
b2JointEdge * | GetJointList ()
| Get the list of all joints attached to this body. More...
const b2JointEdge * | GetJointList () const
b2ContactEdge * | GetContactList ()
const b2ContactEdge * | GetContactList () const
b2Body * | GetNext ()
| Get the next body in the world's body list. More...
const b2Body * | GetNext () const
void * | GetUserData () const
| Get the user data pointer that was provided in the body definition. More...
void | SetUserData (void *data)
| Set the user data. Use this to store your application specific data. More...
b2World * | GetWorld ()
| Get the parent world of this body. More...
const b2World * | GetWorld () const
void | Dump ()
| Dump this body to a log file. More...

## Friends
class | b2World
class | b2Island
class | b2ContactManager
class | b2ContactSolver
class | b2Contact
class | b2DistanceJoint
class | b2FrictionJoint
class | b2GearJoint
class | b2MotorJoint
class | b2MouseJoint
class | b2PrismaticJoint
class | b2PulleyJoint
class | b2RevoluteJoint
class | b2RopeJoint
class | b2WeldJoint
class | b2WheelJoint

## Detailed Description

A rigid body. These are created via b2World::CreateBody.

## Member Function Documentation

void ApplyAngularImpulse | ( | float32 | impulse,
|  | bool | wake
| ) |  |
| inline

Apply an angular impulse.

Parameters

  impulse | the angular impulse in units of kg*m*m/s
  wake | also wake up the body

void ApplyForce | ( | const b2Vec2 & | force,
|  | const b2Vec2 & | point,
|  | bool | wake
| ) |  |
| inline

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 wakes up the body.

Parameters

  force | the world force vector, usually in Newtons (N).
  point | the world position of the point of application.
  wake | also wake up the body

void ApplyForceToCenter | ( | const b2Vec2 & | force,
|  | bool | wake
| ) |  |
| inline

Apply a force to the center of mass. This wakes up the body.

Parameters

  force | the world force vector, usually in Newtons (N).
  wake | also wake up the body

void ApplyLinearImpulse | ( | const b2Vec2 & | impulse,
|  | const b2Vec2 & | point,
|  | bool | wake
| ) |  |
| inline

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 wakes up the body.

Parameters

  impulse | the world impulse vector, usually in N-seconds or kg-m/s.
  point | the world position of the point of application.
  wake | also wake up the body

void ApplyTorque | ( | float32 | torque,
|  | bool | wake
| ) |  |
| inline

Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

Parameters

  torque | about the z-axis (out of the screen), usually in N-m.
  wake | also wake up the body

b2Fixture * CreateFixture | ( | const b2FixtureDef * | def | ) |

Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.

Parameters

  def | the fixture definition.

Warning
  This function is locked during callbacks.

b2Fixture * CreateFixture | ( | const b2Shape * | shape,
|  | float32 | density
| ) |  |

Creates a fixture from a shape and attach it to this body. This is a convenience function. Use b2FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.

Parameters

  shape | the shape to be cloned.
  density | the shape density (set to zero for static bodies).

Warning
  This function is locked during callbacks.

void DestroyFixture | ( | b2Fixture * | fixture | ) |

Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.

Parameters

  fixture | the fixture to be removed.

Warning
  This function is locked during callbacks.

void Dump | ( |  | ) |

Dump this body to a log file.

float32 GetAngle | ( |  | ) | const
| inline

Get the angle in radians.

Returns
  the current world rotation angle in radians.

float32 GetAngularDamping | ( |  | ) | const
| inline

Get the angular damping of the body.

float32 GetAngularVelocity | ( |  | ) | const
| inline

Get the angular velocity.

Returns
  the angular velocity in radians/second.

b2ContactEdge * GetContactList | ( |  | ) |
| inline

Get the list of all contacts attached to this body.

Warning
  this list changes during the time step and you may miss some collisions if you don't use b2ContactListener.

const b2ContactEdge * GetContactList | ( |  | ) | const
| inline

b2Fixture * GetFixtureList | ( |  | ) |
| inline

Get the list of all fixtures attached to this body.

const b2Fixture * GetFixtureList | ( |  | ) | const
| inline

float32 GetGravityScale | ( |  | ) | const
| inline

Get the gravity scale of the body.

float32 GetInertia | ( |  | ) | const
| inline

Get the rotational inertia of the body about the local origin.

Returns
  the rotational inertia, usually in kg-m^2.

b2JointEdge * GetJointList | ( |  | ) |
| inline

Get the list of all joints attached to this body.

const b2JointEdge * GetJointList | ( |  | ) | const
| inline

float32 GetLinearDamping | ( |  | ) | const
| inline

Get the linear damping of the body.

const b2Vec2 & GetLinearVelocity | ( |  | ) | const
| inline

Get the linear velocity of the center of mass.

Returns
  the linear velocity of the center of mass.

b2Vec2 GetLinearVelocityFromLocalPoint | ( | const b2Vec2 & | localPoint | ) | const
| inline

Get the world velocity of a local point.

Parameters

  a | point in local coordinates.

Returns
  the world velocity of a point.

b2Vec2 GetLinearVelocityFromWorldPoint | ( | const b2Vec2 & | worldPoint | ) | const
| inline

Get the world linear velocity of a world point attached to this body.

Parameters

  a | point in world coordinates.

Returns
  the world velocity of a point.

const b2Vec2 & GetLocalCenter | ( |  | ) | const
| inline

Get the local position of the center of mass.

b2Vec2 GetLocalPoint | ( | const b2Vec2 & | worldPoint | ) | const
| inline

Gets a local point relative to the body's origin given a world point.

Parameters

  a | point in world coordinates.

Returns
  the corresponding local point relative to the body's origin.

b2Vec2 GetLocalVector | ( | const b2Vec2 & | worldVector | ) | const
| inline

Gets a local vector given a world vector.

Parameters

  a | vector in world coordinates.

Returns
  the corresponding local vector.

float32 GetMass | ( |  | ) | const
| inline

Get the total mass of the body.

Returns
  the mass, usually in kilograms (kg).

void GetMassData | ( | b2MassData * | data | ) | const
| inline

Get the mass data of the body.

Returns
  a struct containing the mass, inertia and center of the body.

b2Body * GetNext | ( |  | ) |
| inline

Get the next body in the world's body list.

const b2Body * GetNext | ( |  | ) | const
| inline

const b2Vec2 & GetPosition | ( |  | ) | const
| inline

Get the world body origin position.

Returns
  the world position of the body's origin.

const b2Transform & GetTransform | ( |  | ) | const
| inline

Get the body transform for the body's origin.

Returns
  the world transform of the body's origin.

b2BodyType GetType | ( |  | ) | const
| inline

Get the type of this body.

void * GetUserData | ( |  | ) | const
| inline

Get the user data pointer that was provided in the body definition.

b2World * GetWorld | ( |  | ) |
| inline

Get the parent world of this body.

const b2World * GetWorld | ( |  | ) | const
| inline

const b2Vec2 & GetWorldCenter | ( |  | ) | const
| inline

Get the world position of the center of mass.

b2Vec2 GetWorldPoint | ( | const b2Vec2 & | localPoint | ) | const
| inline

Get the world coordinates of a point given the local coordinates.

Parameters

  localPoint | a point on the body measured relative the the body's origin.

Returns
  the same point expressed in world coordinates.

b2Vec2 GetWorldVector | ( | const b2Vec2 & | localVector | ) | const
| inline

Get the world coordinates of a vector given the local coordinates.

Parameters

  localVector | a vector fixed in the body.

Returns
  the same vector expressed in world coordinates.

bool IsActive | ( |  | ) | const
| inline

Get the active state of the body.

bool IsAwake | ( |  | ) | const
| inline

Get the sleeping state of this body.

Returns
  true if the body is sleeping.

bool IsBullet | ( |  | ) | const
| inline

Is this body treated like a bullet for continuous collision detection?

bool IsFixedRotation | ( |  | ) | const
| inline

Does this body have fixed rotation?

bool IsSleepingAllowed | ( |  | ) | const
| inline

Is this body allowed to sleep.

void ResetMassData | ( |  | ) |

This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass.

void SetActive | ( | bool | flag | ) |

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list.

void SetAngularDamping | ( | float32 | angularDamping | ) |
| inline

Set the angular damping of the body.

void SetAngularVelocity | ( | float32 | omega | ) |
| inline

Set the angular velocity.

Parameters

  omega | the new angular velocity in radians/second.

void SetAwake | ( | bool | flag | ) |
| inline

Set the sleep state of the body. A sleeping body has very low CPU cost.

Parameters

  flag | set to true to wake the body, false to put it to sleep.

void SetBullet | ( | bool | flag | ) |
| inline

Should this body be treated like a bullet for continuous collision detection?

void SetFixedRotation | ( | bool | flag | ) |

Set this body to have fixed rotation. This causes the mass to be reset.

void SetGravityScale | ( | float32 | scale | ) |
| inline

Set the gravity scale of the body.

void SetLinearDamping | ( | float32 | linearDamping | ) |
| inline

Set the linear damping of the body.

void SetLinearVelocity | ( | const b2Vec2 & | v | ) |
| inline

Set the linear velocity of the center of mass.

Parameters

  v | the new linear velocity of the center of mass.

void SetMassData | ( | const b2MassData * | data | ) |

Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.

Parameters

  massData | the mass properties.

void SetSleepingAllowed | ( | bool | flag | ) |
| inline

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

void SetTransform | ( | const b2Vec2 & | position,
|  | float32 | angle
| ) |  |

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior.

Parameters

  position | the world position of the body's local origin.
  angle | the world rotation in radians.

void SetType | ( | b2BodyType | type | ) |

Set the type of this body. This may alter the mass and velocity.

void SetUserData | ( | void * | data | ) |
| inline

Set the user data. Use this to store your application specific data.

## Friends And Related Function Documentation

friend class b2Contact
| friend

friend class b2ContactManager
| friend

friend class b2ContactSolver
| friend

friend class b2DistanceJoint
| friend

friend class b2FrictionJoint
| friend

friend class b2GearJoint
| friend

friend class b2Island
| friend

friend class b2MotorJoint
| friend

friend class b2MouseJoint
| friend

friend class b2PrismaticJoint
| friend

friend class b2PulleyJoint
| friend

friend class b2RevoluteJoint
| friend

friend class b2RopeJoint
| friend

friend class b2WeldJoint
| friend

friend class b2WheelJoint
| friend

friend class b2World
| friend

The documentation for this class was generated from the following files:

- Box2D/Dynamics/b2Body.h
- Box2D/Dynamics/b2Body.cpp