diff options
| author | Alexander <alex@cogarr.net> | 2019-06-26 16:14:00 -0400 |
|---|---|---|
| committer | Alexander <alex@cogarr.net> | 2019-06-26 16:14:00 -0400 |
| commit | d5cd0c7b4425e25b11a1ceec154a5c752d508a42 (patch) | |
| tree | ef50cd7d419bba30ee08f46c97232b1c8c68d2be /src/shared/lua_api/phys/bcollider.cpp | |
| parent | 3d60e1432ec43ade4aa61b5a70dd6b8975417e9f (diff) | |
| download | brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.tar.gz brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.tar.bz2 brokengine-d5cd0c7b4425e25b11a1ceec154a5c752d508a42.zip | |
Major refactor of physics code
Move all the physics code into the shared directory,
and fix the ghost objects (aabb only)
Diffstat (limited to 'src/shared/lua_api/phys/bcollider.cpp')
| -rw-r--r-- | src/shared/lua_api/phys/bcollider.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/shared/lua_api/phys/bcollider.cpp b/src/shared/lua_api/phys/bcollider.cpp index 356c504..0a87af3 100644 --- a/src/shared/lua_api/phys/bcollider.cpp +++ b/src/shared/lua_api/phys/bcollider.cpp @@ -33,12 +33,57 @@ to move. int activate(lua_State *L){ btCollisionObject *r = popCollider(L); - r->activate(); + 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} }; |
