gpt4 book ai didi

c++ - Bullet btBvhTriangleMeshShape 不碰撞

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:11 24 4
gpt4 key购买 nike

我试图在我的应用程序中从一个大网格中创建一个 btBvhTriangleMeshShape,并将其用作刚体。这个刚体将构成静态且永不移动的“地平面”。问题是一切都直接落下,就像它根本不存在一样。这是当前的来源:

btTriangleMesh* tMesh = new btTriangleMesh();
irr::scene::IMeshBuffer* MB = WorldNode1->getMesh()->getMeshBuffer(1);

irr::video::S3DVertex* Vertices = (irr::video::S3DVertex*)MB->getVertices();
irr::u16* Indices = MB->getIndices();

for (irr::u32 i = 0; i < MB->getIndexCount(); i+=3)
{
irr::core::vector3df Tri1Pos = Vertices[Indices[i]].Pos;
irr::core::vector3df Tri2Pos = Vertices[Indices[i+1]].Pos;
irr::core::vector3df Tri3Pos = Vertices[Indices[i+2]].Pos;

tMesh->addTriangle(btVector3(Tri1Pos.X, Tri1Pos.Y, Tri1Pos.Z), btVector3(Tri2Pos.X, Tri2Pos.Y, Tri2Pos.Z), btVector3(Tri3Pos.X, Tri3Pos.Y, Tri3Pos.Z));
}

btCollisionShape* groundShape = new btBvhTriangleMeshShape(tMesh, false);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
PH->CreateRigidBody(0, groundMotionState, groundShape);

PH->CreateRigidBody() 只是一个快速创建刚体的辅助函数,我知道这个函数可以正常工作,因为其他对象使用它并且碰撞得很好。

如果您对此处的问题有任何见解,我们将不胜感激。非常感谢大家抽出时间。

编辑:连接调试抽屉后,这里显示的是什么(这是从网格下方拍摄的照片): enter image description here为了澄清,这里是上面的镜头: enter image description here

我不知道这是网格本身的问题还是遍历顶点以创建物理网格的代码

最佳答案

当遍历通过 Irrlicht 网格缓冲区提供的三角形时,我需要像这样遍历模型上存在的所有网格缓冲区:

btTriangleMesh* tMesh = new btTriangleMesh();

irr::u32 MBCount = WorldMesh1->getMeshBufferCount();

for (irr::u32 m = 0; m < MBCount; m++)
{
irr::scene::IMeshBuffer* MB = WorldNode1->getMesh()->getMeshBuffer(m);

irr::video::S3DVertex* Vertices = (irr::video::S3DVertex*)MB->getVertices();
irr::u16* Indices = MB->getIndices();

for (irr::u32 i = 0; i < MB->getIndexCount(); i += 3)
{
irr::core::vector3df Tri1Pos = Vertices[Indices[i]].Pos;
irr::core::vector3df Tri2Pos = Vertices[Indices[i + 1]].Pos;
irr::core::vector3df Tri3Pos = Vertices[Indices[i + 2]].Pos;

tMesh->addTriangle(btVector3(Tri1Pos.X, Tri1Pos.Y, Tri1Pos.Z), btVector3(Tri2Pos.X, Tri2Pos.Y, Tri2Pos.Z), btVector3(Tri3Pos.X, Tri3Pos.Y, Tri3Pos.Z));
}
}

关于c++ - Bullet btBvhTriangleMeshShape 不碰撞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24253560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com