How to "boost" collision detection

dada
Posts: 5
Joined: Tue Jan 05, 2010 5:21 pm

How to "boost" collision detection

Post by dada »

Hi all,
I made benchmark between Bullet's collision detection library (no physics) and the verlet neighbour list method.
- Bullet takes 40 seconds of computation.
- Verlet list takes 6 seconds.
The difference is very high, maybe my code is not adapted. Is there a way to optimize computational time of bullet ?

Some informations:
- All the body are spherical, and they move very slowly.
- I based my code on the CollisionInterfaceDemo.

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

Re: How to "boost" collision detection

Post by Erwin Coumans »

Can you share the benchmark code so we can have a look how to optimized the Bullet implementation?

(zipped attachments should work)
Thanks,
Erwin
dada
Posts: 5
Joined: Tue Jan 05, 2010 5:21 pm

Re: How to "boost" collision detection

Post by dada »

Thanks for your help !

General info:
- OS: Ubuntu 9.04
- Compilation: -O3
- Link: Static

Code is very simple, at the beginning i build the collision system with:
"main.cpp", in the "main" function

Code: Select all

 
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btVector3       worldAabbMin(-200,-200,-200);
btVector3       worldAabbMax(200,200,200);
btAxisSweep3*   broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
btCollisionWorld* collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
After i build the collision object while reading a file:
"ESFichiers.cpp", in the "Readdom3d" function

Code: Select all

btCollisionObject* collisionObject = new  btCollisionObject();
btSphereShape* SphereShape = new btSphereShape(pPart->diam);
collisionObject->setCollisionShape(SphereShape);
collisionObject->getWorldTransform().setOrigin(btVector3(pPart->x,pPart->y,pPart->z));
mapP[collisionObject] = pPart;
collisionWorld->addCollisionObject(collisionObject);
End in last the event loop
"verlet.cpp", in the "Contact3D" function

Code: Select all

//Refresh position of btCollisionObject
std::map<btCollisionObject*, Particule*>::iterator it;
for ( it=mapP.begin() ; it != mapP.end(); it++ )
    {
      const Particule* pPart =  (*it).second;
      (*it).first->getWorldTransform().setOrigin(btVector3(pPart->x,pPart->y,pPart->z)); ;
     }
//Compute collision with bullet
 collisionWorld->performDiscreteCollisionDetection();
//Treat custom physics problem with the "Penetration" function
 int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
  for (int i=0;i<numManifolds;i++)
  {
    btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
    btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
    btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
    assert(mapP.count(obA)==1);
    assert(mapP.count(obB)==1);
    Penetration(mapP[obA],mapP[obB],pDom,pdeltas,pDim);
    }
I give you the code in zip files. Verlet method is implemented in the "Verlet_method.zip", and the bullet method in the "Bullet_method.zip" :)).
If you want to compile insert your path in the makefile to your bulllet sdk file, but you already know this :))
To run the prog, unzip the "entry_file.zip", put you in this folder and run the executables.
Thanks a lot !

PS: Code is dirty, it's just to test !

Damien.
You do not have the required permissions to view the files attached to this post.
dada
Posts: 5
Joined: Tue Jan 05, 2010 5:21 pm

Re: How to "boost" collision detection

Post by dada »

[Edit]
Ooooops there was a mistake in the code (ESFichiers.cpp, line 206)

Code: Select all

btSphereShape* SphereShape = new btSphereShape(pPart->diam); //bad
btSphereShape* SphereShape = new btSphereShape(pPart->diam/2.); //good
So new benchmarks gives :
- Verlet : 3.18 s
- Bullet : 7.23 s

It's better... but, Any idea to optimize bullet computation ?
Thanks,
Damien.
dada
Posts: 5
Joined: Tue Jan 05, 2010 5:21 pm

Re: How to "boost" collision detection

Post by dada »

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

Re: How to "boost" collision detection

Post by Erwin Coumans »

We are preparing to release Bullet 2.76 and will look into this in the future.

To make sure we don't forget about it, I create an issue in the issue tracker, so you can keep track of it:
http://code.google.com/p/bullet/issues/detail?id=326

Thanks,
Erwin
dada
Posts: 5
Joined: Tue Jan 05, 2010 5:21 pm

Re: How to "boost" collision detection

Post by dada »

Okay !
An article talk about this method:
http://www.google.fr/url?sa=t&source=we ... h4GCZXevxA
In fact the exact name is "Verlet-Neighbor List", i will keep aware about your progress, thanks,
Damien.