From 9e907d6dec213271deed0307e21159dc7ea5cf59 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 16 May 2017 23:11:53 -0600 Subject: [PATCH] Orientation fixes; --- src/api/types/body.c | 2 +- src/physics/physics.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api/types/body.c b/src/api/types/body.c index fd42b942..e3d71ead 100644 --- a/src/api/types/body.c +++ b/src/api/types/body.c @@ -28,7 +28,7 @@ int l_lovrBodyGetOrientation(lua_State* L) { lua_pushnumber(L, x); lua_pushnumber(L, y); lua_pushnumber(L, z); - return 3; + return 4; } int l_lovrBodySetOrientation(lua_State* L) { diff --git a/src/physics/physics.c b/src/physics/physics.c index 1a0fbeb8..61775e85 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -108,14 +108,16 @@ void lovrBodySetPosition(Body* body, float x, float y, float z) { void lovrBodyGetOrientation(Body* body, float* angle, float* x, float* y, float* z) { const dReal* q = dBodyGetQuaternion(body->id); - float quaternion[4] = { q[0], q[1], q[2], q[3] }; + float quaternion[4] = { q[1], q[2], q[3], q[0] }; quat_getAngleAxis(quaternion, angle, x, y, z); } void lovrBodySetOrientation(Body* body, float angle, float x, float y, float z) { float quaternion[4]; float axis[3] = { x, y, z }; - dBodySetQuaternion(body->id, quat_fromAngleAxis(quaternion, angle, axis)); + quat_fromAngleAxis(quaternion, angle, axis); + float q[4] = { quaternion[3], quaternion[0], quaternion[1], quaternion[2] }; + dBodySetQuaternion(body->id, q); } void lovrBodyGetLinearVelocity(Body* body, float* x, float* y, float* z) { @@ -354,15 +356,18 @@ void lovrShapeSetPosition(Shape* shape, float x, float y, float z) { } void lovrShapeGetOrientation(Shape* shape, float* angle, float* x, float* y, float* z) { - float quaternion[4]; - dGeomGetOffsetQuaternion(shape->id, quaternion); + dReal q[4]; + dGeomGetOffsetQuaternion(shape->id, q); + float quaternion[4] = { q[1], q[2], q[3], q[0] }; 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)); + quat_fromAngleAxis(quaternion, angle, axis); + float q[4] = { quaternion[3], quaternion[0], quaternion[1], quaternion[2] }; + dGeomSetOffsetQuaternion(shape->id, q); } uint32_t lovrShapeGetCategory(Shape* shape) {