幽灵物体 - 子弹物理学

发布于 2024-10-20 22:44:37 字数 1436 浏览 1 评论 0原文

我正在尝试在子弹物理学中实现一个简单的幽灵对象,这就是我创建幽灵对象的方法:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷清清 2024-10-27 22:44:37

据我对 GhostObject 的了解,您正在覆盖它的默认碰撞标志。尝试将此行更改

ghostObj->setCollisionFlags( btCollisionObject::CF_NO_CONTACT_RESPONSE);

为:

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

HTH

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

━╋う一瞬間旳綻放 2024-10-27 22:44:37

虽然我同意应该通过将新标志添加到现有标志集来正确设置碰撞标志,但我还想指出 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文