quat: fix quaternion inverse and tests about it

* multiplication quaternion and its inverse must be identity
This commit is contained in:
Recep Aslantas
2018-04-11 16:50:37 +03:00
parent 462067cfdc
commit 2d77123999
2 changed files with 12 additions and 1 deletions

View File

@@ -259,7 +259,7 @@ void
glm_quat_inv(versor q, versor dest) {
versor conj;
glm_quat_conjugate(q, conj);
glm_vec_scale(conj, glm_vec4_norm2(q), dest);
glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest);
}
/*!

View File

@@ -26,6 +26,8 @@ test_quat(void **state) {
/* 0. test identiy quat */
glm_quat_identity(q4);
assert_true(glm_quat_real(q4) == cosf(glm_rad(0.0f) * 0.5f));
glm_quat_mat4(q4, rot1);
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
/* 1. test quat to mat and mat to quat */
for (i = 0; i < 1000; i++) {
@@ -184,5 +186,14 @@ test_quat(void **state) {
/* result must be identity */
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
test_rand_quat(q3);
/* 12. inverse of quat, multiplication must be IDENTITY */
glm_quat_inv(q3, q4);
glm_quat_mul(q3, q4, q5);
glm_quat_identity(q3);
test_assert_quat_eq(q3, q5);
/* TODO: add tests for slerp, lerp */
}