diff --git a/src/api/types/body.c b/src/api/types/body.c index 09af8f77..a25d434a 100644 --- a/src/api/types/body.c +++ b/src/api/types/body.c @@ -60,6 +60,25 @@ int l_lovrBodySetLinearVelocity(lua_State* L) { return 0; } +int l_lovrBodyGetAngularVelocity(lua_State* L) { + Body* body = luax_checktype(L, 1, Body); + float x, y, z; + lovrBodyGetAngularVelocity(body, &x, &y, &z); + lua_pushnumber(L, x); + lua_pushnumber(L, y); + lua_pushnumber(L, z); + return 3; +} + +int l_lovrBodySetAngularVelocity(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); + lovrBodySetAngularVelocity(body, x, y, z); + return 0; +} + const luaL_Reg lovrBody[] = { { "getPosition", l_lovrBodyGetPosition }, { "setPosition", l_lovrBodySetPosition }, @@ -67,5 +86,7 @@ const luaL_Reg lovrBody[] = { { "setOrientation", l_lovrBodySetOrientation }, { "getLinearVelocity", l_lovrBodyGetLinearVelocity }, { "setLinearVelocity", l_lovrBodySetLinearVelocity }, + { "getAngularVelocity", l_lovrBodyGetAngularVelocity }, + { "setAngularVelocity", l_lovrBodySetAngularVelocity }, { NULL, NULL } }; diff --git a/src/physics/physics.c b/src/physics/physics.c index 5db61052..4d8b857a 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -129,3 +129,14 @@ void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z) { void lovrBodySetLinearVelocity(Body* body, float x, float y, float z) { dBodySetLinearVel(body->id, x, y, z); } + +void lovrBodyGetAngularVelocity(Body* body, float* x, float* y, float* z) { + const dReal* velocity = dBodyGetAngularVel(body->id); + *x = velocity[0]; + *y = velocity[1]; + *z = velocity[2]; +} + +void lovrBodySetAngularVelocity(Body* body, float x, float y, float z) { + dBodySetAngularVel(body->id, x, y, z); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 99a45518..4292a6f5 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -35,3 +35,5 @@ void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* 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); +void lovrBodyGetAngularVelocity(Body* body, float* x, float* y, float* z); +void lovrBodySetAngularVelocity(Body* body, float x, float y, float z);