Skip to content
Permalink
Browse files

[feature] Allow moving camera up/down using page up/down keys

  • Loading branch information
wonder-sk committed Jun 28, 2018
1 parent 98bce5b commit 2b5f46990c9151e459cc232eeca767f39f4bcfc9
Showing with 24 additions and 0 deletions.
  1. +20 −0 src/3d/qgscameracontroller.cpp
  2. +4 −0 src/3d/qgscameracontroller.h
@@ -49,6 +49,9 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
, mKeyboardTyPosInput( new Qt3DInput::QButtonAxisInput() )
, mKeyboardTxNegInput( new Qt3DInput::QButtonAxisInput() )
, mKeyboardTyNegInput( new Qt3DInput::QButtonAxisInput() )
, mTelevAxis( new Qt3DInput::QAxis() )
, mKeyboardTelevPosInput( new Qt3DInput::QButtonAxisInput() )
, mKeyboardTelevNegInput( new Qt3DInput::QButtonAxisInput() )
{

// not using QAxis + QAnalogAxisInput for mouse X,Y because
@@ -115,6 +118,18 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
mKeyboardTyNegInput->setSourceDevice( mKeyboardDevice );
mTyAxis->addInput( mKeyboardTyNegInput );

// Keyboard Neg Telev
mKeyboardTelevNegInput->setButtons( QVector<int>() << Qt::Key_PageDown );
mKeyboardTelevNegInput->setScale( -1.0f );
mKeyboardTelevNegInput->setSourceDevice( mKeyboardDevice );
mTelevAxis->addInput( mKeyboardTelevNegInput );

// Keyboard Pos Telev
mKeyboardTelevPosInput->setButtons( QVector<int>() << Qt::Key_PageUp );
mKeyboardTelevPosInput->setScale( 1.0f );
mKeyboardTelevPosInput->setSourceDevice( mKeyboardDevice );
mTelevAxis->addInput( mKeyboardTelevPosInput );

mLogicalDevice->addAction( mLeftMouseButtonAction );
mLogicalDevice->addAction( mMiddleMouseButtonAction );
mLogicalDevice->addAction( mRightMouseButtonAction );
@@ -123,6 +138,7 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
mLogicalDevice->addAxis( mWheelAxis );
mLogicalDevice->addAxis( mTxAxis );
mLogicalDevice->addAxis( mTyAxis );
mLogicalDevice->addAxis( mTelevAxis );

// Disable the logical device when the entity is disabled
connect( this, &Qt3DCore::QEntity::enabledChanged,
@@ -244,6 +260,7 @@ void QgsCameraController::frameTriggered( float dt )

float tx = mTxAxis->value() * dt * mCameraData.dist * 1.5;
float ty = -mTyAxis->value() * dt * mCameraData.dist * 1.5;
float telev = mTelevAxis->value() * dt * 300;

if ( !mShiftAction->isActive() && ( tx || ty ) )
{
@@ -282,6 +299,9 @@ void QgsCameraController::frameTriggered( float dt )
mCameraData.y -= p2.y() - p1.y();
}

if ( telev != 0 )
mCameraData.elev += telev;

if ( std::isnan( mCameraData.x ) || std::isnan( mCameraData.y ) )
{
// something went horribly wrong but we need to at least try to fix it somehow
@@ -175,6 +175,10 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
Qt3DInput::QButtonAxisInput *mKeyboardTyPosInput = nullptr;
Qt3DInput::QButtonAxisInput *mKeyboardTxNegInput = nullptr;
Qt3DInput::QButtonAxisInput *mKeyboardTyNegInput = nullptr;

Qt3DInput::QAxis *mTelevAxis = nullptr;
Qt3DInput::QButtonAxisInput *mKeyboardTelevPosInput = nullptr;
Qt3DInput::QButtonAxisInput *mKeyboardTelevNegInput = nullptr;
};

#endif // QGSCAMERACONTROLLER_H

0 comments on commit 2b5f469

Please sign in to comment.
You can’t perform that action at this time.