Skip to content

Commit

Permalink
Add move to 4 directions buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Jun 6, 2019
1 parent 81a8782 commit 6341388
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
34 changes: 19 additions & 15 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -395,21 +395,7 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
{
if ( !hasShift && !hasCtrl )
{
float yaw = mCameraPose.headingAngle();
float dist = mCameraPose.distanceFromCenterPoint();
float x = tx * dist * 0.02f;
float y = -ty * dist * 0.02f;

// moving with keyboard - take into account yaw of camera
float t = sqrt( x * x + y * y );
float a = atan2( y, x ) - yaw * M_PI / 180;
float dx = cos( a ) * t;
float dy = sin( a ) * t;

QgsVector3D center = mCameraPose.centerPoint();
center.set( center.x() + dx, center.y(), center.z() + dy );
mCameraPose.setCenterPoint( center );
updateCameraFromPose( true );
moveView(tx, ty);
}
else if ( hasShift && !hasCtrl )
{
Expand Down Expand Up @@ -468,3 +454,21 @@ void QgsCameraController::setCameraHeadingAngle(float angle){
mCameraPose.setHeadingAngle( angle );
updateCameraFromPose();
}

void QgsCameraController::moveView(float tx, float ty){
float yaw = mCameraPose.headingAngle();
float dist = mCameraPose.distanceFromCenterPoint();
float x = tx * dist * 0.02f;
float y = -ty * dist * 0.02f;

// moving with keyboard - take into account yaw of camera
float t = sqrt( x * x + y * y );
float a = atan2( y, x ) - yaw * M_PI / 180;
float dx = cos( a ) * t;
float dy = sin( a ) * t;

QgsVector3D center = mCameraPose.centerPoint();
center.set( center.x() + dx, center.y(), center.z() + dy );
mCameraPose.setCenterPoint( center );
updateCameraFromPose( true );
}
1 change: 1 addition & 0 deletions src/3d/qgscameracontroller.h
Expand Up @@ -139,6 +139,7 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
void tiltUpAroundViewCenter(float deltaPitch);
void rotateAroundViewCenter(float deltaYaw);
void setCameraHeadingAngle(float angle);
void moveView(float tx, float ty);

private:
void rotateCamera( float diffPitch, float diffYaw );
Expand Down
69 changes: 68 additions & 1 deletion src/app/3d/qgs3dnavigationwidget.cpp
Expand Up @@ -92,14 +92,81 @@ Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(p
}
);

// Move up button
mMoveUpButton = new QToolButton(this);
mMoveUpButton->setToolTip(QStringLiteral("Move up"));
mMoveUpButton->setAutoRepeat(true);
mMoveUpButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowUp.svg" ) ) );
mMoveUpButton->setAutoRaise(true);

QObject::connect(
mMoveUpButton,
&QToolButton::clicked,
parent,
[ = ]{
parent->cameraController()->moveView(0, 1);
}
);

// Move right button
mMoveRightButton = new QToolButton(this);
mMoveRightButton->setToolTip(QStringLiteral("Move right"));
mMoveRightButton->setAutoRepeat(true);
mMoveRightButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowRight.svg" ) ) );
mMoveRightButton->setAutoRaise(true);

QObject::connect(
mMoveRightButton,
&QToolButton::clicked,
parent,
[ = ]{
parent->cameraController()->moveView(1, 0);
}
);

// Move down button
mMoveDownButton = new QToolButton(this);
mMoveDownButton->setToolTip(QStringLiteral("Move down"));
mMoveDownButton->setAutoRepeat(true);
mMoveDownButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowDown.svg" ) ) );
mMoveDownButton->setAutoRaise(true);

QObject::connect(
mMoveDownButton,
&QToolButton::clicked,
parent,
[ = ]{
parent->cameraController()->moveView(0, -1);
}
);

// Move left button
mMoveLeftButton = new QToolButton(this);
mMoveLeftButton->setToolTip(QStringLiteral("Move left"));
mMoveLeftButton->setAutoRepeat(true);
mMoveLeftButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowLeft.svg" ) ) );
mMoveLeftButton->setAutoRaise(true);

QObject::connect(
mMoveLeftButton,
&QToolButton::clicked,
parent,
[ = ]{
parent->cameraController()->moveView(-1, 0);
}
);

QGridLayout *gridLayout = new QGridLayout(this);
gridLayout->addWidget(mTiltUpButton, 0, 0);
gridLayout->addWidget(mTiltDownButton, 3, 0);
gridLayout->addWidget(mZoomInButton, 0, 3);
gridLayout->addWidget(mZoomOutButton, 3, 3);
gridLayout->addWidget(mRotateSceneDial, 1, 1, 2, 2);
gridLayout->addWidget(mMoveUpButton, 0, 1, 1, 2, Qt::AlignCenter);
gridLayout->addWidget(mMoveRightButton, 1, 3, 2, 1, Qt::AlignCenter);
gridLayout->addWidget(mMoveDownButton, 3, 1, 1, 2, Qt::AlignCenter);
gridLayout->addWidget(mMoveLeftButton, 1, 0, 2, 1, Qt::AlignCenter);
gridLayout->setAlignment(Qt::AlignTop);

}

Qgs3DNavigationWidget::~Qgs3DNavigationWidget()
Expand Down
4 changes: 4 additions & 0 deletions src/app/3d/qgs3dnavigationwidget.h
Expand Up @@ -40,6 +40,10 @@ public slots:
QToolButton *mZoomOutButton = nullptr;
QToolButton *mTiltUpButton = nullptr;
QToolButton *mTiltDownButton = nullptr;
QToolButton *mMoveUpButton = nullptr;
QToolButton *mMoveRightButton = nullptr;
QToolButton *mMoveDownButton = nullptr;
QToolButton *mMoveLeftButton = nullptr;
QDial *mRotateSceneDial = nullptr;
};

Expand Down

0 comments on commit 6341388

Please sign in to comment.