我试图在我的应用程序中使用大网格创建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-&gt; CreateRigidBody()只是一个快速创建刚体的辅助函数,我知道这个函数正常工作,因为其他对象使用它并碰撞得很好。
对此问题的任何见解将不胜感激。非常感谢你的时间。
编辑: 在连接调试抽屉后,它显示的是(这是从网格下面拍摄的): 为了澄清这里是上面的镜头:
我不知道它是否是网格本身的问题,或者是通过顶点迭代创建物理网格的代码
答案 0 :(得分:0)
当迭代通过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));
}
}