quat:direction returns vec3;

This commit is contained in:
bjorn 2019-08-19 14:19:10 -07:00
parent 97e90a8699
commit b1b97ddb02
2 changed files with 7 additions and 10 deletions

View File

@ -1301,12 +1301,9 @@ static int l_lovrQuatNormalize(lua_State* L) {
static int l_lovrQuatDirection(lua_State* L) { static int l_lovrQuatDirection(lua_State* L) {
quat q = luax_checkvector(L, 1, V_QUAT, NULL); quat q = luax_checkvector(L, 1, V_QUAT, NULL);
float x, y, z; vec3 v = luax_newtempvector(L, V_VEC3);
quat_getDirection(q, &x, &y, &z); quat_getDirection(q, v);
lua_pushnumber(L, x); return 1;
lua_pushnumber(L, y);
lua_pushnumber(L, z);
return 3;
} }
static int l_lovrQuatConjugate(lua_State* L) { static int l_lovrQuatConjugate(lua_State* L) {

View File

@ -184,10 +184,10 @@ MAF quat quat_normalize(quat q) {
return q; return q;
} }
MAF void quat_getDirection(quat q, float* x, float* y, float* z) { MAF void quat_getDirection(quat q, vec3 v) {
*x = -2.f * q[0] * q[2] - 2.f * q[3] * q[1]; v[0] = -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]; v[1] = -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]; v[2] = -1.f + 2.f * q[0] * q[0] + 2.f * q[1] * q[1];
} }
MAF quat quat_conjugate(quat q) { MAF quat quat_conjugate(quat q) {