Skip to content
Permalink
Browse files

Zoom in/out by pressing middle mouse button and moving up/down

  • Loading branch information
wonder-sk committed Aug 2, 2017
1 parent d7b821d commit 7f1f8a63616bf987eb3fb75e32c1b37ab98ab249
Showing with 16 additions and 0 deletions.
  1. +13 −0 src/3d/cameracontroller.cpp
  2. +3 −0 src/3d/cameracontroller.h
@@ -13,6 +13,8 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
, mLogicalDevice( new Qt3DInput::QLogicalDevice() )
, mLeftMouseButtonAction( new Qt3DInput::QAction() )
, mLeftMouseButtonInput( new Qt3DInput::QActionInput() )
, mMiddleMouseButtonAction( new Qt3DInput::QAction() )
, mMiddleMouseButtonInput( new Qt3DInput::QActionInput() )
, mShiftAction( new Qt3DInput::QAction() )
, mShiftInput( new Qt3DInput::QActionInput() )
, mWheelAxis( new Qt3DInput::QAxis() )
@@ -40,6 +42,11 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
mLeftMouseButtonInput->setSourceDevice( mMouseDevice );
mLeftMouseButtonAction->addInput( mLeftMouseButtonInput );

// middle mouse button
mMiddleMouseButtonInput->setButtons( QVector<int>() << Qt::MiddleButton );
mMiddleMouseButtonInput->setSourceDevice( mMouseDevice );
mMiddleMouseButtonAction->addInput( mMiddleMouseButtonInput );

// Mouse Wheel (Y)
// TODO: zoom with mouse wheel in Qt < 5.8
#if QT_VERSION >= 0x050800
@@ -78,6 +85,7 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
mTyAxis->addInput( mKeyboardTyNegInput );

mLogicalDevice->addAction( mLeftMouseButtonAction );
mLogicalDevice->addAction( mMiddleMouseButtonAction );
mLogicalDevice->addAction( mShiftAction );
mLogicalDevice->addAxis( mWheelAxis );
mLogicalDevice->addAxis( mTxAxis );
@@ -168,6 +176,11 @@ void CameraController::frameTriggered( float dt )

cd.dist -= cd.dist * mWheelAxis->value() * 10 * dt;

if ( mMiddleMouseButtonAction->isActive() )
{
cd.dist -= cd.dist * dy * 0.01;
}

float tx = mTxAxis->value() * dt * cd.dist * 1.5;
float ty = -mTyAxis->value() * dt * cd.dist * 1.5;

@@ -99,6 +99,9 @@ class _3D_EXPORT CameraController : public Qt3DCore::QEntity
Qt3DInput::QAction *mLeftMouseButtonAction;
Qt3DInput::QActionInput *mLeftMouseButtonInput;

Qt3DInput::QAction *mMiddleMouseButtonAction;
Qt3DInput::QActionInput *mMiddleMouseButtonInput;

Qt3DInput::QAction *mShiftAction;
Qt3DInput::QActionInput *mShiftInput;

0 comments on commit 7f1f8a6

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