Skip to content
Permalink
Browse files

Use middle button for rotation/tilt, right button for zoom

  • Loading branch information
wonder-sk committed Aug 12, 2017
1 parent 7ad57e6 commit 33f7c177403cdb7aa4036bc0e8a5ef2cc8854e64
Showing with 28 additions and 20 deletions.
  1. +25 −20 src/3d/cameracontroller.cpp
  2. +3 −0 src/3d/cameracontroller.h
@@ -15,6 +15,8 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
, mLeftMouseButtonInput( new Qt3DInput::QActionInput() )
, mMiddleMouseButtonAction( new Qt3DInput::QAction() )
, mMiddleMouseButtonInput( new Qt3DInput::QActionInput() )
, mRightMouseButtonAction( new Qt3DInput::QAction() )
, mRightMouseButtonInput( new Qt3DInput::QActionInput() )
, mShiftAction( new Qt3DInput::QAction() )
, mShiftInput( new Qt3DInput::QActionInput() )
, mWheelAxis( new Qt3DInput::QAxis() )
@@ -47,6 +49,11 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
mMiddleMouseButtonInput->setSourceDevice( mMouseDevice );
mMiddleMouseButtonAction->addInput( mMiddleMouseButtonInput );

// right mouse button
mRightMouseButtonInput->setButtons( QVector<int>() << Qt::RightButton );
mRightMouseButtonInput->setSourceDevice( mMouseDevice );
mRightMouseButtonAction->addInput( mRightMouseButtonInput );

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

mLogicalDevice->addAction( mLeftMouseButtonAction );
mLogicalDevice->addAction( mMiddleMouseButtonAction );
mLogicalDevice->addAction( mRightMouseButtonAction );
mLogicalDevice->addAction( mShiftAction );
mLogicalDevice->addAxis( mWheelAxis );
mLogicalDevice->addAxis( mTxAxis );
@@ -178,7 +186,7 @@ void CameraController::frameTriggered( float dt )

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

if ( mMiddleMouseButtonAction->isActive() )
if ( mRightMouseButtonAction->isActive() )
{
cd.dist -= cd.dist * dy * 0.01;
}
@@ -197,26 +205,23 @@ void CameraController::frameTriggered( float dt )
cd.y += dy;
}

if ( mLeftMouseButtonAction->isActive() )
if ( ( mLeftMouseButtonAction->isActive() && mShiftAction->isActive() ) || mMiddleMouseButtonAction->isActive() )
{
cd.pitch += dy;
cd.yaw -= dx / 2;
}
else if ( mLeftMouseButtonAction->isActive() && !mShiftAction->isActive() )
{
if ( mShiftAction->isActive() )
{
cd.pitch += dy;
cd.yaw -= dx / 2;
}
else
{
// translation works as if one grabbed a point on the plane and dragged it
// i.e. find out x,z of the previous mouse point, find out x,z of the current mouse point
// and use the difference

float z = mLastPressedHeight;
QPointF p1 = screen_point_to_point_on_plane( QPointF( mMousePos - QPoint( dx, dy ) ), mViewport, mCamera, z );
QPointF p2 = screen_point_to_point_on_plane( QPointF( mMousePos ), mViewport, mCamera, z );

cd.x -= p2.x() - p1.x();
cd.y -= p2.y() - p1.y();
}
// translation works as if one grabbed a point on the plane and dragged it
// i.e. find out x,z of the previous mouse point, find out x,z of the current mouse point
// and use the difference

float z = mLastPressedHeight;
QPointF p1 = screen_point_to_point_on_plane( QPointF( mMousePos - QPoint( dx, dy ) ), mViewport, mCamera, z );
QPointF p2 = screen_point_to_point_on_plane( QPointF( mMousePos ), mViewport, mCamera, z );

cd.x -= p2.x() - p1.x();
cd.y -= p2.y() - p1.y();
}

if ( qIsNaN( cd.x ) || qIsNaN( cd.y ) )
@@ -102,6 +102,9 @@ class _3D_EXPORT CameraController : public Qt3DCore::QEntity
Qt3DInput::QAction *mMiddleMouseButtonAction;
Qt3DInput::QActionInput *mMiddleMouseButtonInput;

Qt3DInput::QAction *mRightMouseButtonAction;
Qt3DInput::QActionInput *mRightMouseButtonInput;

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

0 comments on commit 33f7c17

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