diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-09-23 16:07:21 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-09-23 16:07:21 -0400 |
| commit | 921cfb8d147aea751bb494b4a88efe4cb75daa68 (patch) | |
| tree | 4354942939dcc2c93617581cdaca6986f637d297 /src/client/lua_api/phys/bphysgeneric.cpp | |
| parent | c38d5eca7091fc7f0206ed0c746622022b2ae508 (diff) | |
| download | brokengine-921cfb8d147aea751bb494b4a88efe4cb75daa68.tar.gz brokengine-921cfb8d147aea751bb494b4a88efe4cb75daa68.tar.bz2 brokengine-921cfb8d147aea751bb494b4a88efe4cb75daa68.zip | |
Started moving generic physics into it's own file
Created bphysgeneric that holds all the shared code for bullet
rigidbodies. It needs to be included in any structs that have
a rigidbody field.
Diffstat (limited to 'src/client/lua_api/phys/bphysgeneric.cpp')
| -rw-r--r-- | src/client/lua_api/phys/bphysgeneric.cpp | 115 |
1 files changed, 115 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; +} |
