Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
b2World Class Reference

#include <b2_world.h>

Public Member Functions

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

Private Member Functions

void DrawShape (b2Fixture *shape, const b2Transform &xf, const b2Color &color)
 
void Solve (const b2TimeStep &step)
 
void SolveTOI (const b2TimeStep &step)
 

Private Attributes

bool m_allowSleep
 
b2BlockAllocator m_blockAllocator
 
int32 m_bodyCount
 
b2Bodym_bodyList
 
bool m_clearForces
 
b2ContactManager m_contactManager
 
bool m_continuousPhysics
 
b2Drawm_debugDraw
 
b2DestructionListenerm_destructionListener
 
b2Vec2 m_gravity
 
float m_inv_dt0
 
int32 m_jointCount
 
b2Jointm_jointList
 
bool m_locked
 
bool m_newContacts
 
b2Profile m_profile
 
b2StackAllocator m_stackAllocator
 
bool m_stepComplete
 
bool m_subStepping
 
bool m_warmStarting
 

Friends

class b2Body
 
class b2ContactManager
 
class b2Controller
 
class b2Fixture
 

Detailed Description

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

Definition at line 46 of file b2_world.h.

Constructor & Destructor Documentation

◆ b2World()

b2World::b2World ( const b2Vec2 gravity)

Construct a world object.

Parameters
gravitythe world gravity vector.

Definition at line 43 of file b2_world.cpp.

◆ ~b2World()

b2World::~b2World ( )

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

Definition at line 74 of file b2_world.cpp.

Member Function Documentation

◆ ClearForces()

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

Definition at line 973 of file b2_world.cpp.

◆ CreateBody()

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.

Definition at line 115 of file b2_world.cpp.

◆ CreateJoint()

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.

Definition at line 220 of file b2_world.cpp.

◆ DebugDraw()

void b2World::DebugDraw ( )

Call this to draw shapes and other debug draw data. This is intentionally non-const.

Definition at line 1107 of file b2_world.cpp.

◆ DestroyBody()

void b2World::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.

Definition at line 139 of file b2_world.cpp.

◆ DestroyJoint()

void b2World::DestroyJoint ( b2Joint joint)

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

Warning
This function is locked during callbacks.

Definition at line 280 of file b2_world.cpp.

◆ DrawShape()

void b2World::DrawShape ( b2Fixture shape,
const b2Transform xf,
const b2Color color 
)
private

Definition at line 1039 of file b2_world.cpp.

◆ Dump()

void b2World::Dump ( )

Dump the world into the log file.

Warning
this should be called outside of a time step.

Definition at line 1260 of file b2_world.cpp.

◆ GetAllowSleeping()

bool b2World::GetAllowSleeping ( ) const
inline

Definition at line 151 of file b2_world.h.

◆ GetAutoClearForces()

bool b2World::GetAutoClearForces ( ) const
inline

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

Definition at line 330 of file b2_world.h.

◆ GetBodyCount()

int32 b2World::GetBodyCount ( ) const
inline

Get the number of bodies.

Definition at line 294 of file b2_world.h.

◆ GetBodyList() [1/2]

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 nullptr body indicates the end of the list.

Returns
the head of the world body list.

Definition at line 264 of file b2_world.h.

◆ GetBodyList() [2/2]

const b2Body * b2World::GetBodyList ( ) const
inline

Definition at line 269 of file b2_world.h.

◆ GetContactCount()

int32 b2World::GetContactCount ( ) const
inline

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

Definition at line 304 of file b2_world.h.

◆ GetContactList() [1/2]

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 nullptr 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.

Definition at line 284 of file b2_world.h.

◆ GetContactList() [2/2]

const b2Contact * b2World::GetContactList ( ) const
inline

Definition at line 289 of file b2_world.h.

◆ GetContactManager()

const b2ContactManager & b2World::GetContactManager ( ) const
inline

Get the contact manager for testing.

Definition at line 335 of file b2_world.h.

◆ GetContinuousPhysics()

bool b2World::GetContinuousPhysics ( ) const
inline

Definition at line 159 of file b2_world.h.

◆ GetGravity()

b2Vec2 b2World::GetGravity ( ) const
inline

Get the global gravity vector.

Definition at line 314 of file b2_world.h.

◆ GetJointCount()

int32 b2World::GetJointCount ( ) const
inline

Get the number of joints.

Definition at line 299 of file b2_world.h.

◆ GetJointList() [1/2]

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 nullptr joint indicates the end of the list.

Returns
the head of the world joint list.

Definition at line 274 of file b2_world.h.

◆ GetJointList() [2/2]

const b2Joint * b2World::GetJointList ( ) const
inline

Definition at line 279 of file b2_world.h.

◆ GetProfile()

const b2Profile & b2World::GetProfile ( ) const
inline

Get the current profile.

Definition at line 340 of file b2_world.h.

◆ GetProxyCount()

int32 b2World::GetProxyCount ( ) const

Get the number of broad-phase proxies.

Definition at line 1217 of file b2_world.cpp.

◆ GetSubStepping()

bool b2World::GetSubStepping ( ) const
inline

Definition at line 163 of file b2_world.h.

◆ GetTreeBalance()

int32 b2World::GetTreeBalance ( ) const

Get the balance of the dynamic tree.

Definition at line 1227 of file b2_world.cpp.

◆ GetTreeHeight()

int32 b2World::GetTreeHeight ( ) const

Get the height of the dynamic tree.

Definition at line 1222 of file b2_world.cpp.

◆ GetTreeQuality()

float b2World::GetTreeQuality ( ) const

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

Definition at line 1232 of file b2_world.cpp.

◆ GetWarmStarting()

bool b2World::GetWarmStarting ( ) const
inline

Definition at line 155 of file b2_world.h.

◆ IsLocked()

bool b2World::IsLocked ( ) const
inline

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

Definition at line 319 of file b2_world.h.

◆ QueryAABB()

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.

Definition at line 994 of file b2_world.cpp.

◆ RayCast()

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

Definition at line 1027 of file b2_world.cpp.

◆ SetAllowSleeping()

void b2World::SetAllowSleeping ( bool  flag)

Enable/disable sleep.

Definition at line 376 of file b2_world.cpp.

◆ SetAutoClearForces()

void b2World::SetAutoClearForces ( bool  flag)
inline

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

Definition at line 324 of file b2_world.h.

◆ SetContactFilter()

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.

Definition at line 100 of file b2_world.cpp.

◆ SetContactListener()

void b2World::SetContactListener ( b2ContactListener listener)

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

Definition at line 105 of file b2_world.cpp.

◆ SetContinuousPhysics()

void b2World::SetContinuousPhysics ( bool  flag)
inline

Enable/disable continuous physics. For testing.

Definition at line 158 of file b2_world.h.

◆ SetDebugDraw()

void b2World::SetDebugDraw ( b2Draw debugDraw)

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

Definition at line 110 of file b2_world.cpp.

◆ SetDestructionListener()

void b2World::SetDestructionListener ( b2DestructionListener listener)

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

Definition at line 95 of file b2_world.cpp.

◆ SetGravity()

void b2World::SetGravity ( const b2Vec2 gravity)
inline

Change the global gravity vector.

Definition at line 309 of file b2_world.h.

◆ SetSubStepping()

void b2World::SetSubStepping ( bool  flag)
inline

Enable/disable single stepped continuous physics. For testing.

Definition at line 162 of file b2_world.h.

◆ SetWarmStarting()

void b2World::SetWarmStarting ( bool  flag)
inline

Enable/disable warm starting. For testing.

Definition at line 154 of file b2_world.h.

◆ ShiftOrigin()

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

Definition at line 1237 of file b2_world.cpp.

◆ Solve()

void b2World::Solve ( const b2TimeStep step)
private

Definition at line 394 of file b2_world.cpp.

◆ SolveTOI()

void b2World::SolveTOI ( const b2TimeStep step)
private

Definition at line 585 of file b2_world.cpp.

◆ Step()

void b2World::Step ( float  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.

Definition at line 905 of file b2_world.cpp.

Friends And Related Function Documentation

◆ b2Body

friend class b2Body
friend

Definition at line 219 of file b2_world.h.

◆ b2ContactManager

friend class b2ContactManager
friend

Definition at line 221 of file b2_world.h.

◆ b2Controller

friend class b2Controller
friend

Definition at line 222 of file b2_world.h.

◆ b2Fixture

friend class b2Fixture
friend

Definition at line 220 of file b2_world.h.

Member Data Documentation

◆ m_allowSleep

bool b2World::m_allowSleep
private

Definition at line 241 of file b2_world.h.

◆ m_blockAllocator

b2BlockAllocator b2World::m_blockAllocator
private

Definition at line 229 of file b2_world.h.

◆ m_bodyCount

int32 b2World::m_bodyCount
private

Definition at line 237 of file b2_world.h.

◆ m_bodyList

b2Body* b2World::m_bodyList
private

Definition at line 234 of file b2_world.h.

◆ m_clearForces

bool b2World::m_clearForces
private

Definition at line 252 of file b2_world.h.

◆ m_contactManager

b2ContactManager b2World::m_contactManager
private

Definition at line 232 of file b2_world.h.

◆ m_continuousPhysics

bool b2World::m_continuousPhysics
private

Definition at line 256 of file b2_world.h.

◆ m_debugDraw

b2Draw* b2World::m_debugDraw
private

Definition at line 244 of file b2_world.h.

◆ m_destructionListener

b2DestructionListener* b2World::m_destructionListener
private

Definition at line 243 of file b2_world.h.

◆ m_gravity

b2Vec2 b2World::m_gravity
private

Definition at line 240 of file b2_world.h.

◆ m_inv_dt0

float b2World::m_inv_dt0
private

Definition at line 248 of file b2_world.h.

◆ m_jointCount

int32 b2World::m_jointCount
private

Definition at line 238 of file b2_world.h.

◆ m_jointList

b2Joint* b2World::m_jointList
private

Definition at line 235 of file b2_world.h.

◆ m_locked

bool b2World::m_locked
private

Definition at line 251 of file b2_world.h.

◆ m_newContacts

bool b2World::m_newContacts
private

Definition at line 250 of file b2_world.h.

◆ m_profile

b2Profile b2World::m_profile
private

Definition at line 261 of file b2_world.h.

◆ m_stackAllocator

b2StackAllocator b2World::m_stackAllocator
private

Definition at line 230 of file b2_world.h.

◆ m_stepComplete

bool b2World::m_stepComplete
private

Definition at line 259 of file b2_world.h.

◆ m_subStepping

bool b2World::m_subStepping
private

Definition at line 257 of file b2_world.h.

◆ m_warmStarting

bool b2World::m_warmStarting
private

Definition at line 255 of file b2_world.h.


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


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:22