From 44a1421c393632978d59c0698a93ae22243b97e9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 10 Jun 2020 20:39:54 -0400 Subject: Various progress for 1klutz Added convext shape casts, still a little broken, but it might be just broken bullet side. --- src/shared/lua_api/phys/bcollider.cpp | 178 +++++++++++++++++----------------- 1 file changed, 89 insertions(+), 89 deletions(-) (limited to 'src/shared/lua_api/phys/bcollider.cpp') diff --git a/src/shared/lua_api/phys/bcollider.cpp b/src/shared/lua_api/phys/bcollider.cpp index 0a87af3..91c34fd 100644 --- a/src/shared/lua_api/phys/bcollider.cpp +++ b/src/shared/lua_api/phys/bcollider.cpp @@ -1,89 +1,89 @@ -extern "C" { - #include - #include - #include -} -#include -#include -#include "bcollider.hpp" - - -/*Collider things from lua have the form of: -{ - type = "ghost" | "multi" | "rigidbody" | "softbody" - collider = ud_btCollisionObject, - node = ud_ISceneNode, --Optional, on client -} -*/ -btCollisionObject* popCollider(lua_State *L){ - lua_getfield(L,-1,"collider"); - btCollisionObject *r = (btCollisionObject*)lua_touserdata(L,-1); - lua_pop(L,2); - return r; -} - -/*** -Activates this object. -If this object was sleeping, it will move again. If you are using -applyforce or setvelocity, you will need to activate() the rigidbody for it -to move. -@function collider:activate() -*/ -//collider:activate() -int activate(lua_State *L){ - btCollisionObject *r = popCollider(L); - - r->activate(true); - - return 0; -} - -//collider:getfriction() -int getfriction(lua_State *L){ - btCollisionObject *r = popCollider(L); - double fric = r->getFriction(); - lua_pushnumber(L, fric); - return 1; -} - -//collider:setfriction(number) -int setfriction(lua_State *L){ - double friction = lua_tonumber(L,-1); - lua_pop(L,1); - btCollisionObject *r = popCollider(L); - r->setFriction(friction); - return 0; -} - -//collider:setpos({x,y,z}) -int setpos(lua_State *L){ - double x,y,z; - popvector3d(L,&x,&y,&z); - lua_getfield(L,-1,"collider"); - btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); - lua_pop(L,1); - btTransform t = c->getWorldTransform(); - t.setOrigin(btVector3(x,y,z)); - c->setWorldTransform(t); - c->activate(); - return 0; -} - -//collider:getpos() :: {x,y,z} -int getpos(lua_State *L){ - lua_getfield(L,-1,"collider"); - btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); - btTransform t = c->getWorldTransform(); - btVector3 o = t.getOrigin(); - pushvector3d(L,o.x(), o.y(), o.z()); - return 1; -} - -extern const luaL_reg bcollider_m[] = { - {"activate", activate}, - {"getpos", getpos}, - {"setpos", setpos}, - {"getfriction", getfriction}, - {"setfriction", setfriction}, - {NULL, NULL} -}; +extern "C" { + #include + #include + #include +} +#include +#include +#include "bcollider.hpp" + + +/*Collider things from lua have the form of: +{ + type = "ghost" | "multi" | "rigidbody" | "softbody" + collider = ud_btCollisionObject, + node = ud_ISceneNode, --Optional, on client +} +*/ +btCollisionObject* popCollider(lua_State *L){ + lua_getfield(L,-1,"collider"); + btCollisionObject *r = (btCollisionObject*)lua_touserdata(L,-1); + lua_pop(L,2); + return r; +} + +/*** +Activates this object. +If this object was sleeping, it will move again. If you are using +applyforce or setvelocity, you will need to activate() the rigidbody for it +to move. +@function collider:activate() +*/ +//collider:activate() +int activate(lua_State *L){ + btCollisionObject *r = popCollider(L); + + r->activate(true); + + return 0; +} + +//collider:getfriction() +int getfriction(lua_State *L){ + btCollisionObject *r = popCollider(L); + double fric = r->getFriction(); + lua_pushnumber(L, fric); + return 1; +} + +//collider:setfriction(number) +int setfriction(lua_State *L){ + double friction = lua_tonumber(L,-1); + lua_pop(L,1); + btCollisionObject *r = popCollider(L); + r->setFriction(friction); + return 0; +} + +//collider:setpos({x,y,z}) +int setpos(lua_State *L){ + double x,y,z; + popvector3d(L,&x,&y,&z); + lua_getfield(L,-1,"collider"); + btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); + lua_pop(L,1); + btTransform t = c->getWorldTransform(); + t.setOrigin(btVector3(x,y,z)); + c->setWorldTransform(t); + c->activate(); + return 0; +} + +//collider:getpos() :: {x,y,z} +int getpos(lua_State *L){ + lua_getfield(L,-1,"collider"); + btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1); + btTransform t = c->getWorldTransform(); + btVector3 o = t.getOrigin(); + pushvector3d(L,o.x(), o.y(), o.z()); + return 1; +} + +extern const luaL_reg bcollider_m[] = { + {"activate", activate}, + {"getpos", getpos}, + {"setpos", setpos}, + {"getfriction", getfriction}, + {"setfriction", setfriction}, + {NULL, NULL} +}; -- cgit v1.2.3-70-g09d2