From 112517494847f0c86f58544cbf4c35c9b7712ab1 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 1 Nov 2018 13:53:16 -0400 Subject: Refactored code and added library Physics code for models now lives in the shared directory. To get file loading without irrlicht, a single-file header library (lib/tinyobjloader-c) was added. Metatables for generics and physics generics have also been seperated out. --- src/client/lua_api/load_cphys.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/client/lua_api/load_cphys.cpp (limited to 'src/client/lua_api/load_cphys.cpp') diff --git a/src/client/lua_api/load_cphys.cpp b/src/client/lua_api/load_cphys.cpp new file mode 100644 index 0000000..b38b84d --- /dev/null +++ b/src/client/lua_api/load_cphys.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "../callbackhandeler.hpp" +#include "phys/cbphysbox.hpp" +#include "phys/cbphysmodel.hpp" +#include +#include +//#include +#include + +using namespace irr; +using namespace gui; +using namespace core; + +extern IrrlichtDevice* device; +extern btDiscreteDynamicsWorld* World; +extern btBroadphaseInterface *BroadPhase; + +//raytest({from},{to},{mins},{maxes}) :: hashit +int raytest(lua_State *L){ + double fx,fy,fz; + double tx,ty,tz; + popvector3d(L, &fx, &fy, &fz); + popvector3d(L, &tx, &ty, &tz); + + btVector3 from(fx, fy, fz); + btVector3 to(tx, ty, tz); + btCollisionWorld::RayResultCallback *res = new btDiscreteDynamicsWorld::ClosestRayResultCallback(from, to); + World->rayTest(from,to,*res); + + lua_pushboolean(L,res->hasHit()); + return 1; +} + +void load_physfuncs(lua_State* L){ + lua_newtable(L);//{} + lua_setglobal(L,"phys");// + //phys things + cbphysbox_register(L); + + cbphysmodel_register(L); + + lua_getglobal(L,"phys");//{} + lua_pushcfunction(L,raytest);//{},raytest() + lua_setfield(L,-2,"raytest");//{} + lua_pop(L,1); +} -- cgit v1.2.3-70-g09d2