Fixed quaternion interpolation when cosTheta is close to zero
This commit is contained in:
@@ -22,12 +22,13 @@
|
|||||||
///
|
///
|
||||||
/// @ref gtc_quaternion
|
/// @ref gtc_quaternion
|
||||||
/// @file glm/gtc/quaternion.hpp
|
/// @file glm/gtc/quaternion.hpp
|
||||||
/// @date 2009-05-21 / 2011-06-05
|
/// @date 2009-05-21 / 2012-12-20
|
||||||
/// @author Christophe Riccio
|
/// @author Christophe Riccio
|
||||||
///
|
///
|
||||||
/// @see core (dependence)
|
/// @see core (dependence)
|
||||||
/// @see gtc_half_float (dependence)
|
/// @see gtc_half_float (dependence)
|
||||||
///
|
/// @see gtc_constants (dependence)
|
||||||
|
///
|
||||||
/// @defgroup gtc_quaternion GLM_GTC_quaternion
|
/// @defgroup gtc_quaternion GLM_GTC_quaternion
|
||||||
/// @ingroup gtc
|
/// @ingroup gtc
|
||||||
///
|
///
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
// Dependency:
|
// Dependency:
|
||||||
#include "../glm.hpp"
|
#include "../glm.hpp"
|
||||||
#include "../gtc/half_float.hpp"
|
#include "../gtc/half_float.hpp"
|
||||||
|
#include "../gtc/constants.hpp"
|
||||||
|
|
||||||
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
|
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
|
||||||
# pragma message("GLM: GLM_GTC_quaternion extension included")
|
# pragma message("GLM: GLM_GTC_quaternion extension included")
|
||||||
|
|||||||
@@ -451,8 +451,20 @@ namespace detail
|
|||||||
T const & a
|
T const & a
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
T angle = acos(dot(x, y));
|
T cosTheta = dot(x, y);
|
||||||
return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle);
|
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>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user