i have a huge problem, i can render the triangleMesh, but i cannot apply physics to it!
here is the base code i use for the adding and rendering with bullet:
Code: Select all
btRigidBody *addPhysicsMesh(float mass)
{
btTriangleMesh *mesh = new btTriangleMesh();
for (int i = 0; i < m_model->faces; ++i)
{
GLuint index0 = 3 * m_model->indices[i];
GLuint index1 = 3 * m_model->indices[i + 1];
GLuint index2 = 3 * m_model->indices[i + 2];
GLfloat *pos0 = m_model->verts[index0];
GLfloat *pos1 = m_model->verts[index1];
GLfloat *pos2 = m_model->verts[index2];
btVector3 v0(pos0[0], pos0[1], pos0[2]);
btVector3 v1(pos1[0], pos1[1], pos1[2]);
btVector3 v2(pos2[0], pos2[1], pos2[2]);
mesh->addTriangle(v0, v1, v2);
}
btCollisionShape *shape = new btBvhTriangleMeshShape(mesh, true);
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(m_positionXYZ.x, m_positionXYZ.y, m_positionXYZ.z));
btDefaultMotionState *motion = new btDefaultMotionState(t);
btVector3 inertia(0.0f, 0.0f, 0.0f);
if (mass != 0.0f)
shape->calculateLocalInertia(mass, inertia);
btRigidBody::btRigidBodyConstructionInfo info(mass, motion, shape, inertia);
btRigidBody *body = new btRigidBody(info);
return body;
}
void renderPhysicsMesh(btRigidBody *mesh, ShaderProgram shader)
{
if (mesh->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE)
return;
btTransform t;
mesh->getMotionState()->getWorldTransform(t);
float mat[16];
t.getOpenGLMatrix(mat);
glPushMatrix();
glMultMatrixf(mat);
m_model->Draw(shader);
glPopMatrix();
}
I should also note that i have been setting the world's gravity so it shouldn't be that, but please let me know if the gravity has to be updated all the time, since i am unaware of this.
Thanks for making this physics system open source