diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index c70b1cde..0875efe9 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -148,7 +148,7 @@ namespace glm detail::tquat const & q1, detail::tquat const & q2); - //! Returns a LERP interpolated quaternion of x and y according a. + //! Returns a SLERP interpolated quaternion of x and y according a. //! From GLM_GTC_quaternion extension. template detail::tquat mix( diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index a445c182..32577b77 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -369,6 +369,43 @@ namespace quaternion{ k0 * x.z + k1 * y2.z); } + template + inline detail::tquat mix2 + ( + detail::tquat const & x, + detail::tquat const & y, + T const & a + ) + { + bool flip = false; + if(a <= T(0)) return x; + if(a >= T(1)) return y; + + T cos_t = dot(x, y); + if(cos_t < T(0)) + { + cos_t = -cos_t; + flip = true; + } + + T alpha(0), beta(0); + + if(T(1) - cos_t < 1e-7) + beta = T(1) - alpha; + else + { + T theta = acos(cos_t); + T sin_t = sin(theta); + beta = sin(theta * (T(1) - alpha)) / sin_t; + alpha = sin(alpha * theta) / sin_t; + } + + if(flip) + alpha = -alpha; + + return normalize(beta * x + alpha * y2); + } + template inline detail::tquat conjugate (