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
b2World Class Reference

`#include <b2World.h>`

## Public Member Functions
| b2World (const b2Vec2 &gravity)
| ~b2World ()
| Destruct the world. All physics entities are destroyed and all heap memory is released. More...
void | SetDestructionListener (b2DestructionListener *listener)
void | SetContactFilter (b2ContactFilter *filter)
void | SetContactListener (b2ContactListener *listener)
void | SetDebugDraw (b2Draw *debugDraw)
b2Body * | CreateBody (const b2BodyDef *def)
void | DestroyBody (b2Body *body)
b2Joint * | CreateJoint (const b2JointDef *def)
void | DestroyJoint (b2Joint *joint)
void | Step (float32 timeStep, int32 velocityIterations, int32 positionIterations)
void | ClearForces ()
void | DrawDebugData ()
| Call this to draw shapes and other debug draw data. More...
void | QueryAABB (b2QueryCallback *callback, const b2AABB &aabb) const
void | RayCast (b2RayCastCallback *callback, const b2Vec2 &point1, const b2Vec2 &point2) const
b2Body * | GetBodyList ()
const b2Body * | GetBodyList () const
b2Joint * | GetJointList ()
const b2Joint * | GetJointList () const
b2Contact * | GetContactList ()
const b2Contact * | GetContactList () const
void | SetAllowSleeping (bool flag)
| Enable/disable sleep. More...
bool | GetAllowSleeping () const
void | SetWarmStarting (bool flag)
| Enable/disable warm starting. For testing. More...
bool | GetWarmStarting () const
void | SetContinuousPhysics (bool flag)
| Enable/disable continuous physics. For testing. More...
bool | GetContinuousPhysics () const
void | SetSubStepping (bool flag)
| Enable/disable single stepped continuous physics. For testing. More...
bool | GetSubStepping () const
int32 | GetProxyCount () const
| Get the number of broad-phase proxies. More...
int32 | GetBodyCount () const
| Get the number of bodies. More...
int32 | GetJointCount () const
| Get the number of joints. More...
int32 | GetContactCount () const
| Get the number of contacts (each may have 0 or more contact points). More...
int32 | GetTreeHeight () const
| Get the height of the dynamic tree. More...
int32 | GetTreeBalance () const
| Get the balance of the dynamic tree. More...
float32 | GetTreeQuality () const
void | SetGravity (const b2Vec2 &gravity)
| Change the global gravity vector. More...
b2Vec2 | GetGravity () const
| Get the global gravity vector. More...
bool | IsLocked () const
| Is the world locked (in the middle of a time step). More...
void | SetAutoClearForces (bool flag)
| Set flag to control automatic clearing of forces after each time step. More...
bool | GetAutoClearForces () const
| Get the flag that controls automatic clearing of forces after each time step. More...
void | ShiftOrigin (const b2Vec2 &newOrigin)
const b2ContactManager & | GetContactManager () const
| Get the contact manager for testing. More...
const b2Profile & | GetProfile () const
| Get the current profile. More...
void | Dump ()

## Friends
class | b2Body
class | b2Fixture
class | b2ContactManager
class | b2Controller

## Detailed Description

The world class manages all physics entities, dynamic simulation, and asynchronous queries. The world also contains efficient memory management facilities.

## Constructor & Destructor Documentation

b2World | ( | const b2Vec2 & | gravity | ) |

Construct a world object.

Parameters

  gravity | the world gravity vector.

~b2World | ( |  | ) |

Destruct the world. All physics entities are destroyed and all heap memory is released.

## Member Function Documentation

void ClearForces | ( |  | ) |

Manually clear the force buffer on all bodies. By default, forces are cleared automatically after each call to Step. The default behavior is modified by calling SetAutoClearForces. The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain a fixed sized time step under a variable frame-rate. When you perform sub-stepping you will disable auto clearing of forces and instead call ClearForces after all sub-steps are complete in one pass of your game loop.

See also
  SetAutoClearForces

b2Body * CreateBody | ( | const b2BodyDef * | def | ) |

Create a rigid body given a definition. No reference to the definition is retained.

Warning
  This function is locked during callbacks.

b2Joint * CreateJoint | ( | const b2JointDef * | def | ) |

Create a joint to constrain bodies together. No reference to the definition is retained. This may cause the connected bodies to cease colliding.

Warning
  This function is locked during callbacks.

void DestroyBody | ( | b2Body * | body | ) |

Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during callbacks.

Warning
  This automatically deletes all associated shapes and joints.
  This function is locked during callbacks.

void DestroyJoint | ( | b2Joint * | joint | ) |

Destroy a joint. This may cause the connected bodies to begin colliding.

Warning
  This function is locked during callbacks.

void DrawDebugData | ( |  | ) |

Call this to draw shapes and other debug draw data.

void Dump | ( |  | ) |

Dump the world into the log file.

Warning
  this should be called outside of a time step.

bool GetAllowSleeping | ( |  | ) | const
| inline

bool GetAutoClearForces | ( |  | ) | const
| inline

Get the flag that controls automatic clearing of forces after each time step.

int32 GetBodyCount | ( |  | ) | const
| inline

Get the number of bodies.

b2Body * GetBodyList | ( |  | ) |
| inline

Get the world body list. With the returned body, use b2Body::GetNext to get the next body in the world list. A NULL body indicates the end of the list.

Returns
  the head of the world body list.

const b2Body * GetBodyList | ( |  | ) | const
| inline

int32 GetContactCount | ( |  | ) | const
| inline

Get the number of contacts (each may have 0 or more contact points).

b2Contact * GetContactList | ( |  | ) |
| inline

Get the world contact list. With the returned contact, use b2Contact::GetNext to get the next contact in the world list. A NULL contact indicates the end of the list.

Returns
  the head of the world contact list.

Warning
  contacts are created and destroyed in the middle of a time step. Use b2ContactListener to avoid missing contacts.

const b2Contact * GetContactList | ( |  | ) | const
| inline

const b2ContactManager & GetContactManager | ( |  | ) | const
| inline

Get the contact manager for testing.

bool GetContinuousPhysics | ( |  | ) | const
| inline

b2Vec2 GetGravity | ( |  | ) | const
| inline

Get the global gravity vector.

int32 GetJointCount | ( |  | ) | const
| inline

Get the number of joints.

b2Joint * GetJointList | ( |  | ) |
| inline

Get the world joint list. With the returned joint, use b2Joint::GetNext to get the next joint in the world list. A NULL joint indicates the end of the list.

Returns
  the head of the world joint list.

const b2Joint * GetJointList | ( |  | ) | const
| inline

const b2Profile & GetProfile | ( |  | ) | const
| inline

Get the current profile.

int32 GetProxyCount | ( |  | ) | const

Get the number of broad-phase proxies.

bool GetSubStepping | ( |  | ) | const
| inline

int32 GetTreeBalance | ( |  | ) | const

Get the balance of the dynamic tree.

int32 GetTreeHeight | ( |  | ) | const

Get the height of the dynamic tree.

float32 GetTreeQuality | ( |  | ) | const

Get the quality metric of the dynamic tree. The smaller the better. The minimum is 1.

bool GetWarmStarting | ( |  | ) | const
| inline

bool IsLocked | ( |  | ) | const
| inline

Is the world locked (in the middle of a time step).

void QueryAABB | ( | b2QueryCallback * | callback,
|  | const b2AABB & | aabb
| ) |  | const

Query the world for all fixtures that potentially overlap the provided AABB.

Parameters

  callback | a user implemented callback class.
  aabb | the query box.

void RayCast | ( | b2RayCastCallback * | callback,
|  | const b2Vec2 & | point1,
|  | const b2Vec2 & | point2
| ) |  | const

Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point.

Parameters

  callback | a user implemented callback class.
  point1 | the ray starting point
  point2 | the ray ending point

void SetAllowSleeping | ( | bool | flag | ) |

Enable/disable sleep.

void SetAutoClearForces | ( | bool | flag | ) |
| inline

Set flag to control automatic clearing of forces after each time step.

void SetContactFilter | ( | b2ContactFilter * | filter | ) |

Register a contact filter to provide specific control over collision. Otherwise the default filter is used (b2_defaultFilter). The listener is owned by you and must remain in scope.

void SetContactListener | ( | b2ContactListener * | listener | ) |

Register a contact event listener. The listener is owned by you and must remain in scope.

void SetContinuousPhysics | ( | bool | flag | ) |
| inline

Enable/disable continuous physics. For testing.

void SetDebugDraw | ( | b2Draw * | debugDraw | ) |

Register a routine for debug drawing. The debug draw functions are called inside with b2World::DrawDebugData method. The debug draw object is owned by you and must remain in scope.

void SetDestructionListener | ( | b2DestructionListener * | listener | ) |

Register a destruction listener. The listener is owned by you and must remain in scope.

void SetGravity | ( | const b2Vec2 & | gravity | ) |
| inline

Change the global gravity vector.

void SetSubStepping | ( | bool | flag | ) |
| inline

Enable/disable single stepped continuous physics. For testing.

void SetWarmStarting | ( | bool | flag | ) |
| inline

Enable/disable warm starting. For testing.

void ShiftOrigin | ( | const b2Vec2 & | newOrigin | ) |

Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin

Parameters

  newOrigin | the new origin with respect to the old origin

void Step | ( | float32 | timeStep,
|  | int32 | velocityIterations,
|  | int32 | positionIterations
| ) |  |

Take a time step. This performs collision detection, integration, and constraint solution.

Parameters

  timeStep | the amount of time to simulate, this should not vary.
  velocityIterations | for the velocity constraint solver.
  positionIterations | for the position constraint solver.

## Friends And Related Function Documentation

friend class b2Body
| friend

friend class b2ContactManager
| friend

friend class b2Controller
| friend

friend class b2Fixture
| friend

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

- Box2D/Dynamics/b2World.h
- Box2D/Dynamics/b2World.cpp