Using Bullet to query a Static World.

Jim
Posts: 3
Joined: Wed Aug 22, 2007 8:24 am

Using Bullet to query a Static World.

Post by Jim »

Hello,

My name is James Park, I've been taking a look at Bullet for the last two days in relation to performing queries on a static world. We use Opcode currently and would like to switch to something that is more actively maintained. However, I've run into some problems. I have done the following:
  • Create a btCollisionWorld.
    Add a btBvhTriangleMeshShape to represent the static world.
This seems to work fine. Next I wrote three collision functions:
  • One that performs a sphere query (given centre and radius is there a collision with world geometry?)
    A simple raycast.
    A raycast that returns a normal and hit point.
This implementation works. I know this because the data I calculate using these queries is exactly as it should be. However, its very slow (more than twice as slow as Opcode). I think the problem is in the sphere collision. For the raycasts I just call btCollisionWorld::rayTest() so they couldn't be any more trivial. In the sphere collision function I do the following:
  • Make a btCollisionObject and assign a btSphereShape of the given radius (this sphere is used for every test as the radius never changes).
    Call btCollisionWorld::performDiscreteCollisionDetection().
    Check for collision pretty much exactly as is done in the CollisionInterfaceDemo.
You might be asking why I call performDiscreteCollisionDetection() in every sphere test. This is because if I don't do this every test fails. Basically we perform many of these tests every frame. The sphere's position will change for each test. When I just called this function in the update of the application the sphere test never worked.

I guess my question boils down to - what is the most optimal way I can do a sphere collision test on a world mesh (optimal in the sense of speed, I don't care at all about memory).

Thanks.
Last edited by Jim on Tue Feb 03, 2009 11:22 am, edited 1 time in total.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

We should be able to make this faster then OPCODE. What you need is a single object query against the world, isn't it?

- How many objects are in the btCollisionWorld when you call 'performDiscreteCollisionDetection'?
- are you using quantized btBvhTriangleMeshShape?
Some code snippet for initialization might help.

The basic pipeline when you call 'performDiscreteCollisionDetection' is:

- broadphase, based on axis aligned bounding boxes
- for each pair, do narrowphase.

The narrowphase for sphere versus btBvhTriangleMeshShape will do:

- find overlapping triangles, using an AABB tree (similar but I think more optimal then OPCODE)
- use GJK to find contact points. If this is the bottleneck, there is ways to speed it up, but registering a dedicated sphere-triangle collision algorithm to the dispatcher.

Do you have some timings for each stage?
Thanks,
Erwin