Broadphase collision filtering not filtering some objects

SaharaCremona
Posts: 1
Joined: Fri Jul 24, 2009 11:30 pm

Broadphase collision filtering not filtering some objects

Post by SaharaCremona »

Hey guys,

I've been working on incorporating Bullet's collision detection with a separate physics simulator and I am running into trouble when trying to filter some collisions.
When two objects start far away from each other (outside of the broadphase's detection), the collision filtering works smoothly.
When two objects start near each other (within the broadphase's detection), the collision filtering doesn't work until they get out of range of detection first.

The strange part is that when collision filtering isn't working collision detection still works.
This is strange because that means the broadphase is in fact detecting a potential collision, but somehow that information isn't getting communicated to the filter?
Perhaps I am forgetting to initialize something?

Any help would be greatly appreciated.
I've been stuck on this for a while and have been searching for a solution but so far have had no luck.

Thanks in advance!

The following is the relevant code:
Please note that DBulletCollisionObject is just an extension of the btCollisionObject class.

Code: Select all

DBulletIF::DBulletIF()
{
	// Setup Collision World
	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
	btVector3	worldAabbMin(-1000,-1000,-1000);
	btVector3	worldAabbMax(1000,1000,1000);

	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);

	// Load Collision World
	_collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
        _collisionWorld->getPairCache()->setOverlapFilterCallback(this);
	_collisionWorld->performDiscreteCollisionDetection();
}

bool    DBulletIF::needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const
{
    DBulletCollisionObject* obj0 = ((DBulletCollisionObject*) proxy0->m_clientObject);
    DBulletCollisionObject* obj1 = ((DBulletCollisionObject*) proxy1->m_clientObject);

    std::cout << "needsCheck obj0: " << obj0->name() << std::endl;
    std::cout << "needsCheck obj1: " << obj1->name() << std::endl;

    bool needsCheck = obj0->shouldCheck(*obj1);
    needsCheck &= obj1->shouldCheck(*obj0);

    return needsCheck;
}

bool    DBulletCollisionObject::shouldCheck(DBulletCollisionObject& obj)
{
    bool flag = false;
    for(std::vector<DBulletCollisionObject*>::iterator it = _filteredCollisionObjects.begin(); it != _filteredCollisionObjects.end(); it++)
    {
        DBulletCollisionObject* obj1= *it;
        if(&obj == obj1)
        {
            std::cout << "checking obj: " << (&obj)->name() << std::endl;
            std::cout << "checking obj1: " << obj1->name() << std::endl;
            flag = true;
            break;
        }
    }
    std::cout << "flag (should filter): " << flag << std::endl;
    return !flag;
}