Disabling collision between two bodies

David20321
Posts: 17
Joined: Sat Mar 13, 2010 10:08 pm

Disabling collision between two bodies

Post by David20321 »

When using constraints it's possible to disable collisions using the second parameter of btDynamicsWorld::addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies). But what if I want to disable collisions between two objects without any constraint? Right now I think I can do this using the btGeneric6DofConstraint, but that seems inefficient. Is there any other way to disable collisions between two specific bodies?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Disabling collision between two bodies

Post by Flix »

David20321 wrote:But what if I want to disable collisions between two objects without any constraint?
http://bulletphysics.org/mediawiki-1.5. ... _Filtering
Hope this link helps.

P.S.
David20321 wrote:Right now I think I can do this using the btGeneric6DofConstraint

Adding a "fake" btGeneric6DofConstraint (with all 6 dof free) just to avoid collisions between the two bodies seems to me a bit too extreme :|
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Disabling collision between two bodies

Post by Erwin Coumans »

Indeed. As flix mentions, a fully free btGeneric6DofConstraint would work but is a bit expensive.

Could you try a custom nearcallback or a custom dispatcher?
http://bulletphysics.org/mediawiki-1.5. ... _Filtering

We could create a simpler solution (similar to constraints but without the memory/cpu cost) if needed. Just file a feature request, if above solutions are not desired.
Thanks,
Erwin
David20321
Posts: 17
Joined: Sat Mar 13, 2010 10:08 pm

Re: Disabling collision between two bodies

Post by David20321 »

For now I'm just using a point2point constraint with a near-zero m_impulseClamp value -- I figured that would be less expensive than the btGeneric6DofConstraint. So far it seems to be working ok, but I'll file a feature request if it turns out to be too expensive and the other solutions are not sufficient. Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Disabling collision between two bodies

Post by Erwin Coumans »

It is not a good idea to use the btPoint2PointConstraint, it is a slow option. It will merge islands (just like using the btGeneric6DofConstraint ) but also take constraint solver processing.

Faster is to use a btGeneric6DofConstraint with all limits/degrees of freedom (DOF) free. At least it won't involve CPU cycles during constraint solving.

Even better derive the 'needsCollision' and/or 'needsResponse' in your custom dispatcher.
Thanks,
Erwin
jbacon
Posts: 11
Joined: Wed May 13, 2009 12:30 pm

Re: Disabling collision between two bodies

Post by jbacon »

I'm having the same issue, and tend to use the 'free' generic6dof constraint solution,
but this seems overkill - so does re-implementing the collision dispatcher, since I don't
know on bullet-API level which collisions to exclude, I only know this when using my
own classes that use btRigidBody in a has-a fashion.

how do I file a feature-request properly ?

Thanks,

Jochem
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Disabling collision between two bodies

Post by Flix »

jbacon wrote:so does re-implementing the collision dispatcher, since I don't
know on bullet-API level which collisions to exclude, I only know this when using my
own classes that use btRigidBody in a has-a fashion.
Well, I don't use a "has it" approach, but isn't the (single) user pointer inside the btRigidBody class enough for your task?

I mean: it can be used to pass from a btRigidBody to the class that owns it...
(you can use a common base class for all your custom classes that owns a btRigidBody, so you can still use multiple custom classes if you want).
User avatar
ejtttje
Posts: 96
Joined: Mon Nov 03, 2008 9:57 pm

Re: Disabling collision between two bodies

Post by ejtttje »

Oh hey, somehow I'd missed addContraint's second parameter is supposed to disable collision testing between linked objects?
So if I pass 'true' everywhere I don't need to do this filter...? (because the checkCollideWithOverride() will be done internally for me?)

Code: Select all

struct CollisionFilter : public btOverlapFilterCallback {
	// return true when pairs need collision
	virtual bool	needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const {
		if( (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask)==0 || (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask)==0)
			return false;
		
		btRigidBody* rb0 = btRigidBody::upcast(static_cast<btCollisionObject*>(proxy0->m_clientObject));
		if(rb0==NULL)
			return true;
		return rb0->checkCollideWithOverride(static_cast<btCollisionObject*>(proxy1->m_clientObject));
	}
};
User avatar
ejtttje
Posts: 96
Joined: Mon Nov 03, 2008 9:57 pm

Re: Disabling collision between two bodies

Post by ejtttje »

However, I'll point out that, for better or worse, if you call contactTest() with a rigid body with such constraints, it'll still call addSingleResult() on the callback with the constrained objects. It seems one will need to override needsCollision() in the ContactResultCallback to call checkCollideWithOverride() in order to avoid having addSingleResult() called with such linked objects...
Toadcop
Posts: 11
Joined: Mon Feb 22, 2010 10:13 pm

Re: Disabling collision between two bodies

Post by Toadcop »

ok i have similar problem...
i want to be able control the "tunneling" between specific objects (so they just ignore each other) in specific conditions. broadphase isn't enough for this, so i derivered the dispatcher class and made my own needCollision/needResponse etc. "it works" but for some reason i just can't prevent objects to stuck in each other (if collision occurs) i setted everywhere FALSE so to prevent collision and response but it seems not to work. so the question is:

how can i make objects ignore each other in narrowphase (so they behave like nothing is there, but take account of it)

also if i set broadphase collision filter flags it works properly (but i don't receive callbacks in narrowphase (obviously) and can't filter objects how i need)