Skip to content

Commit 09baadb

Browse files
committedJun 6, 2019
Add behaviour for tilt up/down and rotate view.
1 parent a968cf9 commit 09baadb

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed
 

‎src/3d/qgscameracontroller.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,8 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
414414
else if ( hasShift && !hasCtrl )
415415
{
416416
// rotate/tilt using keyboard (camera moves as it rotates around its view center)
417-
float pitch = mCameraPose.pitchAngle();
418-
float yaw = mCameraPose.headingAngle();
419-
pitch -= ty; // down key = moving camera toward terrain
420-
yaw -= tx; // right key = moving camera clockwise
421-
mCameraPose.setPitchAngle( pitch );
422-
mCameraPose.setHeadingAngle( yaw );
423-
updateCameraFromPose();
417+
tiltUpAroundViewCenter(ty);
418+
rotateAroundViewCenter(tx);
424419
}
425420
else if ( hasCtrl && !hasShift )
426421
{
@@ -450,3 +445,26 @@ void QgsCameraController::onPickerMousePressed( Qt3DRender::QPickEvent *pick )
450445
{
451446
mLastPressedHeight = pick->worldIntersection().y();
452447
}
448+
449+
void QgsCameraController::tiltUpAroundViewCenter(float deltaPitch){
450+
// Tilt up the view by deltaPitch around the view center (camera moves)
451+
float pitch = mCameraPose.pitchAngle();
452+
pitch -= deltaPitch; // down key = moving camera toward terrain
453+
mCameraPose.setPitchAngle( pitch );
454+
updateCameraFromPose();
455+
}
456+
457+
void QgsCameraController::rotateAroundViewCenter(float deltaYaw){
458+
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
459+
float yaw = mCameraPose.headingAngle();
460+
yaw -= deltaYaw; // right key = moving camera clockwise
461+
mCameraPose.setHeadingAngle( yaw );
462+
updateCameraFromPose();
463+
qInfo() << "Delta yaw: " << deltaYaw;
464+
qInfo() << "Yaw: " << yaw;
465+
}
466+
467+
void QgsCameraController::setCameraHeadingAngle(float angle){
468+
mCameraPose.setHeadingAngle( angle );
469+
updateCameraFromPose();
470+
}

‎src/3d/qgscameracontroller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
136136
void readXml( const QDomElement &elem );
137137

138138
void zoom(float factor);
139+
void tiltUpAroundViewCenter(float deltaPitch);
140+
void rotateAroundViewCenter(float deltaYaw);
141+
void setCameraHeadingAngle(float angle);
139142

140143
private:
141144
void rotateCamera( float diffPitch, float diffYaw );

‎src/app/3d/qgs3dnavigationwidget.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <QPushButton>
33
#include <QDial>
44
#include <QObject>
5+
#include <QDebug>
56

67
#include "qgs3dnavigationwidget.h"
78
#include "qgscameracontroller.h"
@@ -44,18 +45,47 @@ Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(p
4445
mTiltUpButton->setToolTip(QStringLiteral("Tilt Up"));
4546
mTiltUpButton->setAutoRepeat(true);
4647

48+
QObject::connect(
49+
mTiltUpButton,
50+
&QPushButton::clicked,
51+
parent,
52+
[ = ]{
53+
parent->cameraController()->tiltUpAroundViewCenter(1);
54+
}
55+
);
56+
4757
// Tilt down button
4858
mTiltDownButton = new QPushButton(this);
4959
mTiltDownButton ->setText(QString::fromUtf8("\u25BD"));
5060
mTiltDownButton->setToolTip(QStringLiteral("Tilt Down"));
5161
mTiltDownButton->setAutoRepeat(true);
5262

63+
QObject::connect(
64+
mTiltDownButton,
65+
&QPushButton::clicked,
66+
parent,
67+
[ = ]{
68+
parent->cameraController()->tiltUpAroundViewCenter(-1);
69+
}
70+
);
71+
5372
// Rotate scene dial
5473
mRotateSceneDial = new QDial(this);
74+
mRotateSceneDial->setToolTip(QStringLiteral("Rotate view"));
5575
mRotateSceneDial->setWrapping(true);
5676
mRotateSceneDial->setMaximum(359);
5777
mRotateSceneDial->setValue(180);
5878

79+
QObject::connect(
80+
mRotateSceneDial,
81+
&QDial::valueChanged,
82+
parent,
83+
[ = ]{
84+
qInfo() << "Dial value: " << mRotateSceneDial->value();
85+
parent->cameraController()->setCameraHeadingAngle(mRotateSceneDial->value());
86+
}
87+
);
88+
5989
QGridLayout *gridLayout = new QGridLayout(this);
6090
gridLayout->addWidget(mTiltUpButton, 0, 0);
6191
gridLayout->addWidget(mTiltDownButton, 3, 0);

0 commit comments

Comments
 (0)
Please sign in to comment.