幽灵物体 - 子弹物理学
我正在尝试在子弹物理学中实现一个简单的幽灵对象,这就是我创建幽灵对象的方法:
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;
但我总是得到一个响应,即我的所有世界对象都与幽灵发生碰撞目的。
任何人都可以帮助我获得一个功能简单的幽灵对象吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我对 GhostObject 的了解,您正在覆盖它的默认碰撞标志。尝试将此行更改
为:
HTH
From what little I understand of the GhostObject, you're overriding its default collision flags. Try changing this line
to:
HTH
虽然我同意应该通过将新标志添加到现有标志集来正确设置碰撞标志,但我还想指出 btBoxShape 的参数是定义 half-extents 对象的。这意味着宽度、高度和长度实际上是这些参数的两倍。
While I agree that the collision flags should be set properly by adding the new flag to the existing set of flags I'd also like to point out that the parameter to btBoxShape is a btVector3 that defines the half-extents of the object. That means the width, height, and length are actually twice as large as those parameters.