幽灵物体 - 形而上学

时间:2011-03-05 08:20:01

标签: bullet bulletphysics

我正在尝试在bulletphysics中实现一个简单的ghost对象,这就是我创建ghost对象的方式:

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);

这是尝试找到碰撞的方法:

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;

但是我总是得到一个回复​​,我所有的世界物体都与幽灵物体相撞。

任何人都可以帮助我获得一个功能简单的鬼对象吗?

感谢

2 个答案:

答案 0 :(得分:3)

从我对GhostObject的了解很少,你就会覆盖它的默认碰撞标志。尝试更改此行

ghostObj->setCollisionFlags( btCollisionObject::CF_NO_CONTACT_RESPONSE);

为:

ghostObj->setCollisionFlags( ghostObj->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);

HTH

答案 1 :(得分:1)

虽然我同意通过将新标志添加到现有标志集来正确设置冲突标志,但我也想指出btBoxShape的参数是btVector3,它定义了一半-extents 对象。这意味着宽度,高度和长度实际上是那些参数的两倍