Ghost object collisions

ZeroPoint
Posts: 8
Joined: Sat Nov 02, 2013 6:47 pm

Ghost object collisions

Post by ZeroPoint »

Have a little technical question about how Bullet Physics sets up collision pairs with ghost objects. I want to ignore collisions for a specific object the ghost object hits. I'm using the code in the Bullet Physics tutorials.....

Code: Select all

void GhostCollisions()
{
    hitobject=false;
    hitPosition=btVector3(0,0,0);
    btManifoldArray   manifoldArray;
    btBroadphasePairArray& pairArray = ghostobject->getOverlappingPairCache()->getOverlappingPairArray();
    int numPairs = pairArray.size();

    for (int i=0;i<numPairs;i++)
    {
        manifoldArray.clear();
        const btBroadphasePair& pair = pairArray[i];

         //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
        btBroadphasePair* collisionPair = world->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
        if (!collisionPair)
            continue;

        if (collisionPair->m_algorithm)
            collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);

        for (int j=0;j<manifoldArray.size();j++)
        {
            btPersistentManifold* manifold = manifoldArray[j];
            btScalar directionSign = manifold->getBody0() == ghostobject ? btScalar(-1.0) : btScalar(1.0);
            int num=manifold->getNumContacts();
            for (int p=0;p<num;p++)
            {
             	const btManifoldPoint&pt = manifold->getContactPoint(p);
                if (pt.getDistance()<0.0f)
                {
                    //const btVector3& ptA = pt.getPositionWorldOnA();
                    //const btVector3& ptB = pt.getPositionWorldOnB();
                    //const btVector3& normalOnB = pt.m_normalWorldOnB;
                    hitobject=true;
                    hitPosition += pt.m_normalWorldOnB*    directionSign * pt.getDistance() * btScalar(1.01);

                    /// work here
                }
            }
         }
      }
}
So does the ghostobject always end up in manifold->getBody0() and the object it hits in manifold->getBody1() or does Bullet Physics get it in reversed order sometimes?