I'm trying to implement a simple ghost object in bulletphysics, this is how I create the ghost objects:
btGhostPairCallback* ghostCall = new btGhostPairCallback();
world->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(ghostCall);
btGhostObject* ghostObj = new btGhostObject();
btCollisionShape* shape = new btBoxShape(btVector3(ofGetWidth()+1000, ofGetHeight()+1000, 50));
ghostObj->setCollisionShape(shape);
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(0,0,-500));
ghostObj->setWorldTransform(trans);
ghostObj->setCollisionFlags( btCollisionObject::CF_NO_CONTACT_RESPONSE);
world->addCollisionObject(ghostObj,btBroadphaseProxy::SensorTrigger,btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger);
and this is how to try to find the collision:
btCollisionObject* obj = world->getCollisionObjectArray()[j];
btRigidBody* body = btRigidBody::upcast(obj);
btAlignedObjectArray < btCollisionObject* > objsInsidePairCachingGhostObject;
btAlignedObjectArray < btCollisionObject* >* pObjsInsideGhostObject = NULL;
btGhostObject* ghost = btGhostObject::upcast(obj);
if(ghost){
objsInsidePairCachingGhostObject.resize(0);
pObjsInsideGhostObject = &ghost->getOverlappingPairs();
cout << ghost->getNumOverlappingObjects() << endl;
but I always get a response that all my world objects are in collision with the ghost object.
Anyone can help me to get a functional simple ghost object?
thanks
From what little I understand of the GhostObject, you're overriding its default collision flags. Try changing this line
ghostObj->setCollisionFlags( btCollisionObject::CF_NO_CONTACT_RESPONSE);
to:
ghostObj->setCollisionFlags( ghostObj->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
HTH