aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/lua_api/common.hpp1
-rw-r--r--src/shared/lua_api/load_phys.cpp6
-rw-r--r--src/shared/lua_api/phys/bphysgeneric.cpp41
3 files changed, 47 insertions, 1 deletions
diff --git a/src/shared/lua_api/common.hpp b/src/shared/lua_api/common.hpp
index 0b7abd6..583ab1e 100644
--- a/src/shared/lua_api/common.hpp
+++ b/src/shared/lua_api/common.hpp
@@ -1,6 +1,7 @@
#ifndef __broken_shared_lua_common
#define __broken_shared_lua_common
+#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3);
extern "C" {
#include <lua.h>
#include <lauxlib.h>
diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp
index 6875970..7580e99 100644
--- a/src/shared/lua_api/load_phys.cpp
+++ b/src/shared/lua_api/load_phys.cpp
@@ -1,10 +1,16 @@
#include "load_phys.hpp"
#include "phys/bphysbox.hpp"
#include "phys/bhingeconstraint.hpp"
+#include <btBulletDynamicsCommon.h>
+#include <shared/lua_api/common.hpp>
void load_physfuncs(lua_State* L){
lua_newtable(L);//{}
lua_setglobal(L,"phys");
+ set_const(L,BT_DISABLE_WORLD_GRAVITY);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY);
bphysbox_register(L);
bhingeconstraint_register(L);
}
diff --git a/src/shared/lua_api/phys/bphysgeneric.cpp b/src/shared/lua_api/phys/bphysgeneric.cpp
index 44c789d..5faef2d 100644
--- a/src/shared/lua_api/phys/bphysgeneric.cpp
+++ b/src/shared/lua_api/phys/bphysgeneric.cpp
@@ -18,7 +18,12 @@ extern "C" {
node = ISceneNode,
}
*/
-
+btRigidBody* popRigidBody(lua_State *L){
+ lua_getfield(L,-1,"rigidbody");
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+ return r;
+}
/***
Sets the direction of gravity on this object.
@function rigidbody:setgravity({x,y,z})
@@ -215,9 +220,42 @@ int setdamping(lua_State *L){
return 0;
}
+/***
+Sets flags on this rigidbody
+@function rigidbody:setflags(flags)
+@tparam number flags
+*/
+int setflags(lua_State *L){
+ int flags = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_getfield(L,-1,"rigidbody");
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+
+ r->setFlags(flags);
+
+ return 0;
+}
+
+/***
+Apply an impulse to the rigidboy
+@function rigidbody:centralimpulse(vec3 impulse)
+@tparam vector3 impulse The direction to apply the impulse in
+*/
+int applyimpulse(lua_State *L){
+ double x,y,z,ox,oy,oz;
+ popvector3d(L,&x,&y,&z);
+ popvector3d(L,&ox,&oy,&oz);
+ btRigidBody *r = popRigidBody(L);
+ r->applyImpulse(btVector3(x,y,z),btVector3(ox,oy,oz));
+ return 0;
+}
+
extern const luaL_reg brigidbody_m[] = {
{"setgravity", setgravity},
{"applyforce", applyforce},
+ {"applyimpulse", applyimpulse},
{"getldamping", getlineardamping},
{"getadamping", getangulardamping},
{"setdamping", setdamping},
@@ -225,5 +263,6 @@ extern const luaL_reg brigidbody_m[] = {
{"getvelocity", getvelocity},
{"setvelocity", setvelocity},
{"setangfactor", setangfactor},
+ {"setflags", setflags},
{NULL, NULL}
};