Bläddra i källkod

Fixed quaternion interpolation when cosTheta is close to zero

Christophe Riccio 13 år sedan
förälder
incheckning
c19dda3797
2 ändrade filer med 18 tillägg och 4 borttagningar
  1. 4 2
      glm/gtc/quaternion.hpp
  2. 14 2
      glm/gtc/quaternion.inl

+ 4 - 2
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")

+ 14 - 2
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<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>