Browse Source

Merge branch 'master' of https://github.com/g-truc/glm

Christophe Riccio 9 years ago
parent
commit
9f1aae08f7
1 changed files with 7 additions and 1 deletions
  1. 7 1
      glm/gtc/quaternion.inl

+ 7 - 1
glm/gtc/quaternion.inl

@@ -574,7 +574,13 @@ namespace detail
 	template<typename T, precision P>
 	GLM_FUNC_QUALIFIER T pitch(tquat<T, P> const & q)
 	{
-		return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
+		//return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
+		const T y = T(2) * (q.y * q.z + q.w * q.x);
+		const T x = q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z;
+        	if(y == T(0) && x == T(0)) //avoid atan2(0,0) - handle singularity - Matiis
+            		return T(T(2)*atan(q.x,q.w));
+		
+		return T(atan(y,x));
 	}
 
 	template<typename T, precision P>