diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 44acbebc..5d900739 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -22,12 +22,13 @@ /// /// @ref gtc_quaternion /// @file glm/gtc/quaternion.hpp -/// @date 2009-05-21 / 2011-06-05 +/// @date 2009-05-21 / 2012-12-20 /// @author Christophe Riccio /// /// @see core (dependence) /// @see gtc_half_float (dependence) -/// +/// @see gtc_constants (dependence) +/// /// @defgroup gtc_quaternion GLM_GTC_quaternion /// @ingroup gtc /// @@ -42,6 +43,7 @@ // Dependency: #include "../glm.hpp" #include "../gtc/half_float.hpp" +#include "../gtc/constants.hpp" #if(defined(GLM_MESSAGES) && !defined(glm_ext)) # pragma message("GLM: GLM_GTC_quaternion extension included") diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 100c26f3..a2469082 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -451,8 +451,20 @@ namespace detail T const & a ) { - T angle = acos(dot(x, y)); - return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle); + T cosTheta = dot(x, y); + if(cosTheta <= epsilon()) + { + return detail::tquat( + mix(x.x, y.x, a), + mix(x.y, y.y, a), + mix(x.z, y.z, a), + mix(x.w, y.w, a)); + } + else + { + T angle = acos(cosTheta); + return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle); + } } template