Navigation Menu

Skip to content

Commit

Permalink
Add behaviour for tilt up/down and rotate view.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Jun 6, 2019
1 parent a968cf9 commit 09baadb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -414,13 +414,8 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
else if ( hasShift && !hasCtrl )
{
// rotate/tilt using keyboard (camera moves as it rotates around its view center)
float pitch = mCameraPose.pitchAngle();
float yaw = mCameraPose.headingAngle();
pitch -= ty; // down key = moving camera toward terrain
yaw -= tx; // right key = moving camera clockwise
mCameraPose.setPitchAngle( pitch );
mCameraPose.setHeadingAngle( yaw );
updateCameraFromPose();
tiltUpAroundViewCenter(ty);
rotateAroundViewCenter(tx);
}
else if ( hasCtrl && !hasShift )
{
Expand Down Expand Up @@ -450,3 +445,26 @@ void QgsCameraController::onPickerMousePressed( Qt3DRender::QPickEvent *pick )
{
mLastPressedHeight = pick->worldIntersection().y();
}

void QgsCameraController::tiltUpAroundViewCenter(float deltaPitch){
// Tilt up the view by deltaPitch around the view center (camera moves)
float pitch = mCameraPose.pitchAngle();
pitch -= deltaPitch; // down key = moving camera toward terrain
mCameraPose.setPitchAngle( pitch );
updateCameraFromPose();
}

void QgsCameraController::rotateAroundViewCenter(float deltaYaw){
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
float yaw = mCameraPose.headingAngle();
yaw -= deltaYaw; // right key = moving camera clockwise
mCameraPose.setHeadingAngle( yaw );
updateCameraFromPose();
qInfo() << "Delta yaw: " << deltaYaw;
qInfo() << "Yaw: " << yaw;
}

void QgsCameraController::setCameraHeadingAngle(float angle){
mCameraPose.setHeadingAngle( angle );
updateCameraFromPose();
}
3 changes: 3 additions & 0 deletions src/3d/qgscameracontroller.h
Expand Up @@ -136,6 +136,9 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
void readXml( const QDomElement &elem );

void zoom(float factor);
void tiltUpAroundViewCenter(float deltaPitch);
void rotateAroundViewCenter(float deltaYaw);
void setCameraHeadingAngle(float angle);

private:
void rotateCamera( float diffPitch, float diffYaw );
Expand Down
30 changes: 30 additions & 0 deletions src/app/3d/qgs3dnavigationwidget.cpp
Expand Up @@ -2,6 +2,7 @@
#include <QPushButton>
#include <QDial>
#include <QObject>
#include <QDebug>

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

QObject::connect(
mTiltUpButton,
&QPushButton::clicked,
parent,
[ = ]{
parent->cameraController()->tiltUpAroundViewCenter(1);
}
);

// Tilt down button
mTiltDownButton = new QPushButton(this);
mTiltDownButton ->setText(QString::fromUtf8("\u25BD"));
mTiltDownButton->setToolTip(QStringLiteral("Tilt Down"));
mTiltDownButton->setAutoRepeat(true);

QObject::connect(
mTiltDownButton,
&QPushButton::clicked,
parent,
[ = ]{
parent->cameraController()->tiltUpAroundViewCenter(-1);
}
);

// Rotate scene dial
mRotateSceneDial = new QDial(this);
mRotateSceneDial->setToolTip(QStringLiteral("Rotate view"));
mRotateSceneDial->setWrapping(true);
mRotateSceneDial->setMaximum(359);
mRotateSceneDial->setValue(180);

QObject::connect(
mRotateSceneDial,
&QDial::valueChanged,
parent,
[ = ]{
qInfo() << "Dial value: " << mRotateSceneDial->value();
parent->cameraController()->setCameraHeadingAngle(mRotateSceneDial->value());
}
);

QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->addWidget(mTiltUpButton, 0, 0);
gridLayout->addWidget(mTiltDownButton, 3, 0);
Expand Down

0 comments on commit 09baadb

Please sign in to comment.