summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.cpp
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2022-08-16 20:37:09 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2022-08-16 20:37:09 +0300
commitb7d91087099e4b69d70c0271fbeae19368d485d4 (patch)
treef46b62227cfeccf32b72f6aeb45c17cc7a933505 /src/gui/math3d/qquaternion.cpp
parent231d3670981a33ec42b91ad1cb33c1fc50551066 (diff)
parentbbfbb18df18658e8ceec4bc04bd2cdf59f6a35ed (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.6' into tqtc/lts-5.15-opensource
Diffstat (limited to 'src/gui/math3d/qquaternion.cpp')
-rw-r--r--src/gui/math3d/qquaternion.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index 5f15949c5b..67f013c82e 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -534,7 +534,11 @@ void QQuaternion::getEulerAngles(float *pitch, float *yaw, float *roll) const
zw /= lengthSquared;
}
- *pitch = std::asin(-2.0f * (yz - xw));
+ const float sinp = -2.0f * (yz - xw);
+ if (std::abs(sinp) >= 1.0f)
+ *pitch = std::copysign(M_PI_2, sinp);
+ else
+ *pitch = std::asin(sinp);
if (*pitch < M_PI_2) {
if (*pitch > -M_PI_2) {
*yaw = std::atan2(2.0f * (xz + yw), 1.0f - 2.0f * (xx + yy));