diff options
Diffstat (limited to 'src/client/lua_api/phys')
| -rw-r--r-- | src/client/lua_api/phys/bphysgeneric.cpp | 115 | ||||
| -rw-r--r-- | src/client/lua_api/phys/bphysgeneric.hpp | 24 |
2 files changed, 139 insertions, 0 deletions
diff --git a/src/client/lua_api/phys/bphysgeneric.cpp b/src/client/lua_api/phys/bphysgeneric.cpp new file mode 100644 index 0000000..0d882d6 --- /dev/null +++ b/src/client/lua_api/phys/bphysgeneric.cpp @@ -0,0 +1,115 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <btBulletDynamicsCommon.h> +//#include <irrlicht.h> +#include <shared/lua_api/common.hpp> + +//extern IrrlichtDevice* device; + +//extern btDiscreteDynamicsWorld* World; +//extern std::list<btRigidBody*> Objects; + +/*Physics things have the form of: +{ + rigidbody = btRigidBody, + node = ISceneNode, +} +*/ + +//rigidbody:setgravity({x,y,z}) +int setgravity(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + btVector3 v = btVector3(x,y,z); + + r->setGravity(v); + + return 0; +} + +//apply force at a reletive offset +//rigidbody:applyforce({x,y,z}[,{rx,ry,rz}]) +int applyforce(lua_State *L){ + double rx,ry,rz; + rx = 0; + ry = 0; + rz = 0; + if(lua_gettop(L) > 2){ + popvector3d(L,&rx,&ry,&rz);//{phys},{x,y,z} + } + + double x,y,z; + popvector3d(L,&x,&y,&z);//{phys} + + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + btVector3 v = btVector3(x,y,z); + btVector3 o = btVector3(rx,ry,rz); + + r->applyForce(v,o); + + return 0; +} + +//rigidbody:getldamping() +int getlineardamping(lua_State *L){ + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + double damp = r->getLinearDamping(); + lua_pushnumber(L,damp); + + return 1; +} + + +//rigidbody:getadamping() +int getangulardamping(lua_State *L){ + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + double damp = r->getAngularDamping(); + lua_pushnumber(L,damp); + + return 1; +} + +//rigidbody:activate() +int activate(lua_State *L){ + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + r->activate(); + + return 0; +} + +//rigidbody:setdamping(lineardamping, angulardamping) +int setdamping(lua_State *L){ + double adamp,ldamp; + adamp = lua_tonumber(L,-1); + ldamp = lua_tonumber(L,-2); + lua_pop(L,2); + + lua_getfield(L,-1,"rigidbody"); + btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1); + lua_pop(L,2); + + r->setDamping(adamp,ldamp); + + return 0; +} diff --git a/src/client/lua_api/phys/bphysgeneric.hpp b/src/client/lua_api/phys/bphysgeneric.hpp new file mode 100644 index 0000000..56bfaed --- /dev/null +++ b/src/client/lua_api/phys/bphysgeneric.hpp @@ -0,0 +1,24 @@ + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + + +int setgravity(lua_State *L); +int applyforce(lua_State *L); +int getlineardamping(lua_State *L); +int getangulardamping(lua_State *L); +int setdamping(lua_State *L); +int activate(lua_State *L); + +static const luaL_reg brigidbody_m[] = { + {"setgravity", setgravity}, + {"applyforce", applyforce}, + {"getldamping", getlineardamping}, + {"getadamping", getangulardamping}, + {"setdamping", setdamping}, + {"activate", activate}, + {NULL, NULL} +}; |
