summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorInho Lee <inho.lee@qt.io>2021-05-10 15:32:26 +0200
committerInho Lee <inho.lee@qt.io>2021-06-01 09:01:23 +0200
commit7ea2fbddcf674d49ad7d219cdb8a4b760258360c (patch)
treef04ddf0e3f284726e13e7f448b765887b5fef014 /src/gui/math3d
parent4f853744c9a88d986b46fc80d62200c82eb048b2 (diff)
QtGui/math3d : Fix QQuaternion::getEulerAngles
When rotating M_PI_2 based on x-axis, quaternion to euler conversion makes NaN for the x-rotation value. This patch fixes this corner case. Fixes: QTBUG-93600 Pick-to: 6.1 6.0 5.15 Change-Id: Ice321a80ad90dba9cf3ee3a14ec7d3d047c21bd3 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/math3d')
-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 48e12f12fe..ba82aaa737 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -511,7 +511,11 @@ void QQuaternion::getEulerAngles(float *pitch, float *yaw, float *roll) const
const float zz = zps * zps;
const float zw = zps * wps;
- *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));