From c9b7b712fb39eb8e99e3ac99ea08f289e36c1ba9 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 27 May 2011 16:34:20 +0100 Subject: [PATCH] Fixed angle implementation --- glm/gtx/quaternion.inl | 2 +- test/gtc/gtc_quaternion.cpp | 9 +++++---- test/gtx/gtx_quaternion.cpp | 30 ++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index aaf07171..ec713c8d 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -149,7 +149,7 @@ namespace quaternion detail::tquat const & x ) { - return acos(x.w) * T(2); + return glm::degrees(acos(x.w) * T(2)); } template diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 00ed0503..7bd07c07 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -23,11 +23,12 @@ int test_quat_slerp() { int Error = 0; - glm::quat A(0.0f, glm::vec3(0, 0, 1)); - glm::quat B(90.0f, glm::vec3(0, 0, 1)); + glm::quat A(glm::vec3(0, 0, 1)); + glm::quat B(glm::vec3(0, 1, 0)); glm::quat C = glm::mix(A, B, 0.5f); - - Error += C == glm::quat(45.f, glm::vec3(0, 0, 1)) ? 0 : 1; + glm::quat D(glm::normalize(glm::vec3(0, 1, 1))); + + Error += C == D ? 0 : 1; return Error; } diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 241f572c..c498a0fb 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -11,31 +11,48 @@ #include #include +int test_quat_angleAxis() +{ + int Error = 0; + + glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1)); + glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1)); + glm::quat C = glm::mix(A, B, 0.5f); + glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); + + Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1; + + return Error; +} + int test_quat_angle() { int Error = 0; { - glm::quat Q(45.0f, glm::vec3(0, 0, 1)); + glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); glm::quat N = glm::normalize(Q); float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; + Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1; float A = glm::angle(N); Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1; } { - glm::quat Q(45.0f, glm::vec3(0, 0, 2)); + glm::quat Q = glm::angleAxis(45.0f, glm::normalize(glm::vec3(0, 1, 1))); glm::quat N = glm::normalize(Q); float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; + Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1; float A = glm::angle(N); Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1; } { - glm::quat Q(45.0f, glm::vec3(1, 2, 3)); + glm::quat Q = glm::angleAxis(45.0f, glm::normalize(glm::vec3(1, 2, 3))); glm::quat N = glm::normalize(Q); float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; + Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1; float A = glm::angle(N); Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1; } @@ -48,6 +65,7 @@ int main() int Error = 0; Error += test_quat_angle(); + Error += test_quat_angleAxis(); return Error; }