how to make 2 boxes do not collision

sssa2000
Posts: 12
Joined: Thu Oct 26, 2006 8:36 am

how to make 2 boxes do not collision

Post 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!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: how to make 2 boxes do not collision

Post 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.