Page 1 of 1
Spatial query of the world
Posted: Wed Oct 31, 2018 11:20 pm
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!
Re: Spatial query of the world
Posted: Thu Nov 01, 2018 1:24 pm
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.
Re: Spatial query of the world
Posted: Thu Nov 01, 2018 5:24 pm
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?
Re: Spatial query of the world
Posted: Fri Nov 02, 2018 3:33 pm
by Erwin Coumans
What type is TestCallback exactly? You should be able to override its 'needsCollision' virtual method.
Re: Spatial query of the world
Posted: Thu Nov 15, 2018 4:18 am
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 ?