needsCollision of derived btCollisionDispatcher not called

User avatar
Tomator
Posts: 9
Joined: Mon Oct 18, 2010 8:53 am

needsCollision of derived btCollisionDispatcher not called

Post by Tomator »

Hi

I have a physical object that can contain other physical objects inside and then it shouldn't collide with (only) those objects. So I derived a btCollisionDispatcher's descendant to filter those collisions. It worked fine in the project... But doesn't do now. Here it looks like:

Code: Select all

	theBulletCollisionConfiguration = new btDefaultCollisionConfiguration();
	theBulletCollisionDispatcher = new DerivedCollisionDispatcher(theBulletCollisionConfiguration);
	btGImpactCollisionAlgorithm::registerAlgorithm(theBulletCollisionDispatcher);
	btVector3 worldMin(-1000, -1000, -1000);
	btVector3 worldMax(1000, 1000, 1000);
	theBulletBroadphase = new btAxisSweep3(worldMin, worldMax);
	theBulletConstraintSolver = new btSequentialImpulseConstraintSolver();
        theBulletWorld = new btDiscreteDynamicsWorld(theBulletCollisionDispatcher,
                                               theBulletBroadphase, 
                                               theBulletConstraintSolver,
                                               theBulletCollisionConfiguration); 
The dispatcher is derived as folows:

Code: Select all

class DerivedCollisionDispatcher : public btCollisionDispatcher
  {
public:
  typedef btCollisionDispatcher BaseClass;

  DerivedCollisionDispatcher(btCollisionConfiguration* aCollisionConfiguration)
    :
    BaseClass(aCollisionConfiguration)
    {};

  virtual bool needsCollision(btCollisionObject* aBody0,  btCollisionObject* aBody1);

protected:
  virtual bool canCollideWith(btCollisionObject* aBody0, btCollisionObject* aBody1);
  };
When the program runs, a breakpoint set in the DerivedCollisionDispatcher::needsCollision(aBody0, aBody1) is never hit (that's why I don't give its code) and collisions aren't disabled. I think the bullet could be changed in the project from 2.76 to 2.8x but I am not sure for that. Anyway, I don't know why it stopped working? Could anybody give a clue?
User avatar
Tomator
Posts: 9
Joined: Mon Oct 18, 2010 8:53 am

Re: needsCollision of derived btCollisionDispatcher not call

Post by Tomator »

Solution

btCollisionDispatcher's needsCollision() definition was changed:

from (2.77):

Code: Select all

bool	btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionObject* body1)
to (2.81):

Code: Select all

bool	btCollisionDispatcher::needsCollision(const btCollisionObject* body0, cost btCollisionObject* body1)
Then, my method in the descendant class that was overriding the btCollisionDispatcher's one became after this change a new one. When I added 'const' to parameter definitions, it it working again. I should thank myself ;)

As the online documentation contains new declaration already, wiki page devoted to collision filtering still does not.
dern23
Posts: 26
Joined: Thu Oct 04, 2012 1:58 pm

Re: needsCollision of derived btCollisionDispatcher not call

Post by dern23 »

I had a similar issue once before with an API change breaking derived code. I mentioned it to Erwin some time ago and since then he usually acknowledges this in his commit comments as a warning when updating. See r2642 for a recent example.