5

Is there a way to set a Broadphase Filter Callback in Bullet Physics as follow:

Compound dynamic bodies built from two shapes, say a cylinder and a box, where cylinders can only collide with cylinders inside other dynamic bodies, and boxes can only collide with a third kind of body, wich is a static sphere

No other collisions are allowed: cylinders with spheres, must NOT collide; boxes with boxes, must NOT collide either

The following image shows what I've described above

collision-filter

rraallvv
  • 2,875
  • 6
  • 30
  • 67

1 Answers1

3

You can do that. Here is code

struct FilterCallback : public btOverlapFilterCallback 
{ 
    virtual bool  needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const; 
}; 
// ....
FilterCallback filterCallback;
// ....
m_dynamicsWorld->getPairCache()->setOverlapFilterCallback(filterCallback);

bool  FilterCallback::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const 
{ 
// return false for pair with no colision
}
Max
  • 6,286
  • 5
  • 44
  • 86
  • do you know if I can retrieve the userData pointer in a shape inside a compound body, like this: btCollisionObject* collisionObject = (btCollisionObject*) proxy0->m_clientObject; customData* userData = (customData*) collisionObject->getUserPointer(); – rraallvv Oct 24 '12 at 18:08
  • hmm... yes that retrieve the userData from the whole thing, I need the userData from the child that is actually colliding... so I can tell whether that shape can collide or not... maybe there is no function in the API to do that – rraallvv Oct 24 '12 at 19:14
  • I think that is a limitation of the Broadphase itself – rraallvv Oct 24 '12 at 19:29
  • You can have 2 bodies and make them to not collide and keep them together by applying forces every frame. – Max Oct 24 '12 at 19:38
  • Yes, or I can use some constraint instead, thought that would be a soft joint, not like the joints that hold together a compound shape... I'll try both ways and see how it goes – rraallvv Oct 24 '12 at 22:20
  • funny I have not thought about joints. I copied code from car simulation. it was filtering wheels in car http://pastie.org/5111723 – Max Oct 24 '12 at 22:36
  • I've modified your code to use in my callback, http://pastebin.com/8MLM6fYn, can you update your answer so I can accept it, please – rraallvv Oct 24 '12 at 23:51
  • You can add a userPointer to a shape and retrieve it from your compound shape. myChildShape->setUserPointer() ..... myChildShape->getUserPointer() – Benoît Lahoz Sep 02 '13 at 19:29