16 #ifndef QGSCAMERACONTROLLER_H
17 #define QGSCAMERACONTROLLER_H
23 #include <Qt3DCore/QEntity>
24 #include <Qt3DInput/QMouseEvent>
30 class QKeyboardDevice;
31 class QKeyboardHandler;
50 class QgsTerrainEntity;
64 Q_PROPERTY( Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged )
65 Q_PROPERTY( QRect viewport READ viewport WRITE setViewport NOTIFY viewportChanged )
74 Q_ENUM( NavigationMode )
83 Q_ENUM( VerticalAxisInversion )
90 Qt3DRender::QCamera *
camera()
const {
return mCamera; }
110 void setCameraMovementSpeed(
double movementSpeed );
129 void setTerrainEntity( QgsTerrainEntity *te );
132 void setCamera( Qt3DRender::QCamera *camera );
134 void setViewport( QRect viewport );
136 void frameTriggered(
float dt );
139 void resetView(
float distance );
142 void setViewFromTop(
float worldX,
float worldY,
float distance,
float yaw = 0 );
153 void setLookingAtPoint(
const QgsVector3D &point,
float distance,
float pitch,
float yaw );
172 float distance()
const {
return mCameraPose.distanceFromCenterPoint(); }
179 float pitch()
const {
return mCameraPose.pitchAngle(); }
186 float yaw()
const {
return mCameraPose.headingAngle(); }
189 QDomElement writeXml( QDomDocument &doc )
const;
191 void readXml(
const QDomElement &elem );
194 void zoom(
float factor );
196 void tiltUpAroundViewCenter(
float deltaPitch );
198 void rotateAroundViewCenter(
float deltaYaw );
200 void setCameraHeadingAngle(
float angle );
202 void moveView(
float tx,
float ty );
209 bool willHandleKeyEvent( QKeyEvent *event );
223 void depthBufferCaptured(
const QImage &depthImage );
226 void rotateCamera(
float diffPitch,
float diffYaw );
227 void updateCameraFromPose();
228 void moveCameraPositionBy(
const QVector3D &posDiff );
232 void cameraChanged();
234 void viewportChanged();
241 void cameraMovementSpeedChanged(
double speed );
247 void setCursorPosition( QPoint point );
253 void requestDepthBufferCapture();
259 void cameraRotationCenterChanged( QVector3D position );
262 void onPositionChanged( Qt3DInput::QMouseEvent *mouse );
263 void onWheel( Qt3DInput::QWheelEvent *wheel );
264 void onMousePressed( Qt3DInput::QMouseEvent *mouse );
265 void onMouseReleased( Qt3DInput::QMouseEvent *mouse );
266 void onKeyPressed( Qt3DInput::QKeyEvent *event );
267 void onKeyReleased( Qt3DInput::QKeyEvent *event );
268 void onPickerMousePressed( Qt3DRender::QPickEvent *pick );
269 void applyFlyModeKeyMovements();
272 void onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event );
273 void onKeyPressedTerrainNavigation( Qt3DInput::QKeyEvent *event );
274 void onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse );
275 void onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse );
277 void handleTerrainNavigationWheelZoom();
283 double sampleDepthBuffer(
const QImage &buffer,
int px,
int py );
287 Qt3DRender::QCamera *mCamera =
nullptr;
291 float mLastPressedHeight = 0;
293 QPointer<QgsTerrainEntity> mTerrainEntity;
300 bool mMousePressed =
false;
301 Qt3DInput::QMouseEvent::Buttons mPressedButton = Qt3DInput::QMouseEvent::Buttons::NoButton;
303 bool mDepthBufferIsReady =
false;
304 QImage mDepthBufferImage;
306 QPoint mMiddleButtonClickPos;
307 bool mRotationCenterCalculated =
false;
308 QVector3D mRotationCenter;
309 double mRotationDistanceFromCenter;
310 double mRotationPitch = 0;
311 double mRotationYaw = 0;
312 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeRotation;
314 QPoint mDragButtonClickPos;
315 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeDrag;
316 bool mDragPointCalculated =
false;
317 QVector3D mDragPoint;
320 bool mIsInZoomInState =
false;
321 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeZoom;
322 bool mZoomPointCalculated =
false;
323 QVector3D mZoomPoint;
326 Qt3DInput::QMouseDevice *mMouseDevice =
nullptr;
327 Qt3DInput::QKeyboardDevice *mKeyboardDevice =
nullptr;
329 Qt3DInput::QMouseHandler *mMouseHandler =
nullptr;
330 Qt3DInput::QKeyboardHandler *mKeyboardHandler =
nullptr;
331 NavigationMode mCameraNavigationMode = NavigationMode::TerrainBasedNavigation;
332 VerticalAxisInversion mVerticalAxisInversion = WhenDragging;
333 double mCameraMovementSpeed = 5.0;
335 QSet< int > mDepressedKeys;
336 bool mCaptureFpsMouseMovements =
false;
337 bool mIgnoreNextMouseMove =
false;
338 QTimer *mFpsNavTimer =
nullptr;
340 double mCumulatedWheelY = 0;
344 #endif // QGSCAMERACONTROLLER_H