From 73ec387545220aa8419b41037df61387967254e0 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 16 May 2017 12:48:01 -0600 Subject: [PATCH] Shape:getOrientation; Shape:setOrientation; --- src/api/types/shapes.c | 21 +++++++++++++++++++++ src/physics/physics.c | 17 ++++++++++++++--- src/physics/physics.h | 2 ++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/api/types/shapes.c b/src/api/types/shapes.c index cd6e88f5..4c3751bb 100644 --- a/src/api/types/shapes.c +++ b/src/api/types/shapes.c @@ -87,3 +87,24 @@ int l_lovrShapeSetPosition(lua_State* L) { lovrShapeSetPosition(shape, x, y, z); return 0; } + +int l_lovrShapeGetOrientation(lua_State* L) { + Shape* shape = luax_checktypeof(L, 1, Shape); + float angle, x, y, z; + lovrShapeGetOrientation(shape, &angle, &x, &y, &z); + lua_pushnumber(L, angle); + lua_pushnumber(L, x); + lua_pushnumber(L, y); + lua_pushnumber(L, z); + return 4; +} + +int l_lovrShapeSetOrientation(lua_State* L) { + Shape* shape = luax_checktypeof(L, 1, Shape); + float angle = luaL_checknumber(L, 1); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + lovrShapeSetOrientation(shape, angle, x, y, z); + return 0; +} diff --git a/src/physics/physics.c b/src/physics/physics.c index a7fc4dfc..8ff7bc0c 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -113,10 +113,9 @@ void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* } void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z) { - float axis[3] = { x, y, z }; float quaternion[4]; - quat_fromAngleAxis(quaternion, angle, axis); - dBodySetQuaternion(body->id, quaternion); + float axis[3] = { x, y, z }; + dBodySetQuaternion(body->id, quat_fromAngleAxis(quaternion, angle, axis)); } void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z) { @@ -314,3 +313,15 @@ void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z) { void lovrShapeSetPosition(Shape* shape, float x, float y, float z) { dGeomSetOffsetPosition(shape->id, x, y, z); } + +void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z) { + float quaternion[4]; + dGeomGetOffsetQuaternion(shape->id, quaternion); + quat_getAngleAxis(quaternion, angle, x, y, z); +} + +void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z) { + float quaternion[4]; + float axis[3] = { x, y, z }; + dGeomSetOffsetQuaternion(shape->id, quat_fromAngleAxis(quaternion, angle, axis)); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 46959d60..95d6bc64 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -84,3 +84,5 @@ void* lovrShapeGetUserData(Shape* shape); void lovrShapeSetUserData(Shape* shape, void* data); void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z); void lovrShapeSetPosition(Shape* shape, float x, float y, float z); +void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z); +void lovrShapeSetOrientation(Shape* shape, float angle, float x, float y, float z);