From 891db00bc92e2f56e0c0c4ffc19b9bc7903f1103 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 15 May 2017 23:11:50 -0600 Subject: [PATCH] Body:getLinearVelocity; Body:setLinearVelocity; --- src/api/types/body.c | 21 +++++++++++++++++++++ src/physics/physics.c | 11 +++++++++++ src/physics/physics.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/src/api/types/body.c b/src/api/types/body.c index a338b0fe..09af8f77 100644 --- a/src/api/types/body.c +++ b/src/api/types/body.c @@ -41,10 +41,31 @@ int l_lovrBodySetOrientation(lua_State* L) { return 0; } +int l_lovrBodyGetLinearVelocity(lua_State* L) { + Body* body = luax_checktype(L, 1, Body); + float x, y, z; + lovrBodyGetLinearVelocity(body, &x, &y, &z); + lua_pushnumber(L, x); + lua_pushnumber(L, y); + lua_pushnumber(L, z); + return 3; +} + +int l_lovrBodySetLinearVelocity(lua_State* L) { + Body* body = luax_checktype(L, 1, Body); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + lovrBodySetLinearVelocity(body, x, y, z); + return 0; +} + const luaL_Reg lovrBody[] = { { "getPosition", l_lovrBodyGetPosition }, { "setPosition", l_lovrBodySetPosition }, { "getOrientation", l_lovrBodyGetOrientation }, { "setOrientation", l_lovrBodySetOrientation }, + { "getLinearVelocity", l_lovrBodyGetLinearVelocity }, + { "setLinearVelocity", l_lovrBodySetLinearVelocity }, { NULL, NULL } }; diff --git a/src/physics/physics.c b/src/physics/physics.c index 1d7ff598..5db61052 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -118,3 +118,14 @@ void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z) quat_fromAngleAxis(quaternion, angle, axis); dBodySetQuaternion(body->id, quaternion); } + +void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z) { + const dReal* velocity = dBodyGetLinearVel(body->id); + *x = velocity[0]; + *y = velocity[1]; + *z = velocity[2]; +} + +void lovrBodySetLinearVelocity(Body* body, float x, float y, float z) { + dBodySetLinearVel(body->id, x, y, z); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index f71650b3..99a45518 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -33,3 +33,5 @@ void lovrBodyGetPosition(Body* body, float* x, float* y, float* z); void lovrBodySetPosition(Body* body, float x, float y, float z); void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* z); void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z); +void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z); +void lovrBodySetLinearVelocity(Body* body, float x, float y, float z);