Skip to content

Commit

Permalink
qgscamerapose: Fix pitch initial value to avoid rotation computation …
Browse files Browse the repository at this point in the history
…error

This is a follow up from commit
b173af9.

This prevents a bug in QgsCameraPose::updateCamera when updating
camera rotation.
Indeed, with a mPitchAngle < 0.2, QQuaternion::fromEulerAngles(
mPitchAngle, mHeadingAngle, 0 ) will return bad rotation angle.

This is fixed is Qt6, but it has not been backported to Qt5.
See: https://bugreports.qt.io/browse/QTBUG-72103

This change is mostly useful when the `setViewFromTop` method is
called because it uses the default QgsCameraPose constructor and
therefore, the initial pitch angle is used.

The different associated tests need to be updated to take into account
this change.
  • Loading branch information
ptitjano authored and nyalldawson committed Jan 9, 2023
1 parent 2e76c14 commit bdf524b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/3d/qgscamerapose.h
Expand Up @@ -94,7 +94,16 @@ class _3D_EXPORT QgsCameraPose
//! distance of camera from the point it is looking at
float mDistanceFromCenterPoint = 1000;
//! aircraft nose up/down (0 = looking straight down to the plane). angle in degrees
float mPitchAngle = 0;
// 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.
// See https://bugreports.qt.io/browse/QTBUG-72103
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
float mPitchAngle = 0.2f;
#else
float mPitchAngle = 0.0f;
#endif

//! aircraft nose left/right. angle in degrees
float mHeadingAngle = 0;
};
Expand Down
7 changes: 6 additions & 1 deletion tests/src/3d/testqgslayout3dmap.cpp
Expand Up @@ -110,7 +110,12 @@ void TestQgsLayout3DMap::testBasic()
map3dItem->setMapSettings( map );
l.addLayoutItem( map3dItem );

QgsLayoutChecker checker( QStringLiteral( "composer3d_basic" ), &l );
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QgsLayoutChecker checker( QStringLiteral( "composer3d_basic_qt5" ), &l );
#else
QgsLayoutChecker checker( QStringLiteral( "composer3d_basic_qt6" ), &l );
#endif

checker.setControlPathPrefix( QStringLiteral( "composer_3d" ) );
const bool result = checker.testLayout( mReport, 0, 100 );
QVERIFY( result );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bdf524b

Please sign in to comment.