Game Development Reference
In-Depth Information
for ( int i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0; --i )
{
btCollisionObject * const obj
= m_dynamicsWorld->getCollisionObjectArray()[i];
RemoveCollisionObject( obj );
}
m_actorBodies.clear();
SAFE_DELETE(m_debugDrawer);
SAFE_DELETE(m_dynamicsWorld);
SAFE_DELETE(m_solver);
SAFE_DELETE(m_broadphase);
SAFE_DELETE(m_dispatcher);
SAFE_DELETE(m_collisionConfiguration);
}
Updating the Physics System
Inside BaseGameLogic::VOnUpdate() , you
ll call two methods of this physics
class to update the physics simulation and sync the visible scene to the results of
any movement under the control of the physics system.
'
if (m_pPhysics)
{
m_pPhysics->VOnUpdate(deltaMilliseconds);
m_pPhysics->VSyncVisibleScene();
}
Let
'
s look at the guts of these methods:
void BulletPhysics::VOnUpdate( float const deltaSeconds )
{
// Bullet uses an internal fixed timestep (default 1/60th of a second)
// We pass in 4 as a max number of sub steps. Bullet will run the
// simulation in increments of the fixed timestep until
deltaSeconds
// amount of time has passed, but will only run a maximum of 4 steps
// this way.
m_dynamicsWorld->stepSimulation( deltaSeconds, 4 );
}
'
Simple, eh? The important thing to know here is that Bullet
s stepSimulation()
function makes sure that even if your game is running slower than 60Hz, the physics
system is always ticked at a maximum time delay of 1/60th of a second. This is
important because a large time delay can create instability in the simulation. Physics
 
 
Search WWH ::




Custom Search