diff options
Diffstat (limited to 'src/shared/lua_api')
| -rw-r--r-- | src/shared/lua_api/common.c | 25 | ||||
| -rw-r--r-- | src/shared/lua_api/common.h | 1 | ||||
| -rw-r--r-- | src/shared/lua_api/load_phys.cpp | 8 | ||||
| -rw-r--r-- | src/shared/lua_api/load_phys.hpp | 7 | ||||
| -rw-r--r-- | src/shared/lua_api/phys/bgame.cpp | 13 | ||||
| -rw-r--r-- | src/shared/lua_api/phys/bphysbox.cpp | 21 |
6 files changed, 60 insertions, 15 deletions
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c index 50eb850..9a8baca 100644 --- a/src/shared/lua_api/common.c +++ b/src/shared/lua_api/common.c @@ -86,6 +86,31 @@ int pushvector2i(lua_State* L, long a, long b){ return 1; } +int popvector4i(lua_State* L,long* a,long* b,long* c, long* d){ + lua_pushinteger(L,1);//{v4},1 + lua_gettable(L,-2);//{v4},v4[1] + *a = lua_tointeger(L,-1);//{v4},v4[1] + lua_pop(L,1);//{v4} + + lua_pushinteger(L,2);//{v4},2 + lua_gettable(L,-2);//{v4},v4[2] + *b = lua_tointeger(L,-1);//{v4},v4[2] + lua_pop(L,1);//{v4} + + lua_pushinteger(L,3);//{v4},3 + lua_gettable(L,-2);//{v4},v4[3] + *c = lua_tointeger(L,-1);//{v4},v4[3] + lua_pop(L,1);//{v4} + + lua_pushinteger(L,4);//{v4},3 + lua_gettable(L,-2);//{v4},v4[3] + *d = lua_tointeger(L,-1);//{v4},v4[3] + lua_pop(L,1);//{v4} + + lua_pop(L,1);// + return 0; +} + int popvector3i(lua_State* L,long* a,long* b,long* c){//{v3} lua_pushinteger(L,1);//{v3},1 lua_gettable(L,-2);//{v3},v3[1] diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h index 9260706..c2e067d 100644 --- a/src/shared/lua_api/common.h +++ b/src/shared/lua_api/common.h @@ -11,6 +11,7 @@ int pushvector3i(lua_State*,long,long,long); int pushvector3d(lua_State*,double,double,double); int pushvector2i(lua_State*,long,long); +int popvector4i(lua_State*,long*,long*,long*,long*); int popvector3i(lua_State*,long*,long*,long*); int popvector3d(lua_State*,double*,double*,double*); int popvector2i(lua_State*,long*,long*); diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp index c91396c..14a27ea 100644 --- a/src/shared/lua_api/load_phys.cpp +++ b/src/shared/lua_api/load_phys.cpp @@ -1,6 +1,8 @@ -#include "load_phys.hpp" - +#include "./load_phys.hpp" +#include "./phys/bphysbox.hpp" void loadPhysLibs(lua_State* L){ - + lua_newtable(L);//{} + lua_setglobal(L,"phys"); + bphysbox_register(L); } diff --git a/src/shared/lua_api/load_phys.hpp b/src/shared/lua_api/load_phys.hpp index 5e05642..6f9e9a9 100644 --- a/src/shared/lua_api/load_phys.hpp +++ b/src/shared/lua_api/load_phys.hpp @@ -3,12 +3,5 @@ extern "C" { #include <lauxlib.h> #include <lualib.h> } -#include "load_core.hpp" - -struct EntityPhysics : EntityMass{ - btTransform* transform; - btRigidBody* rigidbody; - btCollisionShape* shape; -}EntityPhysics; void loadPhysLibs(lua_State* L); diff --git a/src/shared/lua_api/phys/bgame.cpp b/src/shared/lua_api/phys/bgame.cpp new file mode 100644 index 0000000..b755787 --- /dev/null +++ b/src/shared/lua_api/phys/bgame.cpp @@ -0,0 +1,13 @@ +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +#include <btBulletDynamicsCommon.h> + +extern btDiscreteDynamicsWorld* World; + +void registergravity(lua_State* L){ + +} diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp index 3036cf9..78f1c45 100644 --- a/src/shared/lua_api/phys/bphysbox.cpp +++ b/src/shared/lua_api/phys/bphysbox.cpp @@ -45,25 +45,34 @@ void makenewbphysbox(lua_State* L){ btVector3 pos = btVector3(px,py,pz); // Set the initial position of the object - btTransform transform; - transform.setIdentity(); - transform.setOrigin(pos); + btTransform transform = btTransform(btQuaternion(0,0,0,1),pos); + //transform.setIdentity(); + //transform.setOrigin(pos); // Give it a default MotionState btDefaultMotionState* motionstate = new btDefaultMotionState(transform); - + if(!motionstate){ + printf("No motionstate\n"); + } // Create the shape btCollisionShape* shape = new btBoxShape(vshape); + if(!shape){ + printf("no shape\n"); + } // Add mass - btVector3 localinertia; + btVector3 localinertia = btVector3(0,0,0); shape->calculateLocalInertia(mass, localinertia); // Create the rigid body object btRigidBody* rigidbody = new btRigidBody(mass, motionstate, shape, localinertia); + if(!rigidbody){ + printf("No rigidbody\n"); + } // Add it to the world World->addRigidBody(rigidbody); + printf("Added rigid body to world: %p\n",World); Objects.push_back(rigidbody); lua_pushlightuserdata(L,rigidbody);//ud_rigidbody @@ -114,6 +123,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos} bt.setOrigin(to); ms->setWorldTransform(bt); i->activate(); + lua_pop(L,1);// return 0; } @@ -139,6 +149,7 @@ static const luaL_reg bphysbox_m[] = { }; void bphysbox_register(lua_State* L){// + printf("Registered bphysbox\n"); luaL_newmetatable(L, "phys.physbox");//{phys.physbox} lua_newtable(L);//{phys.physbox},{} |
