[SOLVED] help with bullet physics and a obj file

Started by
4 comments, last by Valeranth 15 years, 5 months ago
OK this is a repost of my bug post at 'game programming' but I've been working on this for DAYS and have made no progress in it. And I figure bullet physics, is well physics, and maybe some of you have had to do this before. Anyway, I am using GLM to load a obj file, as I do not wish to write my own loader when glm more then likely does it better then I can, and am trying to use bullet for the physics by loading in the data from the GLMmodel into a triangle mesh. The issue occures when loading in the data, the triangle indices are larger then the total of triangle vertexs, even after you factor in the numvertices*3. However despite this the glmDraw command draws the obj perfectly. So im woundering if anyone could help me debug the program, below is the relevant code, it is used to add the data to the triangle mesh. ( NOTE: the group has over 9000 triangles, the 100 is just to keep it from filling the screen )

                  for( GLuint i = 0; i < 100; i++ ){//group->numtriangles; i++ ){ 
                        printf( "tri %i\n", group->triangles );
                        triangle = mesh->triangles[(group->triangles)];

                        GLuint index0 =3*triangle.vindices[0];
                        GLuint index1 =3*triangle.vindices[1];
                        GLuint index2 =3*triangle.vindices[2];

                        GLfloat* p0 = &mesh->vertices[index0];
                        GLfloat* p1 = &mesh->vertices[index1];
                        GLfloat* p2 = &mesh->vertices[index2];

                        printf( "indeice %i, %i %i %i\n", mesh->numvertices*3, index0, index1, 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;
                        printf( "value %f %f %f\n", v0->x(), v0->y(), v0->z() );
                        trimesh->addTriangle( *v0, *v1, *v2 );
                        verts.push_back( v0 );
                        verts.push_back( v1 );
                        verts.push_back( v2 );

                }



EDIT: After some help with a friend I found the error was that the main file did not have MATERIAL_BY_FACE defined, so the values where being offset. Thanks for the help [Edited by - Valeranth on November 24, 2008 7:33:27 PM]
Advertisement
The obj file format uses indices that start at 1, and not 0, so you likely have everything offset by 1.
Quote:Original post by DrEvil
The obj file format uses indices that start at 1, and not 0, so you likely have everything offset by 1.


Sadly it is not something that easy, GLM just adds +1 to the number of indices, so indice[0] would be a 'empty' value where as indice[1] would the the first one.. etc..
You probably need to post a bit more code.

Don't new 3 vectors every iteration. You don't need to keep track of them, the trimesh stores its own copy.

I don't know much about glm, but I wouldn't think you would need to multiply the triangle.vindices by 3.
having some major issues posting the code for some reason after spending hours getting it to even let me on.. :/ ill see if I can edit this post some time...
Its not letting post the code and I can only hope it will let me post this...

I was messing around and it occured to me maybe I should make a exact copy of the drawing (glmDraw) code and play around with that intill I get the same error I have. So I copyed and pasted it into a function called test and commented out the __glmWarning calls.. THIS CODE , a exact copy, FAILS THE ASSERT's.. yet if I change it from calling wrapper->test() to just calling glmDraw, the object draws fine..

Anyone have any idea what could cause this?? I've made sure the pointers are sain.. :/

EDIT: OMG why will gamedev let me post this but not my code -__-

EDIT2: also by asserts I mean it fails at
Assertion `triangle->vindices[j]>=1 && triangle->vindices[j]<=model->numvertices' failed.

This topic is closed to new replies.

Advertisement