Best way to query if a collision happens at all

snoisius
Posts: 6
Joined: Mon Oct 01, 2012 12:44 pm

Best way to query if a collision happens at all

Post by snoisius »

Hi,

I need to query if a collision happens at all in my collision world.

I have one million sphere objects and a complex triangle mesh with given transformation - no animation, I just want to query the state.

My collision world looks like this

Code: Select all

m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_collisionDispatcher = new btCollisionDispatcher( m_collisionConfiguration );
m_collisionBPI = new btDbvtBroadphase();
m_collisionWorld = new btCollisionWorld( m_collisionDispatcher, m_collisionBPI , m_collisionConfiguration );
The problem is that calling

Code: Select all

m_collisionWorld->performDiscreteCollisionDetection();
takes extremey long if many objects collide.

That is probably because it calculates the pair cache and the contact manifolds for all the collisions. If I retransfrom the object that collides, such that there is no collision anymore, it strangely takes even longer to compute (probably because the pair cache does not get cleared).

Is there a way to query for collisions stopping at the first collision? Because I dont need all the fancy pairs and manifolds - I just need to check if a collision happens at all. Please help!

Thank you!

Patrick
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Best way to query if a collision happens at all

Post by Mako_energy02 »

Sadly Bullet is built with the intent of running an entire simulation. There are simple ways you can override classes, or add callbacks such that you get alerted when a collision occurs. However you cannot halt the check. If many of these objects are overlapping at the same time, even in just AABB's...there is no getting around the check being that slow. You are correct in that Bullet calculates the pair cache and contact manifolds for each "real" collision. You are also correct in that changing the transform of the object does not clear or alter this cache in any way, so it has to recalculate and update the necessary data.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Best way to query if a collision happens at all

Post by Erwin Coumans »

This should be improved with Bullet 3.x.

So you only need a boolean value (true/false) for each sphere, to tell if it is overlapping/colliding?
snoisius
Posts: 6
Joined: Mon Oct 01, 2012 12:44 pm

Re: Best way to query if a collision happens at all

Post by snoisius »

Erwin Coumans wrote:This should be improved with Bullet 3.x.

So you only need a boolean value (true/false) for each sphere, to tell if it is overlapping/colliding?
Actually, I only need a boolean for the whole collision world: "Is any object colliding (respecting a collision filter)?"

As I understand it, performDiscreteCollisionDetection() does:
1. Update AABBs
2. Calculate Collision Pairs
3. Dispatch Collision Pairs

After that I manually have to check the manifolds for real collisions.

Would it be possible to modify the collision pair calculation, such that it dispatches each pair right when it was found and in the dispatching method directly checks if it is a real collision? And if it found a real collision it directly terminates the collision pair calculation and returns "true".

Thanks!

Patrick