Non axis-aligned trigger zone using btPairCachingGhostObject

foolish_mortal
Posts: 3
Joined: Tue Aug 23, 2011 11:28 am

Non axis-aligned trigger zone using btPairCachingGhostObject

Post by foolish_mortal »

Hello

I've been trying to make a sensor/trigger zone using ghost objects. The idea is that an event is generated in the game when an object enters the trigger zone, and when it leaves it. So I created a ghost object and generate the event when rigid bodies enter or leave it.

This works fine except that the events are triggered when objects enter the AABB of the ghost object, not the actual shape. I would like to be able to detect when they enter the actual shape. I feel like there is supposed to be a way of setting it up to do this... the documentation says, tantalizingly:

"The btGhostObject can keep track of all objects that are overlapping By default, this overlap is based on the AABB"

but how do I make it not based on the AABB? I've been searching the documentation and the forums and can't find it. Someone suggested calling:

Code: Select all

dynamics_world->getDispatcher()->dispatchAllCollisionPairs(ghost_object->getOverlappingPairCache(), dynamics_world->getDispatchInfo(), dynamics_world->getDispatcher())
But it doesn't seem to have any effect.

I could manually, every frame, call contactPairTest between each rigid body in the AABB, and the collision shape of the ghost object, but I feel like I'm missing something? Is there a 'proper' way of doing it?

P.S. My trigger zone doesn't move between frames, it is always at the same position.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Non axis-aligned trigger zone using btPairCachingGhostOb

Post by Flix »

foolish_mortal wrote:This works fine except that the events are triggered when objects enter the AABB of the ghost object, not the actual shape.
What do you use for detecting the objects inside the btPairCachingGhostObjects? I ask because if you just use the method inherited by the btGhostObject class, you get only "broadphase" results.
In case this is the problem, I've made a demo some time ago that can be useful: http://bulletphysics.org/Bullet/phpBB3/ ... ilit=ghost. In the demo I used both a plain btGhostObject and a btPairCachingGhostObject and they should work as expected.
Basically you should "navigate" through the ghost object manifolds and extract the information you need (this is because you could be interested in contact point data, and not just in the array of the colliding objects).
foolish_mortal wrote:My trigger zone doesn't move between frames, it is always at the same position.
This should be a perfect "use case" for ghost objects indeed.
foolish_mortal
Posts: 3
Joined: Tue Aug 23, 2011 11:28 am

Re: Non axis-aligned trigger zone using btPairCachingGhostOb

Post by foolish_mortal »

Yes, that does the trick. Thanks! :D