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!
how to make 2 boxes do not collision
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: how to make 2 boxes do not collision
There are a few ways. The easiest is to assign different collision groups, and collision filter flags to the boxes.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!
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;
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,
};
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.