Spatial query of the world

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

Spatial query of the world

Post by bram » Wed Oct 31, 2018 11:20 pm

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: 4176
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Spatial query of the world

Post by Erwin Coumans » Thu Nov 01, 2018 1:24 pm

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: 50
Joined: Sun Nov 23, 2008 4:43 pm

Re: Spatial query of the world

Post by bram » Thu Nov 01, 2018 5:24 pm

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: 4176
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Spatial query of the world

Post by Erwin Coumans » Fri Nov 02, 2018 3:33 pm

What type is TestCallback exactly? You should be able to override its 'needsCollision' virtual method.

PcChip
Posts: 27
Joined: Sun May 20, 2018 3:09 pm

Re: Spatial query of the world

Post by PcChip » Thu Nov 15, 2018 4:18 am

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