summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d/qquaternion.cpp')
-rw-r--r--src/gui/math3d/qquaternion.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index 93e396c5a1..2f12accc41 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -495,8 +495,9 @@ void QQuaternion::getEulerAngles(float *pitch, float *yaw, float *roll) const
// https://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf
// "A tutorial on SE(3) transformation parameterizations and on-manifold optimization".
- // Normalize values even if the length is below the margin. Otherwise we might fail
- // to detect Gimbal lock due to cumulative errors.
+ // We can only detect Gimbal lock when we normalize, which we can't do when
+ // length is nearly zero. Do so before multiplying co-ordinates, to avoid
+ // underflow.
const float len = length();
const bool rescale = !qFuzzyIsNull(len);
const float xps = rescale ? xp / len : xp;