Add quat_identity;

This commit is contained in:
bjorn 2021-04-03 18:38:23 -06:00
parent 609d7e05ce
commit 2b94bcb46e
2 changed files with 6 additions and 2 deletions

View File

@ -87,7 +87,7 @@ int luax_readquat(lua_State* L, int index, quat q, const char* expected) {
switch (lua_type(L, index)) {
case LUA_TNIL:
case LUA_TNONE:
quat_set(q, 0.f, 0.f, 0.f, 1.f);
quat_identity(q);
return ++index;
case LUA_TNUMBER:
angle = luax_optfloat(L, index++, 0.f);
@ -1245,7 +1245,7 @@ static int l_lovrQuatUnpack(lua_State* L) {
int l_lovrQuatSet(lua_State* L) {
quat q = luax_checkvector(L, 1, V_QUAT, NULL);
if (lua_isnoneornil(L, 2)) {
quat_set(q, 0.f, 0.f, 0.f, 1.f);
quat_identity(q);
} else if (lua_type(L, 2) == LUA_TNUMBER) {
float x = lua_tonumber(L, 2);
float y = luax_checkfloat(L, 3);

View File

@ -161,6 +161,10 @@ MAF quat quat_fromMat4(quat q, mat4 m) {
return quat_set(q, x, y, z, w);
}
MAF quat quat_identity(quat q) {
return quat_set(q, 0.f, 0.f, 0.f, 1.f);
}
MAF quat quat_mul(quat out, quat q, quat r) {
return quat_set(out,
q[0] * r[3] + q[3] * r[0] + q[1] * r[2] - q[2] * r[1],