@@ -15,6 +15,8 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
15
15
, mLeftMouseButtonInput( new Qt3DInput::QActionInput() )
16
16
, mMiddleMouseButtonAction( new Qt3DInput::QAction() )
17
17
, mMiddleMouseButtonInput( new Qt3DInput::QActionInput() )
18
+ , mRightMouseButtonAction( new Qt3DInput::QAction() )
19
+ , mRightMouseButtonInput( new Qt3DInput::QActionInput() )
18
20
, mShiftAction( new Qt3DInput::QAction() )
19
21
, mShiftInput( new Qt3DInput::QActionInput() )
20
22
, mWheelAxis( new Qt3DInput::QAxis() )
@@ -47,6 +49,11 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
47
49
mMiddleMouseButtonInput ->setSourceDevice ( mMouseDevice );
48
50
mMiddleMouseButtonAction ->addInput ( mMiddleMouseButtonInput );
49
51
52
+ // right mouse button
53
+ mRightMouseButtonInput ->setButtons ( QVector<int >() << Qt::RightButton );
54
+ mRightMouseButtonInput ->setSourceDevice ( mMouseDevice );
55
+ mRightMouseButtonAction ->addInput ( mRightMouseButtonInput );
56
+
50
57
// Mouse Wheel (Y)
51
58
// TODO: zoom with mouse wheel in Qt < 5.8
52
59
#if QT_VERSION >= 0x050800
@@ -86,6 +93,7 @@ CameraController::CameraController( Qt3DCore::QNode *parent )
86
93
87
94
mLogicalDevice ->addAction ( mLeftMouseButtonAction );
88
95
mLogicalDevice ->addAction ( mMiddleMouseButtonAction );
96
+ mLogicalDevice ->addAction ( mRightMouseButtonAction );
89
97
mLogicalDevice ->addAction ( mShiftAction );
90
98
mLogicalDevice ->addAxis ( mWheelAxis );
91
99
mLogicalDevice ->addAxis ( mTxAxis );
@@ -178,7 +186,7 @@ void CameraController::frameTriggered( float dt )
178
186
179
187
cd.dist -= cd.dist * mWheelAxis ->value () * 10 * dt;
180
188
181
- if ( mMiddleMouseButtonAction ->isActive () )
189
+ if ( mRightMouseButtonAction ->isActive () )
182
190
{
183
191
cd.dist -= cd.dist * dy * 0.01 ;
184
192
}
@@ -197,26 +205,23 @@ void CameraController::frameTriggered( float dt )
197
205
cd.y += dy;
198
206
}
199
207
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 () )
201
214
{
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 ();
220
225
}
221
226
222
227
if ( qIsNaN ( cd.x ) || qIsNaN ( cd.y ) )
0 commit comments