LiquidFun
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
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.
 
void SetDestructionListener (b2DestructionListener *listener)
 
void SetContactFilter (b2ContactFilter *filter)
 
void SetContactListener (b2ContactListener *listener)
 
void SetDebugDraw (b2Draw *debugDraw)
 
b2BodyCreateBody (const b2BodyDef *def)
 
void DestroyBody (b2Body *body)
 
b2JointCreateJoint (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.
 
void QueryAABB (b2QueryCallback *callback, const b2AABB &aabb) const
 
void RayCast (b2RayCastCallback *callback, const b2Vec2 &point1, const b2Vec2 &point2) const
 
b2BodyGetBodyList ()
 
const b2BodyGetBodyList () const
 
b2JointGetJointList ()
 
const b2JointGetJointList () const
 
b2ContactGetContactList ()
 
const b2ContactGetContactList () const
 
void SetAllowSleeping (bool flag)
 Enable/disable sleep.
 
bool GetAllowSleeping () const
 
void SetWarmStarting (bool flag)
 Enable/disable warm starting. For testing.
 
bool GetWarmStarting () const
 
void SetContinuousPhysics (bool flag)
 Enable/disable continuous physics. For testing.
 
bool GetContinuousPhysics () const
 
void SetSubStepping (bool flag)
 Enable/disable single stepped continuous physics. For testing.
 
bool GetSubStepping () const
 
int32 GetProxyCount () const
 Get the number of broad-phase proxies.
 
int32 GetBodyCount () const
 Get the number of bodies.
 
int32 GetJointCount () const
 Get the number of joints.
 
int32 GetContactCount () const
 Get the number of contacts (each may have 0 or more contact points).
 
int32 GetTreeHeight () const
 Get the height of the dynamic tree.
 
int32 GetTreeBalance () const
 Get the balance of the dynamic tree.
 
float32 GetTreeQuality () const
 
void SetGravity (const b2Vec2 &gravity)
 Change the global gravity vector.
 
b2Vec2 GetGravity () const
 Get the global gravity vector.
 
bool IsLocked () const
 Is the world locked (in the middle of a time step).
 
void SetAutoClearForces (bool flag)
 Set flag to control automatic clearing of forces after each time step.
 
bool GetAutoClearForces () const
 Get the flag that controls automatic clearing of forces after each time step.
 
void ShiftOrigin (const b2Vec2 &newOrigin)
 
const b2ContactManagerGetContactManager () const
 Get the contact manager for testing.
 
const b2ProfileGetProfile () const
 Get the current profile.
 
void Dump ()
 
int32 CreateParticle (const b2ParticleDef &def)
 
void DestroyParticle (int32 index)
 
void DestroyParticle (int32 index, bool callDestructionListener)
 
int32 DestroyParticlesInShape (const b2Shape &shape, const b2Transform &xf)
 
int32 DestroyParticlesInShape (const b2Shape &shape, const b2Transform &xf, bool callDestructionListener)
 
b2ParticleGroupCreateParticleGroup (const b2ParticleGroupDef &def)
 
void JoinParticleGroups (b2ParticleGroup *groupA, b2ParticleGroup *groupB)
 
void DestroyParticlesInGroup (b2ParticleGroup *group, bool callDestructionListener)
 
void DestroyParticlesInGroup (b2ParticleGroup *group)
 
b2ParticleGroupGetParticleGroupList ()
 
const b2ParticleGroupGetParticleGroupList () const
 
int32 GetParticleGroupCount () const
 Get the number of particle groups.
 
int32 GetParticleCount () const
 Get the number of particles.
 
int32 GetParticleMaxCount () const
 Get the maximum number of particles.
 
void SetParticleMaxCount (int32 count)
 Set the maximum number of particles.
 
void SetParticleDensity (float32 density)
 Change the particle density.
 
float32 GetParticleDensity () const
 Get the particle density.
 
void SetParticleGravityScale (float32 gravityScale)
 
float32 GetParticleGravityScale () const
 Get the particle gravity scale.
 
void SetParticleDamping (float32 damping)
 
float32 GetParticleDamping () const
 Get damping for particles.
 
void SetParticleRadius (float32 radius)
 
float32 GetParticleRadius () const
 Get the particle radius.
 
uint32 * GetParticleFlagsBuffer ()
 
b2Vec2GetParticlePositionBuffer ()
 
b2Vec2GetParticleVelocityBuffer ()
 
b2ParticleColorGetParticleColorBuffer ()
 
b2ParticleGroup *const * GetParticleGroupBuffer ()
 
void ** GetParticleUserDataBuffer ()
 
const uint32 * GetParticleFlagsBuffer () const
 
const b2Vec2GetParticlePositionBuffer () const
 
const b2Vec2GetParticleVelocityBuffer () const
 
const b2ParticleColorGetParticleColorBuffer () const
 
const b2ParticleGroup *const * GetParticleGroupBuffer () const
 
void *const * GetParticleUserDataBuffer () const
 
void SetParticleFlagsBuffer (uint32 *buffer, int32 capacity)
 
void SetParticlePositionBuffer (b2Vec2 *buffer, int32 capacity)
 
void SetParticleVelocityBuffer (b2Vec2 *buffer, int32 capacity)
 
void SetParticleColorBuffer (b2ParticleColor *buffer, int32 capacity)
 
void SetParticleUserDataBuffer (void **buffer, int32 capacity)
 
const b2ParticleContactGetParticleContacts ()
 Get contacts between particles.
 
int32 GetParticleContactCount ()
 
const b2ParticleBodyContactGetParticleBodyContacts ()
 Get contacts between particles and bodies.
 
int32 GetParticleBodyContactCount ()
 
float32 ComputeParticleCollisionEnergy () const
 Compute the kinetic energy that can be lost by damping force.
 
const b2VersionGetVersion () const
 Get API version.
 
const char * GetVersionString () const
 Get API version string.
 

Friends

class b2Body
 
class b2Fixture
 
class b2ContactManager
 
class b2Controller
 
class b2ParticleSystem
 

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::b2World ( const b2Vec2 gravity)

Construct a world object.

Parameters
gravitythe world gravity vector.

Member Function Documentation

void b2World::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 * b2World::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 * b2World::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.
int32 b2World::CreateParticle ( const b2ParticleDef def)

Create a particle whose properties have been defined. No reference to the definition is retained. A simulation step must occur before it's possible to interact with a newly created particle. For example, DestroyParticleInShape() will not destroy a particle until Step() has been called.

Warning
This function is locked during callbacks.
Returns
the index of the particle.
b2ParticleGroup * b2World::CreateParticleGroup ( const b2ParticleGroupDef def)

Create a particle group whose properties have been defined. No reference to the definition is retained.

Warning
This function is locked during callbacks.
void b2World::DestroyBody ( b2Body body)

Destroy a rigid body. This function is locked during callbacks.

Warning
This automatically deletes all associated shapes and joints.
This function is locked during callbacks.
void b2World::DestroyJoint ( b2Joint joint)

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

Warning
This function is locked during callbacks.
void b2World::DestroyParticle ( int32  index)
inline

Destroy a particle. The particle is removed after the next step.

void b2World::DestroyParticle ( int32  index,
bool  callDestructionListener 
)

Destroy a particle. The particle is removed after the next step.

Parameters
Indexof the particle to destroy.
Whetherto call the destruction listener just before the particle is destroyed.
void b2World::DestroyParticlesInGroup ( b2ParticleGroup group,
bool  callDestructionListener 
)

Destroy particles in a group. This function is locked during callbacks.

Parameters
Theparticle group to destroy.
Whetherto call the world b2DestructionListener for each particle is destroyed.
Warning
This function is locked during callbacks.
void b2World::DestroyParticlesInGroup ( b2ParticleGroup group)
inline

Destroy particles in a group without enabling the destruction callback for destroyed particles. This function is locked during callbacks.

Parameters
Theparticle group to destroy.
Warning
This function is locked during callbacks.
int32 b2World::DestroyParticlesInShape ( const b2Shape shape,
const b2Transform xf 
)
inline

Destroy particles inside a shape without enabling the destruction callback for destroyed particles. This function is locked during callbacks. For more information see DestroyParticleInShape(const b2Shape&, const b2Transform&,bool).

Parameters
Shapewhich encloses particles that should be destroyed.
Transformapplied to the shape.
Warning
This function is locked during callbacks.
Returns
Number of particles destroyed.
int32 b2World::DestroyParticlesInShape ( const b2Shape shape,
const b2Transform xf,
bool  callDestructionListener 
)

Destroy particles inside a shape. This function is locked during callbacks. In addition, this function immediately destroys particles in the shape in constrast to DestroyParticle() which defers the destruction until the next simulation step.

Parameters
Shapewhich encloses particles that should be destroyed.
Transformapplied to the shape.
Whetherto call the world b2DestructionListener for each particle destroyed.
Warning
This function is locked during callbacks.
Returns
Number of particles destroyed.
void b2World::Dump ( )

Dump the world into the log file.

Warning
this should be called outside of a time step.
b2Body * b2World::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.
b2Contact * b2World::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.
b2Joint * b2World::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.
uint32 * b2World::GetParticleFlagsBuffer ( )

Get the particle data.

Returns
the pointer to the head of the particle data.
b2ParticleGroup * b2World::GetParticleGroupList ( )
inline

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

Returns
the head of the world particle group list.
float32 b2World::GetTreeQuality ( ) const

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

void b2World::JoinParticleGroups ( b2ParticleGroup groupA,
b2ParticleGroup groupB 
)

Join two particle groups.

Parameters
thefirst group. Expands to encompass the second group.
thesecond group. It is destroyed.
Warning
This function is locked during callbacks.
void b2World::QueryAABB ( b2QueryCallback callback,
const b2AABB aabb 
) const

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

Parameters
callbacka user implemented callback class.
aabbthe query box.
void b2World::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
callbacka user implemented callback class.
point1the ray starting point
point2the ray ending point
void b2World::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 b2World::SetContactListener ( b2ContactListener listener)

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

void b2World::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 b2World::SetDestructionListener ( b2DestructionListener listener)

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

void b2World::SetParticleDamping ( float32  damping)

Damping is used to reduce the velocity of particles. 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.

void b2World::SetParticleFlagsBuffer ( uint32 *  buffer,
int32  capacity 
)

Set a buffer for particle data.

Parameters
bufferis a pointer to a block of memory.
sizeis the number of values in the block.
void b2World::SetParticleGravityScale ( float32  gravityScale)

Change the particle gravity scale. Adjusts the effect of the global gravity vector on particles. Default value is 1.0f.

void b2World::SetParticleRadius ( float32  radius)

Change the particle radius. You should set this only once, on world start. If you change the radius during execution, existing particles may explode, shrink, or behave unexpectedly.

void b2World::ShiftOrigin ( const b2Vec2 newOrigin)

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

Parameters
newOriginthe new origin with respect to the old origin
void b2World::Step ( float32  timeStep,
int32  velocityIterations,
int32  positionIterations 
)

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

Parameters
timeStepthe amount of time to simulate, this should not vary.
velocityIterationsfor the velocity constraint solver.
positionIterationsfor the position constraint solver.

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