aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-09-29 16:16:42 -0400
committerAlexander Pickering <alex@cogarr.net>2018-09-29 16:16:42 -0400
commit1c790cc19e92d8ad9d74c637de51175159f6bdd2 (patch)
tree6c8e89b97b7c910404ba4ae08f9795937b83b2df
parentecfd36d79eb42a8b83f5984e0d5c1d155498a845 (diff)
downloadbrokengine-1c790cc19e92d8ad9d74c637de51175159f6bdd2.tar.gz
brokengine-1c790cc19e92d8ad9d74c637de51175159f6bdd2.tar.bz2
brokengine-1c790cc19e92d8ad9d74c637de51175159f6bdd2.zip
Added a raytest methods for physics
Added a phys.raytest(vector3 from, vector3 to) :: boolean hasHit
-rw-r--r--src/client/lua_api/load_phys.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/client/lua_api/load_phys.cpp b/src/client/lua_api/load_phys.cpp
index 23bb22a..0a4889b 100644
--- a/src/client/lua_api/load_phys.cpp
+++ b/src/client/lua_api/load_phys.cpp
@@ -8,16 +8,37 @@ extern "C" {
#include <lualib.h>
}
#include <irrlicht.h>
-
#include "../callbackhandeler.hpp"
#include "phys/cbphysbox.hpp"
#include "phys/bphysmodel.hpp"
+#include <btBulletDynamicsCommon.h>
+#include <btBulletCollisionCommon.h>
+//#include <shared/phys/physcommon.hpp>
+#include <shared/lua_api/common.hpp>
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);//{}
@@ -26,4 +47,9 @@ void load_physfuncs(lua_State* L){
cbphysbox_register(L);
bphysmodel_register(L,device);
+
+ lua_getglobal(L,"phys");//{}
+ lua_pushcfunction(L,raytest);//{},raytest()
+ lua_setfield(L,-2,"raytest");//{}
+ lua_pop(L,1);
}