diff options
| author | Alexander <alex@cogarr.net> | 2019-04-24 21:16:08 -0400 |
|---|---|---|
| committer | Alexander <alex@cogarr.net> | 2019-04-24 21:16:08 -0400 |
| commit | 3d60e1432ec43ade4aa61b5a70dd6b8975417e9f (patch) | |
| tree | 954719a0f4a27fe42f9d8113844a21b79ae70f5d /src/client/lua_api | |
| parent | 42bedce123739287339a95626675ffda3a1ce8e7 (diff) | |
| download | brokengine-3d60e1432ec43ade4aa61b5a70dd6b8975417e9f.tar.gz brokengine-3d60e1432ec43ade4aa61b5a70dd6b8975417e9f.tar.bz2 brokengine-3d60e1432ec43ade4aa61b5a70dd6b8975417e9f.zip | |
updates
Diffstat (limited to 'src/client/lua_api')
| -rw-r--r-- | src/client/lua_api/gui/iguielement.cpp | 23 | ||||
| -rw-r--r-- | src/client/lua_api/load_cphys.cpp | 7 | ||||
| -rw-r--r-- | src/client/lua_api/load_video.cpp | 8 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbcharactercontroller.cpp | 120 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbcharactercontroller.hpp | 10 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbphysbox.cpp | 18 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbphysmodel.cpp | 226 | ||||
| -rw-r--r-- | src/client/lua_api/scene/icamera.cpp | 51 | ||||
| -rw-r--r-- | src/client/lua_api/scene/imesh.cpp | 7 |
9 files changed, 399 insertions, 71 deletions
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index af9d234..9254ba0 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -215,6 +215,27 @@ int focus(lua_State *L){ return 0; } +//{guielement},bool +int setelementenabled(lua_State *L){ + int enable = lua_toboolean(L,-1); + lua_pop(L,1); + lua_getfield(L,-1,"guielement"); + IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1); + ele->setEnabled(enable == 1); + lua_pop(L,1); + return 0; +} + +//{guielement} +int getelementenabled(lua_State *L){ + lua_getfield(L,-1,"guielement"); + IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1); + bool enabled = ele->isEnabled(); + lua_pushboolean(L,enabled?1:0); + lua_pop(L,1); + return 1; +} + class guicallback{ private: @@ -257,6 +278,7 @@ int guigetid(lua_State* L){ return 1; } + extern const luaL_reg iguielement_m[] = { {"move", moveiguielement}, {"setvisible", setvisible}, @@ -268,5 +290,6 @@ extern const luaL_reg iguielement_m[] = { {"gettext", getiguitext}, {"remove", removeiguielement}, {"focus", focus}, + {"enable", setelementenabled}, {NULL, NULL} }; diff --git a/src/client/lua_api/load_cphys.cpp b/src/client/lua_api/load_cphys.cpp index ed81408..92eaff0 100644 --- a/src/client/lua_api/load_cphys.cpp +++ b/src/client/lua_api/load_cphys.cpp @@ -11,10 +11,13 @@ extern "C" { #include "../callbackhandeler.hpp" #include "phys/cbphysbox.hpp" #include "phys/cbphysmodel.hpp" +#include "phys/cbcharactercontroller.hpp" #include <btBulletDynamicsCommon.h> #include <btBulletCollisionCommon.h> //#include <shared/phys/physcommon.hpp> #include <shared/lua_api/common.hpp> +#include <shared/lua_api/load_phys.hpp> +#include <shared/lua_api/phys/bghostobject.hpp> using namespace irr; using namespace gui; @@ -41,10 +44,12 @@ int raytest(lua_State *L){ } void load_cphysfuncs(lua_State* L){ + //phys things cbphysbox_register(L); - + cbcharactercontroller_register(L); cbphysmodel_register(L); + bghostobject_register(L); lua_getglobal(L,"phys");//{} lua_pushcfunction(L,raytest);//{},raytest() diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp index 1266c4d..e0c7557 100644 --- a/src/client/lua_api/load_video.cpp +++ b/src/client/lua_api/load_video.cpp @@ -23,9 +23,9 @@ extern IVideoDriver* driver; //{texture},{x,y},{sourcerect},{color},use_alpha int draw2dimage(lua_State* L){ int nargs = lua_gettop(L); - printf("Drawing a 2d image\n"); + //printf("Drawing a 2d image\n"); if(nargs == 2){ - printf("2-argument version\n"); + //printf("2-argument version\n"); long x,y; popvector2i(L,&x,&y); lua_getfield(L,-1,"texture"); @@ -33,10 +33,10 @@ int draw2dimage(lua_State* L){ lua_pop(L,2); driver->draw2DImage(tex,position2d<s32>(x,y)); }else if(nargs == 5){ - printf("5-argument version\n"); + //printf("5-argument version\n"); int usealpha = lua_toboolean(L,-1); lua_pop(L,1); - printf("Got usealpha: %d\n",usealpha); + //printf("Got usealpha: %d\n",usealpha); long r,g,b,a; popvector4i(L,&r,&g,&b,&a); long ssx,ssy,sex,sey; diff --git a/src/client/lua_api/phys/cbcharactercontroller.cpp b/src/client/lua_api/phys/cbcharactercontroller.cpp new file mode 100644 index 0000000..6a6da96 --- /dev/null +++ b/src/client/lua_api/phys/cbcharactercontroller.cpp @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <stdlib.h> +#include <list> +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +#include <btBulletDynamicsCommon.h> +#include <BulletDynamics/Character/btKinematicCharacterController.h> +#include <irrlicht.h> +#include "cbphysbox.hpp" +#include "../scene/imesh.hpp" +#include "../scene/igeneric.hpp" +#include <shared/lua_api/phys/bcharactercontroller.hpp> +#include <shared/lua_api/common.hpp> + +#include <shared/lua_api/phys/bphysgeneric.hpp> + +using namespace irr; +using namespace scene; +using namespace core; +using namespace video; + +extern IrrlichtDevice* device; + +extern btDiscreteDynamicsWorld* World; +extern std::list<btRigidBody*> Objects; + + +//phys.newcharactercontroller({vector3 size},{vector3 origin}) +static int newcbcharactercontroller(lua_State* L){// + printf("Createing new cbcharactercontroller\n"); + double sx,sy,sz,x,y,z; + //Get the data + popvector3d(L,&x,&y,&z);//{v3 size} + popvector3d(L,&sx,&sy,&sz);// + + pushvector3d(L,sx,sy,sz);//{v3 size} + pushvector3d(L,x,y,z);//{v3 size},{v3 origin} + makenewbcharactercontroller(L);//ud_cc + btKinematicCharacterController* cc = (btKinematicCharacterController*)lua_touserdata(L,-1);//ud_cc + lua_pop(L,1); + + pushvector3d(L,sx,sy,sz);//{v3 size} + pushvector3d(L,x,y,z);//{v3 size},{v3 origin} + makenewiscenecube(L);//ud_iscenenode + ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode + lua_pop(L,1); + + //cc->setUserPointer(n);//TODO: what does this break? + + lua_newtable(L);//{} + lua_pushlightuserdata(L,cc);//{},ud_cc + lua_setfield(L,-2,"character");//{} + lua_pushlightuserdata(L,n);//{},ud_iscenenode + lua_setfield(L,-2,"node");//{} + + luaL_getmetatable(L,"phys.charactercontroller");//{},{phys.charactercontroller} + lua_setmetatable(L,-2);//{} + + return 1; +} + +//setMaterial(self,material) +//int cbsetmaterial(lua_State* L){ + //printf("Call to setmaterial\n"); + ////SMaterial* mat = (SMaterial*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_IMaterial + //ITexture* tex = (ITexture*)lua_touserdata(L,-1); + //lua_pop(L,1);//{node=ud_ISceneNode} + //printf("About to get field node\n"); + //lua_getfield(L,-1,"node");//{node=ud_ISceneNode},ud_ISceneNode + //printf("After call to field node\n"); + //ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode},ud_ISceneNode + //lua_pop(L,2);// + + //lua_pushlightuserdata(L,i); + //lua_pushlightuserdata(L,tex); + //printf("Finished getting everything for setmaterial\n"); + //iscenesetmaterial(L); + + //return 0; +//} + +//int cbchar + +static const luaL_reg cbcharactercontroller_m[] = { + //{"setpos", cbcharsetpos},//overload + //{"getpos", cbchargetpos}, + //{"getgravity", cbphysgetgravity}, + //{"applygravity",cbphysapplygravity}, + //{"setMaterial", cbsetmaterial}, +// {"delete", delbphysbox},//client side delete needs to delete the visual representation + {0, 0}, +}; + +void cbcharactercontroller_register(lua_State* L){ + bcharactercontroller_register(L);// + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newcbcharactercontroller);//{},newcbphysbox() + lua_setfield(L,-2,"newccharactercontroller");//{} + + lua_pop(L,1);// + + luaL_getmetatable(L,"phys.charactercontroller");//phys.physbox + lua_newtable(L);//phys.physbox,{} + luaL_register(L,NULL,brigidbody_m); + luaL_register(L,NULL,igeneric_m); + luaL_register(L,NULL,cbcharactercontroller_m);//phys.physbox,{} + lua_setfield(L,-2,"__index");//phys.physbox + + lua_pop(L,1); + + //printf("When registering physbox, new() is %p\n",newcbphysbox); + //printf("setpos is %p\n",cbphyssetpos); + + lua_pop(L,1); + +} diff --git a/src/client/lua_api/phys/cbcharactercontroller.hpp b/src/client/lua_api/phys/cbcharactercontroller.hpp new file mode 100644 index 0000000..d7b76eb --- /dev/null +++ b/src/client/lua_api/phys/cbcharactercontroller.hpp @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> + +void cbcharactercontroller_register(lua_State* L); diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp index 86deacf..c5aacd8 100644 --- a/src/client/lua_api/phys/cbphysbox.cpp +++ b/src/client/lua_api/phys/cbphysbox.cpp @@ -13,6 +13,7 @@ extern "C" { #include "cbphysbox.hpp" #include "../scene/imesh.hpp" #include <shared/lua_api/phys/bphysbox.hpp> +#include <shared/lua_api/phys/bcollider.hpp> #include "../scene/igeneric.hpp" #include <shared/lua_api/common.hpp> @@ -56,7 +57,7 @@ static int newcbphysbox(lua_State* L){// lua_newtable(L);//{} lua_pushlightuserdata(L,r);//{},ud_rigidbody - lua_setfield(L,-2,"rigidbody");//{} + lua_setfield(L,-2,"collider");//{} lua_pushlightuserdata(L,n);//{},ud_iscenenode lua_setfield(L,-2,"node");//{} @@ -73,7 +74,7 @@ int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{ popvector3d(L,&x,&y,&z);//{rigidbody=ud_btRigidbody,node=ud_iscenenode} //printf("Getting rigidbody\n"); - lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody + lua_getfield(L,-1,"collider");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody //printf("Got rigidbody, it was %p\n",r); lua_pop(L,1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode} @@ -99,7 +100,7 @@ int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{ //bphysbox:getpos() int cbphysgetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode} //printf("cphysgetpos called, stack size is %d\n",lua_gettop(L)); - lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody + lua_getfield(L,-1,"collider");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1); lua_pop(L,2); btTransform bt = r->getCenterOfMassTransform(); @@ -109,7 +110,7 @@ int cbphysgetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode} } int cbphysgetgravity(lua_State* L){ - lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody + lua_getfield(L,-1,"collider");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1); lua_pop(L,2); btVector3 p = r->getGravity(); @@ -118,7 +119,7 @@ int cbphysgetgravity(lua_State* L){ } int cbphysapplygravity(lua_State* L){ - lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody + lua_getfield(L,-1,"collider");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1); lua_pop(L,2); r->applyGravity(); @@ -148,10 +149,6 @@ int cbsetmaterial(lua_State* L){ static const luaL_reg cbphysbox_m[] = { {"setpos", cbphyssetpos},//overload {"getpos", cbphysgetpos}, - //{"getgravity", cbphysgetgravity}, - //{"applygravity",cbphysapplygravity}, - //{"setMaterial", cbsetmaterial}, -// {"delete", delbphysbox},//client side delete needs to delete the visual representation {0, 0}, }; @@ -165,9 +162,12 @@ void cbphysbox_register(lua_State* L){ luaL_getmetatable(L,"phys.physbox");//phys.physbox lua_newtable(L);//phys.physbox,{} + luaL_register(L,NULL,bcollider_m); luaL_register(L,NULL,brigidbody_m); luaL_register(L,NULL,igeneric_m); luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{} + lua_pushstring(L,"rigidbody"); + lua_setfield(L,-2,"type"); lua_setfield(L,-2,"__index");//phys.physbox lua_pop(L,1); diff --git a/src/client/lua_api/phys/cbphysmodel.cpp b/src/client/lua_api/phys/cbphysmodel.cpp index 51ff2d8..4f4c106 100644 --- a/src/client/lua_api/phys/cbphysmodel.cpp +++ b/src/client/lua_api/phys/cbphysmodel.cpp @@ -17,7 +17,10 @@ extern "C" { #include "cbphysbox.hpp" #include "cbphysmodel.hpp" #include <client/lua_api/scene/igeneric.hpp> +#include <shared/lua_api/phys/bphysmodel.hpp> +#include <shared/lua_api/phys/bcollider.hpp> #include <shared/lua_api/common.hpp> +#include <shared/util/tinyobj.hpp> using namespace irr; @@ -32,81 +35,209 @@ extern std::list<btRigidBody*> Objects; //newbphysmodel("graphicfile","physicfile",mass,[,{position}][,{lookat}]) static int newbphysmodel(lua_State* L){ - printf("Creating bphysmodel\n"); + printf("Creating cbphysmodel\n"); int nargs = lua_gettop(L); double lx,ly,lz; double x,y,z; if(nargs > 4){ //"graphicsfile","physicsfile",{position},{lookat} popvector3d(L,&lx,&ly,&lz); + }else{ + lx = 1; ly = 1; lz = 1; } + if(nargs > 3){ //"graphicsfile","physicsfile",{position} popvector3d(L,&x,&y,&z); + }else{ + x = 0; y = 0; z = 0; } - //"graphicsfile","physicsfile" + //"graphicsfile","physicsfile",mass double mass = lua_tonumber(L,-1); const char *ppath = lua_tostring(L,-2); const char *gpath = lua_tostring(L,-3); - lua_pop(L,3); + lua_pop(L,3);// ISceneManager *smgr = device->getSceneManager(); printf("bphysnode, creating the scene node\n"); //Create the scene node - IMesh *gmesh = smgr->getMesh(gpath); + //IMeshBuffer *buf = new CDynamicMeshBuffer(E_VERTEX_TYPE::EVT_STANDARD,E_INDEX_TYPE::EIT_16BIT); + IMeshBuffer *buf = new SMeshBuffer(); + tinyobj_attrib_t attrib; + printf("At the very beginning, attrib is %p\n",(void*)&attrib); + tinyobj_shape_t *shapes = NULL; + size_t meshcount; + tinyobj_material_t *materials = NULL; + size_t num_materials; + + //Read data from the graphics file + size_t data_len = 0; + FILE *objfile = fopen(gpath,"rb"); + fseek(objfile,0,SEEK_END); + data_len = ftell(objfile); + printf("model data is %d long\n",(int)data_len); + fseek(objfile,0,SEEK_SET); + char *objdata = (char*)malloc(sizeof(char)*data_len); + fread(objdata, sizeof(char), data_len, objfile); + fclose(objfile); + + //Parse the data into a tinyobj + printf("About to tinyobj_parse_obj\n"); + int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE); + free(objdata); + + //int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, 0); + if(err != TINYOBJ_SUCCESS){ + printf("Tinyobj failed to load model:%s\n",ppath); + } + printf("num_shapes: %d\n",(int)meshcount); + for(size_t i = 0; i < meshcount; i++){ + tinyobj_shape_t shape = shapes[i]; + printf("Shape %d:\n\tname: %s\n\tface_offset: %d\n\tlength: %d\n",(int)i, shape.name, shape.face_offset, shape.length); + } + //u32 meshcount = pmesh->getMeshBufferCount(); + //size_t numverts = attrib.num_vertices; + //size_t stride = 9; //9 = 3 position floats + 3 normal floats + 3 color floats + //size_t face_offset = 0; + printf("Obj attrib:\n\tnum_vertices:%d\n\tnum_normals:%d\n\tnum_texcoords:%d\n\tnum_faces:%d\n\tnum_face_num_verts:%d\n", + attrib.num_vertices, attrib.num_normals, attrib.num_texcoords, attrib.num_faces, attrib.num_face_num_verts); + //S3DVertex verts[attrib.num_faces]; + //for(size_t i = 0; i < attrib.num_face_num_verts; i++){ + //printf("verts %d starts at %p\n",(int)i,(void*)&(verts[i])); + //} + //u16 indicies[attrib.num_faces]; + size_t index_c = 0; + printf("Faces for %d verts:\n",attrib.num_face_num_verts); + //int num_faces = attrib.num_faces; + //for(int i = 0; i < num_faces; i+=3){ + ////printf("\t%u verts in face %u\n",attrib.face_num_verts[i],i); + //tinyobj_vertex_index_t fac1 = attrib.faces[i + 0]; + //tinyobj_vertex_index_t fac2 = attrib.faces[i + 1]; + //tinyobj_vertex_index_t fac3 = attrib.faces[i + 2]; + ////printf("Verts:\n\tPosition, normal, texture\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n",fac1.v_idx,fac1.vn_idx,fac1.vt_idx,fac2.v_idx,fac2.vn_idx,fac2.vt_idx,fac3.v_idx,fac3.vn_idx,fac3.vt_idx); + + //float f1px, f1py, f1pz; + //f1px = attrib.vertices[(3 * fac1.v_idx) + 0]; + //f1py = attrib.vertices[(3 * fac1.v_idx) + 1]; + //f1pz = attrib.vertices[(3 * fac1.v_idx) + 2]; + //float f1nx, f1ny, f1nz; + //f1nx = attrib.normals[(3 * fac1.vn_idx) + 0]; + //f1ny = attrib.normals[(3 * fac1.vn_idx) + 1]; + //f1nz = attrib.normals[(3 * fac1.vn_idx) + 2]; + + //float f2px, f2py, f2pz; + //f2px = attrib.vertices[(3 * fac2.v_idx) + 0]; + //f2py = attrib.vertices[(3 * fac2.v_idx) + 1]; + //f2pz = attrib.vertices[(3 * fac2.v_idx) + 2]; + //float f2nx, f2ny, f2nz; + //f2nx = attrib.normals[(3 * fac2.vn_idx) + 0]; + //f2ny = attrib.normals[(3 * fac2.vn_idx) + 1]; + //f2nz = attrib.normals[(3 * fac2.vn_idx) + 2]; + + //float f3px, f3py, f3pz; + //f3px = attrib.vertices[(3 * fac3.v_idx) + 0]; + //f3py = attrib.vertices[(3 * fac3.v_idx) + 1]; + //f3pz = attrib.vertices[(3 * fac3.v_idx) + 2]; + //float f3nx, f3ny, f3nz; + //f3nx = attrib.normals[(3 * fac3.vn_idx) + 0]; + //f3ny = attrib.normals[(3 * fac3.vn_idx) + 1]; + //f3nz = attrib.normals[(3 * fac3.vn_idx) + 2]; + + /*printf("Triangle %d:\n\t\ + //Positions:\n\t\t\ + //(%f %f %f)\n\t\t\ + //(%f %f %f)\n\t\t\ + //(%f %f %f)\n\t\ + //Normals:\n\t\t\ + //(%f %f %f)\n\t\t\ + //(%f %f %f)\n\t\t\ + //(%f %f %f)\n",((int)i)/3,f1px,f1py,f1pz,f2px,f2py,f2pz,f3px,f3py,f3pz,f1nx,f1ny,f1nz,f2nx,f2ny,f2nz,f3nx,f3ny,f3nz); + */ + ////float + + //verts[i + 0] = S3DVertex(f1px,f1py,f1pz,f1nx,f1ny,f1nz,SColor(255,255,255,255),0,0); + //verts[i + 1] = S3DVertex(f2px,f2py,f2pz,f2nx,f2ny,f2nz,SColor(255,255,255,255),0,0); + //verts[i + 2] = S3DVertex(f3px,f3py,f3pz,f3nx,f3ny,f3nz,SColor(255,255,255,255),0,0); + //indicies[index_c] = i; + //index_c++; + //indicies[index_c] = i + 1; + //index_c++; + //indicies[index_c] = i + 2; + //index_c++; + //} + S3DVertex verts[attrib.num_vertices]; + u16 indicies[attrib.num_faces]; + for(size_t i = 0; i < attrib.num_vertices; i++){ + float x,y,z; + x = attrib.vertices[i * 3]; + y = attrib.vertices[(i * 3) + 1]; + z = attrib.vertices[(i * 3) + 2]; + verts[i] = S3DVertex(x,y,z,0,0,0,SColor(255,255,255,255),0,0); + } + for(size_t i = 0; i < attrib.num_faces; i ++){ + indicies[i] = attrib.faces[i].v_idx; + } + printf("indicies:\n"); + for(size_t i = 0; i < index_c; i++){ + printf("%d ",indicies[i]); + } + printf("\n"); + + //for(size_t i = 0; i < attrib.num_faces; i++){ + //tinyobj_vertex_index_t tface = attrib.faces[i]; + //printf("Looking at face %d: %d %d %d\n", (int)i, (int)tface.v_idx, (int)tface.vt_idx, (int)tface.vn_idx); + //indicies[index_c] = (u16)tface.v_idx; + //index_c++; + //} + buf->append(verts, attrib.num_vertices, indicies, (u32)attrib.num_faces); + //buf->recalculateBoundingBox(); + SMesh *gmesh = new SMesh(); + gmesh->addMeshBuffer(buf); + //gmesh->recalculateBoundingBox(); + //gmesh->setDirty(); + + //IMesh *gmesh = smgr->getMesh(gpath); + printf("Creating client physbox at %f %f %f\n",x,y,z); ISceneNode *node = smgr->addMeshSceneNode(gmesh,0,-1,vector3df(x,y,z)); printf("bphysnode, createing the physics body\n"); //Create the physics body - IMesh *pmesh = smgr->getMesh(ppath); - printf("We have %d mesh buffers\n",pmesh->getMeshBufferCount()); - u32 meshcount = pmesh->getMeshBufferCount(); - btTriangleMesh* trimesh = new btTriangleMesh(); - for(u32 meshnum = 0; meshnum < meshcount; meshnum++){ - IMeshBuffer *b = pmesh->getMeshBuffer(meshnum); - //assert(b->getVertexType() == video::EVT_STANDARD); - u32 bi = b->getIndexCount(); - u16 *indices = b->getIndices(); - for(u32 i = 0; i < bi; i+= 3){ - printf("Getting triangle %u of %u\n",i,bi); - u16 i1 = indices[i]; - u16 i2 = indices[i + 1]; - u16 i3 = indices[i + 2]; - vector3df p1 = b->getPosition(i1); - vector3df p2 = b->getPosition(i2); - vector3df p3 = b->getPosition(i3); - btVector3 b1 = btVector3(p1.X,p1.Y,p1.Z) ; - btVector3 b2 = btVector3(p2.X,p2.Y,p2.Z) ; - btVector3 b3 = btVector3(p3.X,p3.Y,p3.Z) ; - trimesh->addTriangle(b1,b2,b3); - } - } - printf("Done building trimesh\n"); - 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)); - btVector3 li; - shape->calculateLocalInertia(mass, li); - btRigidBody *rb = new btRigidBody(mass,ms,shape,li); - rb->setUserPointer((void*) node); - World->addRigidBody(rb); - Objects.push_back(rb); - printf("Rigid body finished\n"); + lua_pushstring(L,ppath);//"physpath" + lua_pushnumber(L,mass);//"physpath",mass + pushvector3d(L,x,y,z);//"physpath",mass,{x,y,z} + pushvector3d(L,lx,ly,lz);//"physpath,mass,{x,y,z},{lx,ly,lz} + printf("About to makebphysmodel\n"); + makebphysmodel(L);//ud_rigidbody + printf("done makebphysmodel\n"); + + btRigidBody *rb = (btRigidBody*)lua_touserdata(L,-1); + rb->setUserPointer(node); + lua_pop(L,1); //Create the lua representation - lua_newtable(L); + lua_newtable(L);//{} + lua_pushlightuserdata(L,rb); - lua_setfield(L,-2,"rigidbody"); + lua_setfield(L,-2,"collider");//{rb=ud_rb} + + lua_pushstring(L,"rigidbody"); + lua_setfield(L,-2,"type");//{rb=ud_rb, type="rigidbody"} + lua_pushlightuserdata(L,node); - lua_setfield(L,-2,"node"); + lua_setfield(L,-2,"node");//{rb=ud_rb, node=ud_node, type="rigidbody"} + luaL_getmetatable(L,"phys.physmodel"); - lua_setmetatable(L,-2); + lua_setmetatable(L,-2);//{physnode} + + lua_getglobal(L,"phys");//{rb},{phys} + lua_getfield(L,-1,"colliders");//{rb},{phys},{phys.colliders} + lua_pushlightuserdata(L,rb);//{rb},{phys},{colliders},ud_rb + lua_pushvalue(L,-4);//{rb},{phys},{colliders},ud_rb,{rb} + lua_settable(L,-3);//{rb},{phys},{phys.colliders} + lua_pop(L,2);//{rb} printf("finished creating the lua representation\n"); return 1; @@ -125,8 +256,11 @@ int cbphysmodel_register(lua_State* L){ //printf("bphysmodel registered\n"); luaL_newmetatable(L, "phys.physmodel");//{} - luaL_register(L,NULL,bphysmodel_m); + lua_newtable(L);//{physmodel_m},{} luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes + luaL_register(L,NULL,bcollider_m); + luaL_register(L,NULL,bphysmodel_m); + lua_setfield(L,-2,"__index"); lua_getglobal(L,"phys"); luaL_register(L,NULL,bphysmodel_f); diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp index 482bf31..003f2ad 100644 --- a/src/client/lua_api/scene/icamera.cpp +++ b/src/client/lua_api/scene/icamera.cpp @@ -42,6 +42,7 @@ static int newiscenemayacamera(lua_State* L){ static int newiscenefpscamera(lua_State* L){// ISceneManager* smgr = device->getSceneManager(); ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(); + //cam->bindTargetAndRotation(false); lua_newtable(L);//{} lua_pushlightuserdata(L,cam);//{},ud_cam lua_setfield(L,-2,"node"); @@ -97,21 +98,52 @@ static int newiscenecamera(lua_State* L){ return 1; } +//camera:bind_target(bool) :: nil +static int icamerabindtarget(lua_State *L){ + int should_bind = lua_toboolean(L,-1);//{node=ud_cam},bool_shouldbind + printf("Bind target called %d\n",should_bind); + lua_pop(L,1);//{node=ud_cam} + lua_getfield(L,-1,"node");//{node=ud_cam},ud_cam + ICameraSceneNode *cam = (ICameraSceneNode*)lua_touserdata(L,-1); + lua_pop(L,2);// + cam->bindTargetAndRotation(should_bind == 1); + return 0; +} + +//camera:gettarget() :: v3f +static int icameragettarget(lua_State *L){ + lua_getfield(L,-1,"node"); + ICameraSceneNode *cam = (ICameraSceneNode*)lua_touserdata(L,-1); + lua_pop(L,2);// + vector3df targ = cam->getTarget(); + pushvector3d(L,targ.X, targ.Y, targ.Z); + return 1; +} + +//camera:settarget(v3f) +static int icamerasettarget(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + lua_getfield(L,-1,"node"); + ICameraSceneNode *cam = (ICameraSceneNode*)lua_touserdata(L,-1); + lua_pop(L,2);// + cam->setTarget(vector3df(x,y,z)); + return 0; +} + static const luaL_reg icamera_m[] = { - {"getpos", iscenegetpos}, - {"setpos", iscenesetpos}, - {"getangle", iscenegetangle}, - {"setangle", iscenesetangle}, - {0, 0}, + {"bindtarget", icamerabindtarget}, + {"gettarget", icameragettarget}, + {"settarget", icamerasettarget}, + {0,0}, }; static const luaL_reg imayacamera_m[] = { - {0,0}, + {0,0}, }; static const luaL_reg ifpscamera_m[] = { - {"getpos", iscenegetpos}, - {0,0}, + {0,0}, }; void icamera_register(lua_State* L){ @@ -119,6 +151,7 @@ void icamera_register(lua_State* L){ luaL_newmetatable(L, "scene.icamera");//scene.icamera lua_newtable(L);//scene.icamera, {} luaL_register(L,NULL,icamera_m);//scene.icamera, {} + luaL_register(L,NULL,igeneric_m);//scene.icamera, {} lua_setfield(L,-2,"__index");//scene.icamera lua_pop(L,1);// @@ -126,6 +159,7 @@ void icamera_register(lua_State* L){ lua_newtable(L);//scene.imayascamera,{} luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{} luaL_register(L,NULL,icamera_m);//scene.imayascamera,{} + luaL_register(L,NULL,igeneric_m); lua_setfield(L,-2,"__index");//scene.imayascamera lua_pop(L,1);// @@ -133,6 +167,7 @@ void icamera_register(lua_State* L){ lua_newtable(L);//scene.ifpscamera, {} luaL_register(L,NULL,ifpscamera_m);//scene.ifpscamera,{} luaL_register(L,NULL,icamera_m);//scene.ifpscamera,{} + luaL_register(L,NULL,igeneric_m); lua_setfield(L,-2,"__index");//scene.ifpscamera lua_pop(L,1);// diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp index c6ced65..7a72edf 100644 --- a/src/client/lua_api/scene/imesh.cpp +++ b/src/client/lua_api/scene/imesh.cpp @@ -82,9 +82,9 @@ int newiscenecube(lua_State* L){//{v3 size}, {v3 origin} } static const luaL_reg imesh_m[] = { - {"setMaterial", iscenesetmaterial}, - {"getpos", iscenegetpos}, - {"setpos", iscenesetpos}, + //{"setMaterial", iscenesetmaterial}, + //{"getpos", iscenegetpos}, + //{"setpos", iscenesetpos}, // {"remove", removeiguielement}, {0, 0}, }; @@ -98,6 +98,7 @@ void imesh_register(lua_State* L){ luaL_newmetatable(L, "scene.imesh");//scene.icamera lua_newtable(L);//scene.icamera,{} luaL_register(L,NULL,imesh_m);//scene.icamera,{} + luaL_register(L,NULL,igeneric_m); lua_setfield(L,-2,"__index");//scene.icamera lua_pop(L,1);// |
