Fixed quaternion interpolation when cosTheta is close to zero

This commit is contained in:
Christophe Riccio 2012-12-20 00:37:28 +01:00
parent ec05d43d7d
commit c19dda3797
2 changed files with 18 additions and 4 deletions

View File

@ -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")

View File

@ -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<T>())
{
return detail::tquat<T>(
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 <typename T>