Custom Collision Filtering with Broadphase Callback (Bitmask)

Post Reply
Lewa
Posts: 5
Joined: Wed May 31, 2017 8:55 pm

Custom Collision Filtering with Broadphase Callback (Bitmask)

Post by Lewa »

Bullet is using bitmasks for collision filtering.
In the btBroadphaseProxy.h file we have the collisiongroups defined:

Code: Select all

	
	enum CollisionFilterGroups
	{
	        DefaultFilter = 1,
	        StaticFilter = 2,
	        KinematicFilter = 4,
	        DebrisFilter = 8,
			SensorTrigger = 16,
			CharacterFilter = 32,
	        AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
	};
Now, as far as i was able to read bullet is using 16 bit Bitmasks for collision filtering. (Meaning we have only 16 bits/collisiongroups available.)

My intention now is to implement custom collision filtering in order to bypass this limit in order to allow a much higher number of collisiongroups.

On the bullet wiki i was able to read that we can create a custom Broadphase filter callback for this purpose:

Code: Select all

	
	//Global Filter Callback which is used by the physicsworld in order to implement custom collision filtering
	struct PhysicsWorldFilterCallback : public btOverlapFilterCallback
	{
		// return true when pairs need collision
		virtual bool	needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const
		{
			bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
			collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);


			//<<<<<<<<<<< add some additional logic here that modified 'collides' >>>>>>>>>>
			
			
			return collides;
		}
	};
But what data can this additional logic rely on in order to do the filtering?

Both btBroadphaseProxy instances (proxy0 and proxy1) seem to provide limited information about the actual collisionobjects which are being tested. (Besides the collisiongroups and collisinfiltermask which we want to extend in the first place.)

Is it possible to somehow inject additional data into this callback which is stored in the proxy instances? (Like pointers to some object which hold additional filtering information, additional bitmasks, etc...)
Or is it easily possible to extend the bitmask from short int (16 bit) to an integer (32 bit) or long (64 bit)?

How is this custom callback intended to be used?
S1L3nCe
Posts: 50
Joined: Thu Mar 24, 2016 10:22 am
Location: France

Re: Custom Collision Filtering with Broadphase Callback (Bitmask)

Post by S1L3nCe »

Even if there are 15 max different mask&group it allows a lot of combination as you can change mask&group of a body in run time.

Otherwise:
m_clientObject in btBroadphaseProxy is what you are looking for. It's probably the userPtr of the relevant btBody. (see btBroadphaseProxy constructor)
You can stock a pointer to your object in it and figure out what it is like that during collision need check.
Post Reply