qt6-bb10/src/gui/math3d
Yuya Nishihara 6ffc8d8eb6 QtGui/math3d: Fix QQuaternion::getEulerAngles for GimbalLock cases
This is heavily inspired by the patch written by Inho Lee
<inho.lee@qt.io>, which says "There is a precision problem in the
previous algorithm when checking pitch value. (In the case that the
rotation on the X-axis makes Gimbal lock.)"

In order to work around the precision problem, this patch does:

 1. switch to the algorithm described in the inline comment to make
    the story simple.
 2. forcibly normalize the {x, y, z, w} components to eliminate
    fractional errors.
 3. set threshold to avoid hidden division by cos(pitch) =~ 0.

From my testing which compares dot product of the original quaternion
and the one recreated from Euler angles, calculation within float range
seems okay. (abs(normalize(q_orig) * normalize(q_roundtrip)) >= 0.99999)

Many thanks to Inho Lee for the original patch and discussion about
rounding errors.

Fixes: QTBUG-72103
Pick-to: 6.3 6.2 5.15
Change-Id: I8995e4affe603111ff2303a0dfcbdb0b1ae03f10
Reviewed-by: Yuya Nishihara <yuya@tcha.org>
Reviewed-by: Inho Lee <inho.lee@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-01-16 01:12:15 +01:00
..
qgenericmatrix.cpp Doc: Fix documentation warnings for Qt GUI 2020-11-19 12:28:45 +01:00
qgenericmatrix.h Purge Q_NO_TEMPLATE_FRIENDS and platforms lacking support for them 2021-10-02 12:47:43 +02:00
qmatrix4x4.cpp gui: Fix typos in documentation 2021-10-12 12:52:02 +02:00
qmatrix4x4.h tst_QMatrixNxN: fix type-punning warning 2021-06-30 23:13:28 +02:00
qquaternion.cpp QtGui/math3d: Fix QQuaternion::getEulerAngles for GimbalLock cases 2022-01-16 01:12:15 +01:00
qquaternion.h QQuaternion: mark as PRIMITIVE type 2021-03-05 11:19:44 +01:00
qvector2d.h Clean up QVector2D/3D/4D 2020-11-19 12:28:45 +01:00
qvector3d.h Clean up QVector2D/3D/4D 2020-11-19 12:28:45 +01:00
qvector4d.h Clean up QVector2D/3D/4D 2020-11-19 12:28:45 +01:00
qvectornd.cpp Clean up documentation in QVector[234]D 2021-02-05 15:40:01 +01:00
qvectornd.h Add more support for structured bindings 2021-02-25 16:08:44 +01:00