aboutsummaryrefslogtreecommitdiff
path: root/src/shared/lua_api/phys
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
commit35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (patch)
treed345f620b51ae1ad1d7923e572a6b07ed8731ee5 /src/shared/lua_api/phys
parentcc12503339004bae2f945e7f7339fc845b2a194f (diff)
downloadbrokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.gz
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.bz2
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.zip
Major update
Diffstat (limited to 'src/shared/lua_api/phys')
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp30
-rw-r--r--src/shared/lua_api/phys/bphysbox.hpp2
2 files changed, 18 insertions, 14 deletions
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index be9db07..3036cf9 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -26,22 +26,15 @@ static LISceneNode* checkismesh(lua_State* L){
return checkismesh(L,1);
}
*/
-
-// phys.newphysbox(vector3 size, vector3 origin, double mass)
-int newbphysbox(lua_State* L){
- printf("Createing bphysbox!\n");
- int nargs = lua_gettop(L);
- if(nargs != 3){
- lua_pushfstring(L,"Expected 3 arguments, got %d",nargs);
- lua_error(L);
- }
+// ud_btRigidBody :: ({v3 size}, {v3 origin}, double mass)
+void makenewbphysbox(lua_State* L){
double px,py,pz; //position
double sx,sy,sz; //size
double mass;
mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass
lua_pop(L,1);//{v3_size},{v3_origin}
- printf("Got mass: %d\n",mass);
+ printf("Got mass: %f\n",mass);
popvector3d(L,&px,&py,&pz);//{v3_size}
printf("Got position: (%f,%f,%f)\n",px,py,pz);
@@ -73,9 +66,18 @@ int newbphysbox(lua_State* L){
World->addRigidBody(rigidbody);
Objects.push_back(rigidbody);
+ lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
+}
+
+// phys.newphysbox(vector3 size, vector3 origin, double mass)
+int newbphysbox(lua_State* L){
+ printf("Createing bphysbox!\n");
//Create it's lua representation
+ makenewbphysbox(L);//ud_btRigidBody
+ btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,1);
lua_newtable(L);//{}
- lua_pushlightuserdata(L,rigidbody);//{},ud_rigidbody
+ lua_pushlightuserdata(L,r);//ud_btRigidBody
lua_setfield(L,-2,"rigidbody");//{}
//Set it's metatable
@@ -118,6 +120,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos}
// {v3 pos} :: physbox:getpos()
static int bphysgetpos(lua_State *L){//self
+ printf("Physics box set pos called\n");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* i = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
btTransform bt = i->getWorldTransform();
@@ -145,7 +148,8 @@ void bphysbox_register(lua_State* L){//
lua_pop(L,1);//
lua_getglobal(L,"phys");//{}
- lua_pushcfunction(L,newbphysbox);
- lua_setfield(L,-2,"newphysbox");
+ lua_pushcfunction(L,newbphysbox);//{},newbphysbox()
+ lua_setfield(L,-2,"newphysbox");//{}
+ lua_pop(L,1);
}
diff --git a/src/shared/lua_api/phys/bphysbox.hpp b/src/shared/lua_api/phys/bphysbox.hpp
index c031037..96b58a7 100644
--- a/src/shared/lua_api/phys/bphysbox.hpp
+++ b/src/shared/lua_api/phys/bphysbox.hpp
@@ -11,4 +11,4 @@ extern "C" {
#include "../common.h"
void bphysbox_register(lua_State* L);
-int newbphysbox(lua_State* L);
+void makenewbphysbox(lua_State* L);