diff options
| author | Alexander <alex@cogarr.net> | 2019-06-26 16:14:00 -0400 |
|---|---|---|
| committer | Alexander <alex@cogarr.net> | 2019-06-26 16:14:00 -0400 |
| commit | d5cd0c7b4425e25b11a1ceec154a5c752d508a42 (patch) | |
| tree | ef50cd7d419bba30ee08f46c97232b1c8c68d2be /src/shared/lua_api/phys/bphysmodel.cpp | |
| parent | 3d60e1432ec43ade4aa61b5a70dd6b8975417e9f (diff) | |
| download | brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.tar.gz brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.tar.bz2 brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.zip | |
Major refactor of physics code
Move all the physics code into the shared directory,
and fix the ghost objects (aabb only)
Diffstat (limited to 'src/shared/lua_api/phys/bphysmodel.cpp')
| -rw-r--r-- | src/shared/lua_api/phys/bphysmodel.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index 55039ba..a89a28f 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -16,9 +16,13 @@ extern "C" { #include <shared/lua_api/common.hpp> #include <shared/util/tinyobj.hpp> +#include <shared/lua_api/phys/bcollider.hpp> +#include <shared/lua_api/phys/bphysgeneric.hpp> + extern btDiscreteDynamicsWorld* World; extern std::list<btRigidBody*> Objects; +//TODO: This will break in the future, see github.com/syoyo/tinyobjloader-c/issues/16 //"physicfile",mass[,position][,lookat] :: ud_rigidbody void makebphysmodel(lua_State *L){ printf("making bphysmodel\n"); @@ -57,25 +61,37 @@ void makebphysmodel(lua_State *L){ fclose(objfile); printf("About to tinyobj_parse_obj\n"); int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE); + printf("Finished parsing tinyobj\n"); if(err != TINYOBJ_SUCCESS){ printf("Tinyobj failed to load model:%s\n",ppath); } //u32 meshcount = pmesh->getMeshBufferCount(); + __mingw_printf("attrib.num_vertices: %u\n",attrib.num_vertices); + __mingw_printf("attrib.num_faces: %u\n",attrib.num_faces); btTriangleMesh* trimesh = new btTriangleMesh(); - for(size_t i = 0; i < attrib.num_vertices; i++){ - float *vs = attrib.vertices + (sizeof(float)*3*i);//3 floats per vertex + 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]; + //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); } - for(size_t i = 0; i < attrib.num_faces; i+= 3){ + 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 tinyobj_vertex_index_t i1,i2,i3; 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); } + 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; @@ -197,12 +213,18 @@ int bphysmodel_register(lua_State* L){ //printf("bphysmodel registered\n"); - luaL_newmetatable(L, "phys.physmodel");//{} + luaL_newmetatable(L, "phys.physmodel");//{m_physmodel} + lua_newtable(L);//{m_physmodel},{} + luaL_register(L,NULL,bcollider_m); luaL_register(L,NULL,bphysmodel_m); + luaL_register(L,NULL,brigidbody_m); + lua_setfield(L,-2,"__index");//{m_physmodel} + lua_pop(L,1);// //luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes lua_getglobal(L,"phys"); luaL_register(L,NULL,bphysmodel_f); + lua_pop(L,1); - return 1; + return 0; } |
