mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 04:31:47 +00:00
Fixed quaternion interpolation when cosTheta is close to zero
This commit is contained in:
parent
ec05d43d7d
commit
c19dda3797
@ -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")
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user