Switch to fromEulerAngles() to fromAxisAndAngle() for rotations

... because Euler angles are horrible and everyone should be using quaternions :-)

We also do not need the workaround for clamping of pitch angle anymore...
This commit is contained in:
Martin Dobias 2024-12-15 21:36:06 +01:00
parent 4c654c88fd
commit 63bd42d87d
2 changed files with 2 additions and 11 deletions

View File

@ -988,7 +988,6 @@ int Qgs3DUtils::openGlMaxClipPlanes( QSurface *surface )
QQuaternion Qgs3DUtils::rotationFromPitchHeadingAngles( float pitchAngle, float headingAngle )
{
// we use two separate fromEulerAngles() calls because one would not do rotations in order we need
return QQuaternion::fromEulerAngles( 0, 0, headingAngle ) *
QQuaternion::fromEulerAngles( pitchAngle, 0, 0 );
return QQuaternion::fromAxisAndAngle( QVector3D( 0, 0, 1 ), headingAngle ) *
QQuaternion::fromAxisAndAngle( QVector3D( 1, 0, 0 ), pitchAngle );
}

View File

@ -62,15 +62,7 @@ void QgsCameraPose::setDistanceFromCenterPoint( float distance )
void QgsCameraPose::setPitchAngle( float pitch )
{
// prevent going over the head
// prevent bug in QgsCameraPose::updateCamera when updating camera rotation.
// With a mPitchAngle < 0.2 or > 179.8, QQuaternion::fromEulerAngles( mPitchAngle, mHeadingAngle, 0 )
// will return bad rotation angle in Qt5.
// See https://bugreports.qt.io/browse/QTBUG-72103
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
mPitchAngle = std::clamp( pitch, 0.2f, 179.8f );
#else
mPitchAngle = std::clamp( pitch, 0.0f, 180.0f );
#endif
}
void QgsCameraPose::updateCamera( Qt3DRender::QCamera *camera )