Using btTriangleMesh for Obj files?

molma100
Posts: 11
Joined: Sat Apr 09, 2011 8:12 pm

Using btTriangleMesh for Obj files?

Post by molma100 »

hey im using bullet with GLM(the model loading library by nate robins) to load up my models.


should i be using btTriangleMesh to match a collision object with my model?


if so then how would i go on about doing this?

-Molma

EDIT: I attempted some code just now, but as of now, the game crashes instantly. :(

this is the code that i came up with, while looking at other peoples codes:

Code: Select all

btRigidBody *GroundBodyCreate()
{
    btTriangleMesh *WorldTriMesh = new btTriangleMesh();
    for(int v=0;v<ModelList[0]->numvertices;v+3)
    {
        btVector3 v0(ModelList[0]->vertices[v,0],ModelList[0]->vertices[v,1],ModelList[0]->vertices[v,2]);
        btVector3 v1(ModelList[0]->vertices[v+1,0],ModelList[0]->vertices[v+1,1],ModelList[0]->vertices[v+1,2]);
        btVector3 v2(ModelList[0]->vertices[v+2,0],ModelList[0]->vertices[v+2,1],ModelList[0]->vertices[v+2,2]);
        WorldTriMesh->addTriangle(v0,v1,v2);
    }
    btCollisionShape *WorldColShape = new btBvhTriangleMeshShape(WorldTriMesh,false);
    btDefaultMotionState *defMOTstate = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
    btRigidBody::btRigidBodyConstructionInfo GroundBodyCI(0,defMOTstate,WorldColShape,btVector3(0,0,0));
    btRigidBody *GroundBody = new btRigidBody(GroundBodyCI);
    return GroundBody;
}
also im using Wavefront .OBJ files in my GLM loader