From f672fe77cd10396ab2239ac0b48f4db8a8099974 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 15 May 2017 23:15:50 -0600 Subject: [PATCH] Body:isKinematic; Body:setKinematic; --- src/api/types/body.c | 15 +++++++++++++++ src/physics/physics.c | 12 ++++++++++++ src/physics/physics.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/api/types/body.c b/src/api/types/body.c index 6f244613..689b05b2 100644 --- a/src/api/types/body.c +++ b/src/api/types/body.c @@ -140,6 +140,19 @@ int l_lovrBodyApplyTorque(lua_State* L) { return 0; } +int l_lovrBodyIsKinematic(lua_State* L) { + Body* body = luax_checktype(L, 1, Body); + lua_pushboolean(L, lovrBodyIsKinematic(body)); + return 1; +} + +int l_lovrBodySetKinematic(lua_State* L) { + Body* body = luax_checktype(L, 1, Body); + int kinematic = lua_toboolean(L, 2); + lovrBodySetKinematic(body, kinematic); + return 0; +} + const luaL_Reg lovrBody[] = { { "getPosition", l_lovrBodyGetPosition }, { "setPosition", l_lovrBodySetPosition }, @@ -155,5 +168,7 @@ const luaL_Reg lovrBody[] = { { "setAngularDamping", l_lovrBodySetAngularDamping }, { "applyForce", l_lovrBodyApplyForce }, { "applyTorque", l_lovrBodyApplyForce }, + { "isKinematic", l_lovrBodyIsKinematic }, + { "setKinematic", l_lovrBodySetKinematic }, { NULL, NULL } }; diff --git a/src/physics/physics.c b/src/physics/physics.c index 1917b104..7a2549ff 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -172,3 +172,15 @@ void lovrBodyApplyForceAtPosition(Body* body, float x, float y, float z, float c void lovrBodyApplyTorque(Body* body, float x, float y, float z) { dBodyAddTorque(body->id, x, y, z); } + +int lovrBodyIsKinematic(Body* body) { + return dBodyIsKinematic(body->id); +} + +void lovrBodySetKinematic(Body* body, int kinematic) { + if (kinematic) { + dBodySetKinematic(body->id); + } else { + dBodySetDynamic(body->id); + } +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 2a952700..bbd7168f 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -44,3 +44,5 @@ void lovrBodySetAngularDamping(Body* body, float damping, float threshold); void lovrBodyApplyForce(Body* body, float x, float y, float z); void lovrBodyApplyForceAtPosition(Body* body, float x, float y, float z, float cx, float cy, float cz); void lovrBodyApplyTorque(Body* body, float x, float y, float z); +int lovrBodyIsKinematic(Body* body); +void lovrBodySetKinematic(Body* body, int kinematic);