From c506b43d49ac212388c2749d14a8acada4482021 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 12 Jun 2014 00:29:56 +0200 Subject: [PATCH] Quaternion vector rotation error. #209 --- glm/gtc/quaternion.inl | 8 ++++---- test/gtc/gtc_quaternion.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 9e926ee9..6396ea2e 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -302,11 +302,11 @@ namespace detail detail::tvec3 const & v ) { - detail::tvec3 u(q.x, q.y, q.z); - detail::tvec3 uv(glm::cross(u, v) * q.w); - detail::tvec3 uuv(glm::cross(u, uv)); + detail::tvec3 const QuatVector(q.x, q.y, q.z); + detail::tvec3 const uv(glm::cross(QuatVector, v)); + detail::tvec3 const uuv(glm::cross(QuatVector, uv)); - return v + (uv + uuv) * static_cast(2); + return v + ((uv * q.w) + uuv) * static_cast(2); } template diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 4346e8fc..f56ad47e 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -247,6 +247,16 @@ int test_quat_type() return 0; } +int test_quat_mul_vec() +{ + glm::quat q = glm::angleAxis(glm::pi() * 0.5f, glm::vec3(0, 0, 1)); + glm::vec3 v(1, 0, 0); + glm::vec3 u(q * v); + glm::vec3 w(u * q); + + return glm::all(glm::epsilonEqual(v, w, 0.01f)); +} + int test_quat_ctr() { int Error(0); @@ -269,6 +279,7 @@ int main() int Error(0); Error += test_quat_ctr(); + Error += test_quat_mul_vec(); Error += test_quat_two_axis_ctr(); Error += test_quat_mul(); Error += test_quat_precision();