query a region for objects

knea
Posts: 1
Joined: Tue Dec 13, 2011 7:36 pm

query a region for objects

Post by knea »

Is it possible to query a specific region for objects, that currently are in that region? The region could be defined as a box or sphere shape.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: query a region for objects

Post by Mako_energy02 »

You can do this using a ghost object as a sensor trigger in your simulation. It's easier if you just need the overlapping objects by AABB, as you can then use the broadphase pair cache on the ghost object itself. Otherwise you'll have to iterate over the contact manifolds to see which objects overlap with the ghost object.

There are posts throughout this forum that go over the details of how to do all that.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: query a region for objects

Post by Flix »

I believe there's another option too (although I've never tested it so far, as far as I remember): btCollisionWorld::contactTest:

Code: Select all

///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback.
   ///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
   void   btCollisionWorld::contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback);

   ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
   ///it reports one or more contact points (including the one with deepest penetration)
   void   btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback);
It should be possible to create the btCollisionObject on the stack easily with just a btCollisionShape and a world transform (it doesn't need to be added to the world).
P.S. I thought there was some kind of aabbTest method too, but I can't find it right now in the btCollisionWorld class... (maybe there's something about it in the btDbvhBroadphase class).