Page 1 of 1

how to make 2 boxes do not collision

Posted: Mon Nov 20, 2006 9:08 am
by sssa2000
for example, there are 2 boxes in a room,
i only want to the box can collision with the room's wall,
i do not want to the collision between the boxes,
how can i do it ?
thanks!

Re: how to make 2 boxes do not collision

Posted: Fri Nov 24, 2006 1:00 pm
by Erwin Coumans
sssa2000 wrote:for example, there are 2 boxes in a room,
i only want to the box can collision with the room's wall,
i do not want to the collision between the boxes,
how can i do it ?
thanks!
There are a few ways. The easiest is to assign different collision groups, and collision filter flags to the boxes.

By default, once you add a rigidbody to the dynamics world, it gets automatically assigned collision filter flags: this prevents collision between static versus static objects. In code this is:

Code: Select all

          short collisionFilterGroup = isDynamic? btBroadphaseProxy::DefaultFilter : btBroadphaseProxy::StaticFilter;
          short collisionFilterMask = isDynamic?  btBroadphaseProxy::AllFilter :  btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter;

rigidbody->getBroadphaseProxy()->m_collisionFilterGroup = collisionFilterGroup;
rigidbody->getBroadphaseProxy()->m_collisionFilterMask = collisionFilterMask;
Remember to re-assign a new collisionFilterGroup and collisionFilterMask AFTER you added the rigidbody to the world. Otherwise the rigidbody won't have a broadphase proxy yet.

The collisionFilterMask determines (filters) the collision objects belonging to certain collisionFilterGroups to collision with. The group/mask is stored as short integer,so this gives 16 different groups of objects. Some default groups are defined:

Code: Select all

 ///optional filtering to cull potential collisions       
enum CollisionFilterGroups        
{               
 DefaultFilter = 1,               
 StaticFilter = 2,               
 KinematicFilter = 4,               
 DebrisFilter = 8,               
 AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
};

I will add some Bullet Demo that demonstrates its use.
Thanks,
Erwin

PS: If you need more fine grain control, you can override the 'needsCollision' by deriving your own version of the btCollisionDispatcher. This is tricky, so I might just add some callback that you can register for to prevent collisions between certain objects.