[Solved] Detect overlap/collision between two ghost objects

gunnar
Posts: 18
Joined: Fri Jun 20, 2008 2:01 pm

[Solved] Detect overlap/collision between two ghost objects

Post by gunnar »

I have been searching high and low on Google and this forum, but have not been successful in finding an answer to a problem that I am trying to solve.

I am currently trying to implement a traffic simulator, and detect where the users vehicle is located (which side of road, inside intersection, parking lot, etc). I also need to detect collisions with other vehicles.

So currently I have one raycast vehicle that has a ghost object attached which follows the movement of the car (so that I can efficiently detect overlaps/collisions with other rigid bodies). This works very well. I also have ghost objects that I want to use as triggers, but the ghost object attached to the vehicle does not seem to be able to detect these triggers.

In other words, I want to detect overlaps between two ghost objects.

This is how I create the ghost objects (both triggers and the one following the vehicle):

Code: Select all

btConvexShape* collisionShape = ...;
  
m_ghostObject = new btPairCachingGhostObject();
m_ghostObject->setWorldTransform(startTransform);
  
m_ghostObject->setCollisionShape(collisionShape);
m_ghostObject->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);

m_ghostObject->setUserPointer(...);
  
m_dynamicsWorld->addCollisionObject(m_ghostObject, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger);
And when I get the overlapping objects of the ghost object that is attached to the vehicle object when I know it is inside on of the trigger zones, the overlap pair array size does not change:

Code: Select all

btBroadphasePairArray& pairArray = m_vehicleGhostObject->getOverlappingPairCache()->getOverlappingPairArray();
int numPairs = pairArray.size();
numPairs is the same when entering/exiting the other ghost object.

Does anybody have any pointers or advice on how to get this to work?

Thanks
Last edited by gunnar on Thu Aug 18, 2011 2:11 pm, edited 1 time in total.
gunnar
Posts: 18
Joined: Fri Jun 20, 2008 2:01 pm

Re: Detect overlap/collision between two ghost objects

Post by gunnar »

Ok, I was able to solve this using a rigid body for the trigger areas with the "CF_NO_CONTACT_RESPONSE" collision flag set. This way the ghost object attached to the vehicle can query what roadsections/trigger zones it currently is in.

Code: Select all

btTransform startTransform;

btConvexShape* collisionShape = ...;

btRigidBody::btRigidBodyConstructionInfo cInfo(0.0, new btDefaultMotionState(), collisionShape, btVector3(0.0, 0.0, 0.0));

btRigidBody* body = new btRigidBody(cInfo);
body->setWorldTransform(startTransform);
body->setContactProcessingThreshold(m_defaultContactProcessingThreshold);
body->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);

body->setUserPointer(...);

m_dynamicsWorld->addRigidBody(body);
But I never got the btGhostObject <-> btGhostObject overlap detection working.
N00001
Posts: 1
Joined: Sat Sep 03, 2011 9:23 pm

Re: [Solved] Detect overlap/collision between two ghost obje

Post by N00001 »

m_dynamicsWorld->addCollisionObject(m_ghostObject, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger);
I think you did not setup correctly the collision category and filter flags, if you use the same code for trigger and vehicle.
Bullet checks are :

Code: Select all

bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
You set m_collisionFilterMask to AllFlags minus Sensor flag. So a sensor cannot collide with another sensor. Just set mask to btBroadphaseProxy::AllFilter.