Right now im working on my c++ game, and im having alot of trouble using GLM and Bullet Physics to create my world correctly.
The main problem is that when i export my physics with Blenderv2.57, and export my models for GLM, the models never line up with the physics correctly...
Im wondering if there are any model loaders that would be good to use with Bullet Physics, and I can export the vertices,texture coords, etc. from Blender to be loaded and used as btTriangleMeshes..
I managed to make a btBvhTriangleMesh
with my GLM model, but I think its falling, or my character is not picking it up correctly..
heres the code:
void BulletifyContinent(GLMmodel* mesh,float x,float y,float z,float scale)
{
btTriangleMesh* trimesh = new btTriangleMesh();
for(int t=0;t<mesh->numtriangles;++t)
{
GLuint index0 =3*mesh->triangles[t].vindices[0];
GLuint index1 =3*mesh->triangles[t].vindices[1];
GLuint index2 =3*mesh->triangles[t].vindices[2];
GLfloat* p0 = &mesh->vertices[index0];
GLfloat* p1 = &mesh->vertices[index1];
GLfloat* p2 = &mesh->vertices[index2];
btVector3* v0 = new btVector3( p0[0], p0[1], p0[2] );
btVector3* v1 = new btVector3( p1[0], p1[1], p1[2] );
btVector3* v2 = new btVector3( p2[0], p2[1], p2[2] );
*v0 *= scale;
*v1 *= scale;
*v2 *= scale;
trimesh->addTriangle( *v0, *v1, *v2 );
///trimesh->addTriangle(mesh->triangles[t].vindices[0]*100,mesh->triangles[t].vindices[1]*100,mesh->triangles[t].vindices[2]*100);
}
btCollisionShape* shape = 0;
bool useQuantization = true;
shape = new btBvhTriangleMeshShape(trimesh,useQuantization);
btDefaultMotionState *StillStateMOT = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,0),btVector3(x,y,z)));
btScalar Mass = 1;
btVector3 FallInertia(0,0,0);
btRigidBody::btRigidBodyConstructionInfo StillRigidCI(Mass,StillStateMOT,shape,FallInertia);
btRigidBody *ContiRigid = new btRigidBody(StillRigidCI);
PhysicsWorld->addRigidBody(ContiRigid);
Edit 1:
btScalar Mass = 1;
btVector3 FallInertia(0,0,0);
// This line is missing in your code
shape->calculateLocalInertia(Mass, FallInertia);
btRigidBody::btRigidBodyConstructionInfo StillRigidCI(Mass,StillStateMOT,shape,FallInertia);
btRigidBody *ContiRigid = new btRigidBody(StillRigidCI);
PhysicsWorld->addRigidBody(ContiRigid);
Edit 2:
There is no need to create the bullet vertices on the heap with new:
btVector3 v0( p0[0], p0[1], p0[2] );
btVector3 v1( p1[0], p1[1], p1[2] );
btVector3 v2( p2[0], p2[1], p2[2] );
v0 *= scale;
v1 *= scale;
v2 *= scale;
trimesh->addTriangle( v0, v1, v2 );
Edit 3:
This is not a proper identity quaternion:
btDefaultMotionState(btTransform(btQuaternion(0,0,0,0),btVector3(x,y,z)));
either do it this way:
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(x,y,z));
btDefaultMotionState *StillStateMOT = new btDefaultMotionState(trans);
or by passing a proper identity quaternion either yourself:
btDefaultMotionState *StillStateMOT =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(x,y,z)));
or using quaternion's identity member function:
btDefaultMotionState *StillStateMOT =
new btDefaultMotionState(btTransform(btQuaternion::getIdentity(),btVector3(x,y,z)));
shape->calculateLocalInertia(Mass, FallInertia);
in the line afterbtVector3 FallInertia(0,0,0);
\$\endgroup\$