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
This commit is contained in:
Christophe 2020-11-21 22:06:08 +01:00 committed by GitHub
commit f52f232f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}