diff options
Diffstat (limited to 'src/client/lua_api/phys')
| -rw-r--r-- | src/client/lua_api/phys/bphysbox.cpp | 49 | ||||
| -rw-r--r-- | src/client/lua_api/phys/cbphysbox.cpp | 93 |
2 files changed, 88 insertions, 54 deletions
diff --git a/src/client/lua_api/phys/bphysbox.cpp b/src/client/lua_api/phys/bphysbox.cpp deleted file mode 100644 index c15646f..0000000 --- a/src/client/lua_api/phys/bphysbox.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <list> -extern "C" { - #include <lua.h> - #include <lauxlib.h> - #include <lualib.h> -} - -#include <btBulletDynamicsCommon.h> -#include <irrlicht.h> -#include "bphysbox.hpp" -#include "../../../shared/lua_api/phys/bphysbox.hpp" - -using namespace irr; -using namespace scene; -using namespace core; -using namespace video; - -extern IrrlichtDevice* device; - -extern btDiscreteDynamicsWorld* World; -extern std::list<btRigidBody*> Objects; -/* -static LBPhysNode* checkisbphysbox(lua_State* L, int index){ - void* ud = luaL_checkudata(L,index,"phys.physbox"); - luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected"); - return (LBPhysNode*) ud; -} -*/ - -/* -static LISceneNode* checkismesh(lua_State* L){ - return checkismesh(L,1); -} -*/ - -//phys.newphysbox({vector3 size},{vector3 origin},mass) -/* -static int newcbphysbox(lua_State* L){// - newbphysbox(L);//{phys.physbox} - LBPhysNode -} -*/ - -void cbphysbox_register(lua_State* L){ - bphysbox_register(L); -} diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp index 0da9939..029e6ab 100644 --- a/src/client/lua_api/phys/cbphysbox.cpp +++ b/src/client/lua_api/phys/cbphysbox.cpp @@ -11,6 +11,7 @@ extern "C" { #include <btBulletDynamicsCommon.h> #include <irrlicht.h> #include "cbphysbox.hpp" +#include "../scene/imesh.hpp" #include "../../../shared/lua_api/phys/bphysbox.hpp" using namespace irr; @@ -22,6 +23,7 @@ extern IrrlichtDevice* device; extern btDiscreteDynamicsWorld* World; extern std::list<btRigidBody*> Objects; + /* static LBPhysNode* checkisbphysbox(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"phys.physbox"); @@ -37,13 +39,94 @@ static LISceneNode* checkismesh(lua_State* L){ */ //phys.newphysbox({vector3 size},{vector3 origin},mass) -/* static int newcbphysbox(lua_State* L){// - newbphysbox(L);//{phys.physbox} - LBPhysNode + printf("Createing new cbphysbox\n"); + double sx,sy,sz,x,y,z,mass; + //Get the data + mass = lua_tonumber(L,-1);//{v3 size}, {v3 origin}, mass + lua_pop(L,1);//{v3 size}, {v3 origin} + 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} + lua_pushnumber(L,mass);//{v3 size}, {v3 origin}, mass + makenewbphysbox(L);//ud_btRigidbody + btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//ud_btRigidbody + 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); + + lua_newtable(L);//{} + lua_pushlightuserdata(L,r);//{},ud_rigidbody + lua_setfield(L,-2,"rigidbody");//{} + lua_pushlightuserdata(L,n);//{},ud_iscenenode + lua_setfield(L,-2,"node");//{} + + luaL_getmetatable(L,"phys.physbox");//{},{phys.physbox} + lua_setmetatable(L,-2);//{} + + return 1; } -*/ + +//bphysbox:setpos({v3 pos}) +int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{v3 pos} + printf("calling cbphysbox setpos\n"); + double x,y,z; + 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 + 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} + lua_getfield(L,-1,"node");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode + ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{btRigidBody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode + printf("Got node, it was %p\n",i); + lua_pop(L,2);// + + btTransform bt; + btMotionState* ms = r->getMotionState(); + ms->getWorldTransform(bt); + bt.setOrigin(btVector3(x,y,z)); + ms->setWorldTransform(bt); + r->activate(); + + i->setPosition(vector3df(x,y,z)); + i->updateAbsolutePosition(); + + return 0; + +} + +static const luaL_reg cbphysbox_m[] = { + {"setcpos", cbphyssetpos},//overload +// {"delete", delbphysbox},//client side delete needs to delete the visual representation + {0, 0}, +}; void cbphysbox_register(lua_State* L){ - bphysbox_register(L); + bphysbox_register(L);// + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox() + lua_setfield(L,-2,"newcphysbox");//{} + + lua_pop(L,1);// + + luaL_getmetatable(L,"phys.physbox");//phys.physbox + lua_newtable(L);//phys.physbox,{} + luaL_register(L,NULL,cbphysbox_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); + } |
