Browse Source

Merge pull request #1038 from EZForever/patch-angle

fix: glm::angle() discards the sign of result for angles in range (2*pi-1, 2*pi) #1038
Christophe 5 years ago
parent
commit
f52f232f59
2 changed files with 10 additions and 1 deletions
  1. 4 1
      glm/ext/quaternion_trigonometric.inl
  2. 6 0
      test/ext/ext_quaternion_trigonometric.cpp

+ 4 - 1
glm/ext/quaternion_trigonometric.inl

@@ -7,7 +7,10 @@ namespace glm
 	{
 		if (abs(x.w) > cos_one_over_two<T>())
 		{
-			return asin(sqrt(x.x * x.x + x.y * x.y + x.z * x.z)) * static_cast<T>(2);
+			T const a = asin(sqrt(x.x * x.x + x.y * x.y + x.z * x.z)) * static_cast<T>(2);
+			if(x.w < static_cast<T>(0))
+				return pi<T>() * static_cast<T>(2) - a;
+			return a;
 		}
 
 		return acos(x.w) * static_cast<T>(2);

+ 6 - 0
test/ext/ext_quaternion_trigonometric.cpp

@@ -21,6 +21,12 @@ static int test_angle()
 		Error += glm::equal(A, 90.0f, Epsilon) ? 0 : 1;
 	}
 
+	{
+		glm::quat const Q = glm::angleAxis(glm::two_pi<float>() - 1.0f, glm::vec3(1, 0, 0));
+		float const A = glm::angle(Q);
+		Error += glm::equal(A, 1.0f, Epsilon) ? 1 : 0;
+	}
+
 	return Error;
 }