From b1b97ddb02e34b0ef9f1a0b4278dadd3979bcde2 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 19 Aug 2019 14:19:10 -0700 Subject: [PATCH] quat:direction returns vec3; --- src/api/l_vectors.c | 9 +++------ src/core/maf.h | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/api/l_vectors.c b/src/api/l_vectors.c index 07b75c38..e34df050 100644 --- a/src/api/l_vectors.c +++ b/src/api/l_vectors.c @@ -1301,12 +1301,9 @@ static int l_lovrQuatNormalize(lua_State* L) { static int l_lovrQuatDirection(lua_State* L) { quat q = luax_checkvector(L, 1, V_QUAT, NULL); - float x, y, z; - quat_getDirection(q, &x, &y, &z); - lua_pushnumber(L, x); - lua_pushnumber(L, y); - lua_pushnumber(L, z); - return 3; + vec3 v = luax_newtempvector(L, V_VEC3); + quat_getDirection(q, v); + return 1; } static int l_lovrQuatConjugate(lua_State* L) { diff --git a/src/core/maf.h b/src/core/maf.h index 52264164..13386fa9 100644 --- a/src/core/maf.h +++ b/src/core/maf.h @@ -184,10 +184,10 @@ MAF quat quat_normalize(quat q) { return q; } -MAF void quat_getDirection(quat q, float* x, float* y, float* z) { - *x = -2.f * q[0] * q[2] - 2.f * q[3] * q[1]; - *y = -2.f * q[1] * q[2] + 2.f * q[3] * q[0]; - *z = -1.f + 2.f * q[0] * q[0] + 2.f * q[1] * q[1]; +MAF void quat_getDirection(quat q, vec3 v) { + v[0] = -2.f * q[0] * q[2] - 2.f * q[3] * q[1]; + v[1] = -2.f * q[1] * q[2] + 2.f * q[3] * q[0]; + v[2] = -1.f + 2.f * q[0] * q[0] + 2.f * q[1] * q[1]; } MAF quat quat_conjugate(quat q) {