Figuring out the number of colliding objects

elethiomel
Posts: 10
Joined: Wed Oct 27, 2010 11:05 pm

Figuring out the number of colliding objects

Post by elethiomel »

I'd like to know how many objects are currently colliding in my simulation. Knowing broadphase and narrowphase stats would be great too. I had thought to do it this way with callbacks. Here's the broadphase code.

Code: Select all

struct FilterCallback : 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);
		
                if(collides)
                        num_collides_broad++;
		return collides;
	}
};

btOverlapFilterCallback * filterCallback = new BroadFilterCallback();
dynamicsWorld->getPairCache()->setOverlapFilterCallback(filterCallback);

Interestingly, in a scene where a SoftBody ball hits a ground plane, the callback fires for the initial collision and bounce, but NOT for when the ball is rolling along the ground.

Is there an better/easier way to get the stats I want and why does my callback not fire with the ball rolling on the ground?

thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Figuring out the number of colliding objects

Post by Erwin Coumans »

You could iterate over all overlapping pairs and then for each pair, iterate over all contact manifold/points, check their distance.

There is a demo showing how to do this, Demos/CollisionInterfaceDemo.

The filtering is done when adding a new pair, and pairs are persistent.
Thanks,
Erwin