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 | |
| 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.
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | src/client/lua_api/phys/bphysgeneric.cpp | 115 | ||||
| -rw-r--r-- | src/client/lua_api/phys/bphysgeneric.hpp | 24 |
3 files changed, 140 insertions, 1 deletions
@@ -151,7 +151,7 @@ SHARED_CLIENT_OBJS = $(SHARED_CLIENT_FILES:%=$(BUILD_DIR)/$(CLIENTNAME)/%.o) # The client-side only stuff LAPI_GUI = iguibutton iguicheckbox iguielement iguiimage iguilabel iguiwindow iguieditbox iguicolorselector iguifiledialog iguispinbox iguitreeview -LAPI_PHYS = bphysmodel cbphysbox +LAPI_PHYS = bphysmodel cbphysbox bphysgeneric LAPI_SCENE = icamera igeneric ilight imesh LAPI_VIDEO = iimage itexture smaterial LAPI_IO = ifilesystem 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} +}; |
