16#ifndef QGSCAMERACONTROLLER_H
17#define QGSCAMERACONTROLLER_H
21#include <Qt3DCore/QEntity>
22#include <Qt3DInput/QMouseEvent>
29 class QKeyboardHandler;
51class QgsCameraController4Test;
79 Qt3DRender::QCamera *
camera()
const {
return mCamera; }
98 void setCameraMovementSpeed(
double movementSpeed );
113 void frameTriggered(
float dt );
116 void resetView(
float distance );
119 void setViewFromTop(
float worldX,
float worldY,
float distance,
float yaw = 0 );
130 void setLookingAtPoint(
const QgsVector3D &point,
float distance,
float pitch,
float yaw );
149 float distance()
const {
return mCameraPose.distanceFromCenterPoint(); }
156 float pitch()
const {
return mCameraPose.pitchAngle(); }
163 float yaw()
const {
return mCameraPose.headingAngle(); }
166 QDomElement writeXml( QDomDocument &doc )
const;
168 void readXml(
const QDomElement &elem );
171 void zoom(
float factor );
173 void tiltUpAroundViewCenter(
float deltaPitch );
175 void rotateAroundViewCenter(
float deltaYaw );
177 void setCameraHeadingAngle(
float angle );
179 void moveView(
float tx,
float ty );
185 void walkView(
double tx,
double ty,
double tz );
193 void rotateCamera(
float diffPitch,
float diffYaw );
200 bool willHandleKeyEvent( QKeyEvent *event );
214 void depthBufferCaptured(
const QImage &depthImage );
222 void updateCameraFromPose();
223 void moveCameraPositionBy(
const QVector3D &posDiff );
225 QWindow *window()
const;
228 enum class MouseOperation
241 const QList<MouseOperation> mTranslateOrRotate =
243 MouseOperation::Translation,
244 MouseOperation::RotationCamera,
245 MouseOperation::RotationCenter
249 bool isATranslationRotationSequence( MouseOperation newOperation )
const;
251 void setMouseParameters(
const MouseOperation &newOperation,
const QPoint &clickPoint = QPoint() );
284 void onPositionChanged( Qt3DInput::QMouseEvent *mouse );
285 void onWheel( Qt3DInput::QWheelEvent *wheel );
286 void onMousePressed( Qt3DInput::QMouseEvent *mouse );
287 void onMouseReleased( Qt3DInput::QMouseEvent *mouse );
288 void onKeyPressed( Qt3DInput::QKeyEvent *event );
289 void onKeyReleased( Qt3DInput::QKeyEvent *event );
290 void applyFlyModeKeyMovements();
293 void onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event );
294 void onKeyPressedTerrainNavigation( Qt3DInput::QKeyEvent *event );
295 void onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse );
296 void onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse );
298 void handleTerrainNavigationWheelZoom();
304 double sampleDepthBuffer(
const QImage &buffer,
int px,
int py );
308 bool screenPointToWorldPos( QPoint position, Qt3DRender::QCamera *cameraBefore,
double &depth, QVector3D &worldPosition );
315 Qt3DRender::QCamera *mCamera =
nullptr;
326 bool mDepthBufferIsReady =
false;
327 QImage mDepthBufferImage;
329 std::unique_ptr< Qt3DRender::QCamera > mCameraBefore;
331 bool mRotationCenterCalculated =
false;
332 QVector3D mRotationCenter;
333 double mRotationDistanceFromCenter;
334 double mRotationPitch = 0;
335 double mRotationYaw = 0;
337 bool mDragPointCalculated =
false;
338 QVector3D mDragPoint;
341 bool mZoomPointCalculated =
false;
342 QVector3D mZoomPoint;
344 Qt3DInput::QMouseHandler *mMouseHandler =
nullptr;
345 Qt3DInput::QKeyboardHandler *mKeyboardHandler =
nullptr;
348 double mCameraMovementSpeed = 5.0;
350 QSet< int > mDepressedKeys;
351 bool mCaptureFpsMouseMovements =
false;
352 bool mIgnoreNextMouseMove =
false;
353 QTimer *mFpsNavTimer =
nullptr;
355 double mCumulatedWheelY = 0;
357 MouseOperation mCurrentOperation = MouseOperation::None;
359 friend QgsCameraController4Test;
VerticalAxisInversion
Vertical axis inversion options for 3D views.
@ WhenDragging
Invert vertical axis movements when dragging in first person modes.
NavigationMode
The navigation mode used by 3D cameras.
@ TerrainBased
The default navigation based on the terrain.
void navigationModeChanged(Qgis::NavigationMode mode)
Emitted when the navigation mode is changed using the hotkey ctrl + ~.
QgsCameraPose cameraPose() const
Returns camera pose.
float pitch() const
Returns pitch angle in degrees (0 = looking from the top, 90 = looking from the side).
Qt3DRender::QCamera * camera() const
Returns camera that is being controlled.
~QgsCameraController() override
float yaw() const
Returns yaw angle in degrees.
void requestDepthBufferCapture()
Emitted to ask for the depth buffer image.
Qgis::VerticalAxisInversion verticalAxisInversion() const
Returns the vertical axis inversion behavior.
float distance() const
Returns distance of the camera from the point it is looking at.
double cameraMovementSpeed() const
Returns the camera movement speed.
void cameraChanged()
Emitted when camera has been updated.
void cameraMovementSpeedChanged(double speed)
Emitted whenever the camera movement speed is changed by the controller.
Qgis::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera controller.
void cameraRotationCenterChanged(QVector3D position)
Emitted when the camera rotation center changes.
void setCursorPosition(QPoint point)
Emitted when the mouse cursor position should be moved to the specified point on the map viewport.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)