Spatial query of the world

Post Reply
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Spatial query of the world

Post by bram »

I am trying to find out what collision objects are in the neighbourhood of a location in the world.

Is there a way to do a quick query, or collision test of sphere versus world?

I need the query only on mouse clicks, so prefer not to add an object to my world permanently to do this, as it's just a one-shot thing. And I would like to have the results immediately, instead of only after stepping the world.

In OpenDE, I would just collide a Sphere with a Space, but since there is no concept of Space in Bullet, there has to be another way to do this?

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

Re: Spatial query of the world

Post by Erwin Coumans »

Fastest is broadphase->aabbTest(), but based on aabb bounding volumes of objects.

Precise is collisionWorld->contactTest(). If you use a sphere (btSphereShape), it will be similar to the OpenDE test.

The query btCollisionObject in contactTest isn't part of the world.
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Re: Spatial query of the world

Post by bram »

Thanks Erwin, not sure why I missed that.

I implemented the sphere test, and it works, but there is a problem with filtering.
I don't get all collision objects. Only the ones in group 0x1.

I use this code:

Code: Select all

        btSphereShape sph( radius );
        btCollisionObject obj;
        obj.setCollisionShape( &sph );
        obj.setCollisionFlags( btCollisionObject::CF_STATIC_OBJECT );
        btTransform trf;
        trf.setIdentity();
        btVector3 origin( pt[0], pt[1], pt[2] );
        trf.setOrigin( origin );
        obj.setWorldTransform( trf );
        TestCallback cb( cnt, walls );
        world->contactTest( &obj, cb );
The filter groups and masks seem to be a property of the btCollisionWorld, and I am not sure how to set it for the sphere object that is not in the world?
Is it always in group 0x1?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Spatial query of the world

Post by Erwin Coumans »

What type is TestCallback exactly? You should be able to override its 'needsCollision' virtual method.
PcChip
Posts: 33
Joined: Sun May 20, 2018 3:09 pm

Re: Spatial query of the world

Post by PcChip »

would this be a better method of AI Units in an RTS game detecting nearby enemies than having each unit carry around its own btPairCachingGhostObject ?
Post Reply