collision problem - broadphase pair

Post Reply
Enrico Cappelletto
Posts: 4
Joined: Mon Mar 11, 2019 3:20 pm

collision problem - broadphase pair

Post by Enrico Cappelletto »

Hi everyone,

I have a collision world that contains all the parts of a panel bending machine, there are a lot of parts (one houndred and half parts). I divided them in 14 groups and used masks to filter collisions.
I have a problem with the collisions detection. In a particolar moment i know that two objects are colliding but the collision is not detected.
I think that the problem is in the broadphase, because if i register the filter callback i see that at the beginning the pair of solids that shoud be in collision is not considered. there is no callback for the two objects. Maybe i am misunderstanding something.

I know that broadphase pairs are only added incrementally when I add a new object in the collision world and I had assumed that when I add a new object needBroadphaseCollision would be invoked n times, one for each solid already present in the world. In this way the pair cache is filled only with the pairs that are compatible with groups/masks.
Is it true? is it what shoud i expect?? What can be the problem???

Thank you in advance for any reply.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: collision problem - broadphase pair

Post by drleviathan »

The btOverlappingPairCache::needsBroadphaseCollision() implementation looks like this:

Code: Select all

        SIMD_FORCE_INLINE bool needsBroadphaseCollision(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1) const
        {
                if (m_overlapFilterCallback)
                        return m_overlapFilterCallback->needBroadphaseCollision(proxy0, proxy1);

                bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
                collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);

                return collides;
        }
There are two things to notice:
(1) If m_overlapFilterCallback has been supplied then the function defers to it.
(2) Otherwise it only returns true if both filter0&mask1 and filter1&mask0 have overlapping bits.

If you have n objects in the broadphase and add the n+1 object... it does not necessarily call that function n times. Instead it adds the bounding box to a btDbvt (dynamic bounding volume tree) of bounds "proxies" and for each fresh overlap (n or less) it calls btOverlappingPairCache::addOverlappingPair() and the PairCache will use needsBroadphaseCollision() to decide if it needs to remember that overlap or not.

If the function is not being called for an expected pair then we must conclude: either (a) the bounds proxies don't overlap at the moment when n+1 is added to the broadphase or (b) there is a bug in broadphase logic.
Enrico Cappelletto
Posts: 4
Joined: Mon Mar 11, 2019 3:20 pm

Re: collision problem - broadphase pair

Post by Enrico Cappelletto »

Thank you very much for the explanation.
I am still missing few piece in order to come full circle.

So, let's say that at the moment X when n+1 is added the bounds proxies don't overlap and that i do not add any other objects in the collisionWorld. In a successive moment Y (with Y > x) the two objects are moved and now they shoud overlap.
So when I call PerformDiscreteCollisionDetection

Code: Select all

	
	updateAabbs();

	computeOverlappingPairs();

	btDispatcher* dispatcher = getDispatcher();
	{
		BT_PROFILE("dispatchAllCollisionPairs");
		if (dispatcher)
			dispatcher->dispatchAllCollisionPairs(m_broadphasePairCache->getOverlappingPairCache(), dispatchInfo, m_dispatcher1);
	}
this clearly updates the bounding box of all the active objects in the collision world and calls computeOverlappingPairs. This computeOverlappingPairs will analyze only the pairs in the pair cache that is has been already computed?
If the answer is yes i suppose that the function needsBroadphaseCollision will be called when an object is added in the collision world and each time the bounding box is being updated but only for pairs that overlap.

So if at at instant Y, after i moved the object and called the PerformDiscreteCollisionDetection, I don't receive the expected pair in the needBroadphaseCollision it can only means that the bound proxies don't overlap. Is it right?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: collision problem - broadphase pair

Post by drleviathan »

So if at at instant Y, after i moved the object and called the PerformDiscreteCollisionDetection, I don't receive the expected pair in the needBroadphaseCollision it can only means that the bound proxies don't overlap. Is it right?
I believe that is correct. The needBroadphaseCollision would be called inside computeOverlappingPairs() and would be used to keep or discard candidate overlaps. Once the valid pairs are computed they really are cached: you can "process" them using the dispatcher method.
Post Reply