Skip to content

Commit 33f7c17

Browse files
committed
Use middle button for rotation/tilt, right button for zoom
1 parent 7ad57e6 commit 33f7c17

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/3d/cameracontroller.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
1515
, mLeftMouseButtonInput( new Qt3DInput::QActionInput() )
1616
, mMiddleMouseButtonAction( new Qt3DInput::QAction() )
1717
, mMiddleMouseButtonInput( new Qt3DInput::QActionInput() )
18+
, mRightMouseButtonAction( new Qt3DInput::QAction() )
19+
, mRightMouseButtonInput( new Qt3DInput::QActionInput() )
1820
, mShiftAction( new Qt3DInput::QAction() )
1921
, mShiftInput( new Qt3DInput::QActionInput() )
2022
, mWheelAxis( new Qt3DInput::QAxis() )
@@ -47,6 +49,11 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
4749
mMiddleMouseButtonInput->setSourceDevice( mMouseDevice );
4850
mMiddleMouseButtonAction->addInput( mMiddleMouseButtonInput );
4951

52+
// right mouse button
53+
mRightMouseButtonInput->setButtons( QVector<int>() << Qt::RightButton );
54+
mRightMouseButtonInput->setSourceDevice( mMouseDevice );
55+
mRightMouseButtonAction->addInput( mRightMouseButtonInput );
56+
5057
// Mouse Wheel (Y)
5158
// TODO: zoom with mouse wheel in Qt < 5.8
5259
#if QT_VERSION >= 0x050800
@@ -86,6 +93,7 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
8693

8794
mLogicalDevice->addAction( mLeftMouseButtonAction );
8895
mLogicalDevice->addAction( mMiddleMouseButtonAction );
96+
mLogicalDevice->addAction( mRightMouseButtonAction );
8997
mLogicalDevice->addAction( mShiftAction );
9098
mLogicalDevice->addAxis( mWheelAxis );
9199
mLogicalDevice->addAxis( mTxAxis );
@@ -178,7 +186,7 @@ void CameraController::frameTriggered( float dt )
178186

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

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

200-
if ( mLeftMouseButtonAction->isActive() )
208+
if ( ( mLeftMouseButtonAction->isActive() && mShiftAction->isActive() ) || mMiddleMouseButtonAction->isActive() )
209+
{
210+
cd.pitch += dy;
211+
cd.yaw -= dx / 2;
212+
}
213+
else if ( mLeftMouseButtonAction->isActive() && !mShiftAction->isActive() )
201214
{
202-
if ( mShiftAction->isActive() )
203-
{
204-
cd.pitch += dy;
205-
cd.yaw -= dx / 2;
206-
}
207-
else
208-
{
209-
// translation works as if one grabbed a point on the plane and dragged it
210-
// i.e. find out x,z of the previous mouse point, find out x,z of the current mouse point
211-
// and use the difference
212-
213-
float z = mLastPressedHeight;
214-
QPointF p1 = screen_point_to_point_on_plane( QPointF( mMousePos - QPoint( dx, dy ) ), mViewport, mCamera, z );
215-
QPointF p2 = screen_point_to_point_on_plane( QPointF( mMousePos ), mViewport, mCamera, z );
216-
217-
cd.x -= p2.x() - p1.x();
218-
cd.y -= p2.y() - p1.y();
219-
}
215+
// translation works as if one grabbed a point on the plane and dragged it
216+
// i.e. find out x,z of the previous mouse point, find out x,z of the current mouse point
217+
// and use the difference
218+
219+
float z = mLastPressedHeight;
220+
QPointF p1 = screen_point_to_point_on_plane( QPointF( mMousePos - QPoint( dx, dy ) ), mViewport, mCamera, z );
221+
QPointF p2 = screen_point_to_point_on_plane( QPointF( mMousePos ), mViewport, mCamera, z );
222+
223+
cd.x -= p2.x() - p1.x();
224+
cd.y -= p2.y() - p1.y();
220225
}
221226

222227
if ( qIsNaN( cd.x ) || qIsNaN( cd.y ) )

src/3d/cameracontroller.h

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class _3D_EXPORT CameraController : public Qt3DCore::QEntity
102102
Qt3DInput::QAction *mMiddleMouseButtonAction;
103103
Qt3DInput::QActionInput *mMiddleMouseButtonInput;
104104

105+
Qt3DInput::QAction *mRightMouseButtonAction;
106+
Qt3DInput::QActionInput *mRightMouseButtonInput;
107+
105108
Qt3DInput::QAction *mShiftAction;
106109
Qt3DInput::QActionInput *mShiftInput;
107110

0 commit comments

Comments
 (0)