From e610e9446e6207390548c1a7e63f2caebec55cc7 Mon Sep 17 00:00:00 2001 From: Joel Nises Date: Thu, 5 Jun 2014 17:48:53 +0200 Subject: [PATCH] fixed bug in quaternion slerp --- glm/gtc/quaternion.inl | 8 ++++---- test/gtc/gtc_quaternion.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 9e926ee9..4059d426 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -582,10 +582,10 @@ namespace detail { // Linear interpolation return detail::tquat( - mix(x.w, y.w, a), - mix(x.x, y.x, a), - mix(x.y, y.y, a), - mix(x.z, y.z, a)); + mix(x.w, z.w, a), + mix(x.x, z.x, a), + mix(x.y, z.y, a), + mix(x.z, z.z, a)); } else { diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 4346e8fc..5e5b120a 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -196,6 +196,15 @@ int test_quat_slerp() // Must be 0 0.00X 0 0.99999 glm::quat almostid = glm::slerp(id, glm::angleAxis(0.1f, glm::vec3(0.0f, 1.0f, 0.0f)), 0.5f); + // Testing quaternions with opposite sign + { + glm::quat a(-1, 0, 0, 0); + + glm::quat result = glm::slerp(a, id, 0.5f); + + Error += glm::epsilonEqual(glm::pow(glm::dot(id, result), 2.f), 1.f, 0.01f) ? 0 : 1; + } + return Error; }