#include #include #include extern "C" { #include #include #include } #include #include #include "cbphysbox.hpp" #include "../scene/imesh.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 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){// 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);// 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); }