Merge pull request #1022 from qsantos/fix-small-angle-quaternion-zero-test

Fix handling of small magnitude quaternions #1022
This commit is contained in:
Christophe 2020-08-30 14:56:02 +02:00 committed by GitHub
commit b3f8772026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,7 +56,11 @@ namespace glm
//Prevent a division by 0 error later on //Prevent a division by 0 error later on
T VectorMagnitude = x.x * x.x + x.y * x.y + x.z * x.z; T VectorMagnitude = x.x * x.x + x.y * x.y + x.z * x.z;
if (glm::abs(VectorMagnitude - static_cast<T>(0)) < glm::epsilon<T>()) { //Despite the compiler might say, we actually want to compare
//VectorMagnitude to 0. here; we could use denorm_int() compiling a
//project with unsafe maths optimizations might make the comparison
//always false, even when VectorMagnitude is 0.
if (VectorMagnitude < std::numeric_limits<T>::min()) {
//Equivalent to raising a real number to a power //Equivalent to raising a real number to a power
return qua<T, Q>(pow(x.w, y), 0, 0, 0); return qua<T, Q>(pow(x.w, y), 0, 0, 0);
} }