diff options
Diffstat (limited to 'src/shared/lua_api/phys/bphysmodel.cpp')
| -rw-r--r-- | src/shared/lua_api/phys/bphysmodel.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index 0cff0ed..2c9a02d 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -12,6 +12,8 @@ extern "C" { #include <lualib.h> } #include <btBulletDynamicsCommon.h> +#include <btBulletCollisionCommon.h> +#include <BulletCollision/Gimpact/btGImpactShape.h> #include "bphysmodel.hpp" #include <shared/lua_api/common.hpp> #include <shared/util/tinyobj.hpp> @@ -69,19 +71,22 @@ void makebphysmodel(lua_State *L){ //__mingw_printf("attrib.num_vertices: %u\n",attrib.num_vertices); //__mingw_printf("attrib.num_faces: %u\n",attrib.num_faces); btTriangleMesh* trimesh = new btTriangleMesh(); + btVector3 vertexes[attrib.num_vertices]; for(size_t i = 0; i < attrib.num_vertices; i++){ //0 - x, so num_vertices - 1 - //__mingw_printf("Looking at vertice %llu/%u\n",i,attrib.num_vertices); - //DO NOT MULTIPLY THIS BY SIEZEOF(FLOAT) float *vs = attrib.vertices + (3*i);//3 floats per vertex //printf("Got start\n"); - float v1 = vs[0]; + //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); + //trimesh->findOrAddVertex(btVector3(v1,v2,v3),true); + vertexes[i] = btVector3(v1,v2,v3); } printf("Finished finding or adding vertexes\n"); for(size_t i = 0; i < attrib.num_faces - 1; i+= 3){ //0 - y to num_faces - 1 @@ -89,7 +94,8 @@ void makebphysmodel(lua_State *L){ i1 = attrib.faces[i]; i2 = attrib.faces[i+1]; i3 = attrib.faces[i+2]; - trimesh->addTriangleIndices(i1.v_idx,i2.v_idx,i3.v_idx); + 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); } printf("Finished adding triangle indicies\n"); //size_t numverts = attrib.num_face_num_verts; @@ -120,7 +126,8 @@ void makebphysmodel(lua_State *L){ //face_offset += (size_t)attrib.face_num_verts[i]; //} printf("Done building trimesh\n"); - btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true); + //btCollisionShape *shape = new btGImpactMeshShape(trimesh); + btCollisionShape *shape = new btConvexTriangleMeshShape(trimesh); btTransform tr; tr.setIdentity(); tr.setOrigin(btVector3(x,y,z)); |
