diff options
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/lua_api/common.c | 37 | ||||
| -rw-r--r-- | src/shared/lua_api/common.h | 3 | ||||
| -rw-r--r-- | src/shared/lua_api/phys/bphysbox.cpp | 22 | ||||
| -rw-r--r-- | src/shared/phys/physcommon.cpp | 12 |
4 files changed, 57 insertions, 17 deletions
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c index 9a8baca..2eeee11 100644 --- a/src/shared/lua_api/common.c +++ b/src/shared/lua_api/common.c @@ -153,6 +153,43 @@ int popvector3d(lua_State* L,double* a,double* b,double* c){ return 0; } +int popvector4d(lua_State* L, double *a, double *b, double *c, double *d){ + lua_pushinteger(L,1);//{a,b,c,d},1 + lua_gettable(L,-2);//{a,b,c,d},a + *a = lua_tonumber(L,-1);//{a,b,c,d},a + lua_pop(L,1);//{a,b,c,d} + + lua_pushinteger(L,2); + lua_gettable(L,-2); + *b = lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pushinteger(L,3); + lua_gettable(L,-2); + *c = lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pushinteger(L,4); + lua_gettable(L,-2); + *d = lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pop(L,1); + return 0; +} + +//{{sx,sy},{ex,ey}} +int poprecti(lua_State* L, long *sx, long *sy, long *ex, long *ey){ + lua_pushnumber(L,1); + lua_gettable(L,-2); + popvector2i(L,sx,sy); + lua_pushnumber(L,2); + lua_gettable(L,-2); + popvector2i(L,ex,ey); + lua_pop(L,1); + return 0; +} + int popvector2i(lua_State* L, long* a, long* b){ lua_pushinteger(L,1); lua_gettable(L,-2); diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h index c2e067d..6086065 100644 --- a/src/shared/lua_api/common.h +++ b/src/shared/lua_api/common.h @@ -12,6 +12,9 @@ int pushvector3d(lua_State*,double,double,double); int pushvector2i(lua_State*,long,long); int popvector4i(lua_State*,long*,long*,long*,long*); +int popvector4d(lua_State*,double*,double*,double*,double*); int popvector3i(lua_State*,long*,long*,long*); int popvector3d(lua_State*,double*,double*,double*); int popvector2i(lua_State*,long*,long*); + +int poprecti(lua_State* L,long*,long*,long*,long*); diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp index 78f1c45..0fe9f72 100644 --- a/src/shared/lua_api/phys/bphysbox.cpp +++ b/src/shared/lua_api/phys/bphysbox.cpp @@ -34,14 +34,14 @@ void makenewbphysbox(lua_State* L){ mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass lua_pop(L,1);//{v3_size},{v3_origin} - printf("Got mass: %f\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); + //printf("Got position: (%f,%f,%f)\n",px,py,pz); popvector3d(L,&sx,&sy,&sz);// btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f); - printf("Got size: (%f,%f,%f)\n",sx,sy,sz); + //printf("Got size: (%f,%f,%f)\n",sx,sy,sz); btVector3 pos = btVector3(px,py,pz); // Set the initial position of the object @@ -52,12 +52,12 @@ void makenewbphysbox(lua_State* L){ // Give it a default MotionState btDefaultMotionState* motionstate = new btDefaultMotionState(transform); if(!motionstate){ - printf("No motionstate\n"); + //printf("No motionstate\n"); } // Create the shape btCollisionShape* shape = new btBoxShape(vshape); if(!shape){ - printf("no shape\n"); + //printf("no shape\n"); } // Add mass @@ -67,12 +67,12 @@ void makenewbphysbox(lua_State* L){ // Create the rigid body object btRigidBody* rigidbody = new btRigidBody(mass, motionstate, shape, localinertia); if(!rigidbody){ - printf("No rigidbody\n"); + //printf("No rigidbody\n"); } // Add it to the world World->addRigidBody(rigidbody); - printf("Added rigid body to world: %p\n",World); + //printf("Added rigid body to world: %p\n",World); Objects.push_back(rigidbody); lua_pushlightuserdata(L,rigidbody);//ud_rigidbody @@ -80,7 +80,7 @@ void makenewbphysbox(lua_State* L){ // phys.newphysbox(vector3 size, vector3 origin, double mass) int newbphysbox(lua_State* L){ - printf("Createing bphysbox!\n"); + //printf("Createing bphysbox!\n"); //Create it's lua representation makenewbphysbox(L);//ud_btRigidBody btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1); @@ -98,7 +98,7 @@ int newbphysbox(lua_State* L){ //{phys.physbox}:delete() static int delbphysbox(lua_State* L){//self - printf("Attempting to delete physbox\n"); + //printf("Attempting to delete physbox\n"); lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody delete r->getCollisionShape(); @@ -130,7 +130,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"); + //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(); @@ -149,7 +149,7 @@ static const luaL_reg bphysbox_m[] = { }; void bphysbox_register(lua_State* L){// - printf("Registered bphysbox\n"); + //printf("Registered bphysbox\n"); luaL_newmetatable(L, "phys.physbox");//{phys.physbox} lua_newtable(L);//{phys.physbox},{} diff --git a/src/shared/phys/physcommon.cpp b/src/shared/phys/physcommon.cpp index 4f506bb..b1c4c67 100644 --- a/src/shared/phys/physcommon.cpp +++ b/src/shared/phys/physcommon.cpp @@ -33,17 +33,17 @@ btSequentialImpulseConstraintSolver* Solver; void phys_genesis(){ BroadPhase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000)); - printf("Broadphase\n"); + //printf("Broadphase\n"); CollisionConfiguration = new btDefaultCollisionConfiguration(); - printf("Collision config\n"); + //printf("Collision config\n"); Dispatcher = new btCollisionDispatcher(CollisionConfiguration); - printf("Dispatcher\n"); + //printf("Dispatcher\n"); Solver = new btSequentialImpulseConstraintSolver(); - printf("Solver\n"); + //printf("Solver\n"); World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration); - printf("Physics world init ok.\n"); + //printf("Physics world init ok.\n"); World->setGravity(btVector3(0,-10,0)); - printf("Created physics world: %p\n",World); + //printf("Created physics world: %p\n",World); } void phys_shutdown(void(*f)(btRigidBody*)){ |
