Issue with custom dispatcher

tgalluzzo
Posts: 3
Joined: Tue Mar 20, 2012 2:09 pm

Issue with custom dispatcher

Post by tgalluzzo »

I am having trouble getting my custom dispatcher to do what I expect. The dispatcher is appears to be getting called just fine when I run the performDiscreteCollisionDetection on my collision world, and based on my printouts I can tell that my custom needsCollision function is properly returning true and false as I expect. The problem is that no matter how I change the logic in the needsCollision function, I always get the same manifolds from "collisionWorld->getDispatcher()->getNumManifolds();" I would expect that if the needsCollision function returns false for everything that there would be no manifolds after running performDiscreteCollisionDetection. Is this correct?

In my application I just need collision detection, no dynamics. Any suggestions on where to get more information?

Thanks
Tom

Ps. here is some sample code of what I am doing:

Code: Select all


// What my custom dispatcher looks like:
class armsEnvDispatcher : public btCollisionDispatcher
{
public:
    armsEnvDispatcher(btCollisionConfiguration* collisionConfiguration)
        : btCollisionDispatcher(collisionConfiguration)
    {
    }

    // need special collision function
    virtual bool needsCollision(btCollisionObject* co0, btCollisionObject* co1)
    {
        if( btCollisionDispatcher::needsCollision(co0, co1) )
        {
            // recheck the broadphase again
            return _poverlapfilt != NULL ? _poverlapfilt->needBroadphaseCollision(co0->getBroadphaseHandle(), co1->getBroadphaseHandle()) : true;
        }
        return false;
    }

    btOverlapFilterCallback* _poverlapfilt;
};


// What's inside my own collision detection abstraction constructor:
    btDbvtBroadphase* broadphase = new btDbvtBroadphase();
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    armsEnvDispatcher* dispatcher = new armsEnvDispatcher(collisionConfiguration);
    collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
    btGImpactCollisionAlgorithm::registerAlgorithm((btCollisionDispatcher*)collisionWorld->getDispatcher());

    filterCallback = new ArmsEnvironmentFilterCallback();
    dispatcher->_poverlapfilt = filterCallback;
    filterCallback->objectOfInterest = NULL;
    collisionWorld->getPairCache()->setOverlapFilterCallback(filterCallback);

// What my collision check method looks like in my class:
	syncBullet();  // updates bullet collision object positions (they are already added to the collision world before this)
    collisionWorld->performDiscreteCollisionDetection();
    collisionWorld->getBroadphase()->calculateOverlappingPairs(collisionWorld->getDispatcher());

    bool collisionDetected = false;
	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	for (int i=0; i < numManifolds; i++)
	{
           // work done here

tgalluzzo
Posts: 3
Joined: Tue Mar 20, 2012 2:09 pm

Re: Issue with custom dispatcher

Post by tgalluzzo »

I found the problem. I was incorrectly assuming that the manifolds would change, rather than the contact points of the manifold. Once I changed that assumption it appears to be working well.

I do have another question though. Is it possible to re-run the broadphase filter after objects have been added to the collision world? In my case, I would like to change the logic of my filter between subsequent runs of collision checking. Therefore I need to re-run all of the pairs through broadphase filtering. What is the best way to do this? Or is there another way to achieve the same result? What would that be?

Thanks!