Game Development Reference
In-Depth Information
GCC_ASSERT( world->getWorldUserInfo() );
BulletPhysics * const bulletPhysics =
static_cast<BulletPhysics*>( world->getWorldUserInfo() );
CollisionPairs currentTickCollisionPairs;
// look at all existing contacts
btDispatcher * const dispatcher = world->getDispatcher();
for ( int manifoldIdx=0;
manifoldIdx<dispatcher->getNumManifolds(); ++manifoldIdx )
{
, or data corresponding to a contact point
// between two physics objects
btPersistentManifold const * const manifold =
dispatcher->getManifoldByIndexInternal( manifoldIdx );
GCC_ASSERT( manifold );
if (!manifold)
continue;
// get the
manifold
// Get the two bodies used in the manifold. Bullet stores them as void*,
// so we must cast them back to btRigidBody*s. Manipulating void*
// pointers is usually a bad idea, but we know this
// is safe because we only ever add btRigidBodys to the simulation
btRigidBody const * const body0 =
static_cast<btRigidBody const *>(manifold->getBody0());
btRigidBody const * const body1 =
static_cast<btRigidBody const *>(manifold->getBody1());
// always create the pair in a predictable order
const bool swapped = body0 > body1;
btRigidBody const * const sortedBodyA = swapped ? body1 : body0;
btRigidBody const * const sortedBodyB = swapped ? body0 : body1;
CollisionPair const thisPair =
std::make_pair( sortedBodyA, sortedBodyB );
currentTickCollisionPairs.insert( thisPair );
if ( bulletPhysics->m_previousTickCollisionPairs.find( thisPair ) ==
bulletPhysics->m_previousTickCollisionPairs.end() )
{
// this is a new contact, which wasn
'
t in our list before.
// send an event to the game.
bulletPhysics->SendCollisionPairAddEvent( manifold, body0, body1 );
}
}
Search WWH ::




Custom Search