diff options
Diffstat (limited to 'src/shared/lua_api/phys/bphysmodel.cpp')
| -rw-r--r-- | src/shared/lua_api/phys/bphysmodel.cpp | 48 |
1 files changed, 10 insertions, 38 deletions
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index 2c9a02d..0515922 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -74,18 +74,12 @@ void makebphysmodel(lua_State *L){ btVector3 vertexes[attrib.num_vertices]; for(size_t i = 0; i < attrib.num_vertices; i++){ //0 - x, so num_vertices - 1 float *vs = attrib.vertices + (3*i);//3 floats per vertex - //printf("Got start\n"); //For some reason irrlicht and bullet disagree with which direction +x is, //negate the x in the physics engine so the graphical stuff lines up //with the physics stuff float v1 = -vs[0]; - //printf("Got 1\n"); float v2 = vs[1]; - //printf("Got 2\n"); float v3 = vs[2]; - //printf("Got all 3 vertexees\n"); - //printf("Adding vertex: (%f %f %f)\n",v1, v2, v3); - //trimesh->findOrAddVertex(btVector3(v1,v2,v3),true); vertexes[i] = btVector3(v1,v2,v3); } printf("Finished finding or adding vertexes\n"); @@ -94,45 +88,23 @@ void makebphysmodel(lua_State *L){ i1 = attrib.faces[i]; i2 = attrib.faces[i+1]; i3 = attrib.faces[i+2]; - trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],true); - //trimesh->addTriangleIndices(i1.v_idx,i2.v_idx,i3.v_idx); + btVector3 v1,v2,v3; + v1 = vertexes[i1.v_idx]; + v2 = vertexes[i2.v_idx]; + v3 = vertexes[i3.v_idx]; + trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],true);//Some triangles are "the wrong way round", + trimesh->addTriangle(vertexes[i3.v_idx],vertexes[i2.v_idx],vertexes[i1.v_idx],true);//double-side all triangles } printf("Finished adding triangle indicies\n"); - //size_t numverts = attrib.num_face_num_verts; - ////size_t stride = 9; //9 = 3 position floats + 3 normal floats + 3 color floats - //size_t face_offset = 0; - //for(size_t i = 0; i < numverts; i++){ - //for(size_t j = 0; j < (size_t)attrib.face_num_verts[i] / 3; j++){ - //float v[3][3]; //this tri - //tinyobj_vertex_index_t idx0, idx1, idx2; - //idx0 = attrib.faces[face_offset + 3 * j + 0]; - //idx1 = attrib.faces[face_offset + 3 * j + 1]; - //idx2 = attrib.faces[face_offset + 3 * j + 2]; - //for(short k = 0; k < 3; k++){ - //int f0, f1, f2; - //f0 = idx0.v_idx; - //f1 = idx1.v_idx; - //f2 = idx2.v_idx; - //v[0][k] = attrib.vertices[3 * (size_t)f0 + k]; - //v[1][k] = attrib.vertices[3 * (size_t)f1 + k]; - //v[2][k] = attrib.vertices[3 * (size_t)f2 + k]; - //} - //btVector3 b1,b2,b3; - //b1 = btVector3(v[0][0],v[0][1],v[0][2]); - //b2 = btVector3(v[1][0],v[1][1],v[1][2]); - //b3 = btVector3(v[2][0],v[2][1],v[2][2]); - //trimesh->addTriangle(b1,b2,b3); - //} - //face_offset += (size_t)attrib.face_num_verts[i]; - //} printf("Done building trimesh\n"); - //btCollisionShape *shape = new btGImpactMeshShape(trimesh); - btCollisionShape *shape = new btConvexTriangleMeshShape(trimesh); + btGImpactShapeInterface *shape = new btGImpactMeshShape(trimesh); + shape->updateBound(); + //btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true); btTransform tr; tr.setIdentity(); tr.setOrigin(btVector3(x,y,z)); printf("Created default motion shape\n"); - btDefaultMotionState *ms = new btDefaultMotionState(btTransform(tr)); + btDefaultMotionState *ms = new btDefaultMotionState(tr); btVector3 li; shape->calculateLocalInertia(mass, li); btRigidBody *rb = new btRigidBody(mass,ms,shape,li); |
