I might have just missunderstood something when it comes to btBvhTriangleMeshShape but I tried to create a rigid body
with a btBvhTriangleMeshShape as collision shape. But when I try to calculate the inertia with calculateLocalInertia I get a runtime error.
This is the constructor of the Object class I created. When I call this the error occurs in calculateLocalInertia.
Code: Select all
myClass::myClass(VECTOR_3F* vertices, VECTOR_3F* faces, int numOfVertices, int numOfFaces, btScalar mass, VECTOR_3F position)
{
this->m_forces = true;
this->m_vetrices = vertices;
this->m_faces = faces;
this->m_inertia = btVector3(0, 0, 0);
this->m_mesh = new btTriangleMesh;
btVector3 v1(0, 0, 0);
btVector3 v2(0, 0, 0);
btVector3 v3(0, 0, 0);
for(int i = 0; i < numOfFaces; i++)
{
v1 = btVector3(vertices[(int)faces[i].x-1].x, vertices[(int)faces[i].x-1].y, vertices[(int)faces[i].x-1].z);
v2 = btVector3(vertices[(int)faces[i].y-1].x, vertices[(int)faces[i].y-1].y, vertices[(int)faces[i].y-1].z);
v3 = btVector3(vertices[(int)faces[i].z-1].x, vertices[(int)faces[i].z-1].y, vertices[(int)faces[i].z-1].z);
this->m_mesh->addTriangle(v1, v2, v3);
}
btCollisionShape* shape = new btBvhTriangleMeshShape(this->m_mesh, true, true);
this->setCollisionshape(shape);
btVector3 pos;
pos.setX(position.x);
pos.setY(position.y);
pos.setZ(position.z);
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),pos));
this->setMotionState(motionState);
this->calculateInertia();
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass,motionState,shape,this->getInertia());
btRigidBody* rigidBody = new btRigidBody(rigidBodyCI);
rigidBody->setActivationState(DISABLE_DEACTIVATION);
this->setRigidBody(rigidBody);
}
void myClass::calculateInertia()
{
btVector3 inertia(0,0,0);
if(this->getCollisionShape() == NULL)
return;
this->getCollisionShape()->calculateLocalInertia(this->getMass(),inertia);
this->m_inertia = inertia;
}
Do the triangles have to be added in a spezific order? Or did I do another mistake?
I hope some has any idea why I get this error.
Thank you for your help!