From 35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 26 Dec 2017 00:57:52 -0500 Subject: Major update --- src/shared/lua_api/phys/bphysbox.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/shared/lua_api/phys/bphysbox.cpp') diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp index be9db07..3036cf9 100644 --- a/src/shared/lua_api/phys/bphysbox.cpp +++ b/src/shared/lua_api/phys/bphysbox.cpp @@ -26,22 +26,15 @@ static LISceneNode* checkismesh(lua_State* L){ return checkismesh(L,1); } */ - -// phys.newphysbox(vector3 size, vector3 origin, double mass) -int newbphysbox(lua_State* L){ - printf("Createing bphysbox!\n"); - int nargs = lua_gettop(L); - if(nargs != 3){ - lua_pushfstring(L,"Expected 3 arguments, got %d",nargs); - lua_error(L); - } +// ud_btRigidBody :: ({v3 size}, {v3 origin}, double mass) +void makenewbphysbox(lua_State* L){ double px,py,pz; //position double sx,sy,sz; //size double mass; mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass lua_pop(L,1);//{v3_size},{v3_origin} - printf("Got mass: %d\n",mass); + printf("Got mass: %f\n",mass); popvector3d(L,&px,&py,&pz);//{v3_size} printf("Got position: (%f,%f,%f)\n",px,py,pz); @@ -73,9 +66,18 @@ int newbphysbox(lua_State* L){ World->addRigidBody(rigidbody); Objects.push_back(rigidbody); + lua_pushlightuserdata(L,rigidbody);//ud_rigidbody +} + +// phys.newphysbox(vector3 size, vector3 origin, double mass) +int newbphysbox(lua_State* L){ + printf("Createing bphysbox!\n"); //Create it's lua representation + makenewbphysbox(L);//ud_btRigidBody + btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,1); lua_newtable(L);//{} - lua_pushlightuserdata(L,rigidbody);//{},ud_rigidbody + lua_pushlightuserdata(L,r);//ud_btRigidBody lua_setfield(L,-2,"rigidbody");//{} //Set it's metatable @@ -118,6 +120,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos} // {v3 pos} :: physbox:getpos() static int bphysgetpos(lua_State *L){//self + printf("Physics box set pos called\n"); lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody btRigidBody* i = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody btTransform bt = i->getWorldTransform(); @@ -145,7 +148,8 @@ void bphysbox_register(lua_State* L){// lua_pop(L,1);// lua_getglobal(L,"phys");//{} - lua_pushcfunction(L,newbphysbox); - lua_setfield(L,-2,"newphysbox"); + lua_pushcfunction(L,newbphysbox);//{},newbphysbox() + lua_setfield(L,-2,"newphysbox");//{} + lua_pop(L,1); } -- cgit v1.2.3-70-g09d2