16#ifndef QGSCAMERACONTROLLER_H
17#define QGSCAMERACONTROLLER_H
21#include <Qt3DCore/QEntity>
22#include <Qt3DInput/QMouseEvent>
29 class QKeyboardHandler;
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;
258 void onPositionChanged( Qt3DInput::QMouseEvent *mouse );
259 void onWheel( Qt3DInput::QWheelEvent *wheel );
260 void onMousePressed( Qt3DInput::QMouseEvent *mouse );
261 void onMouseReleased( Qt3DInput::QMouseEvent *mouse );
262 void onKeyPressed( Qt3DInput::QKeyEvent *event );
263 void onKeyReleased( Qt3DInput::QKeyEvent *event );
264 void applyFlyModeKeyMovements();
267 void onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event );
268 void onKeyPressedTerrainNavigation( Qt3DInput::QKeyEvent *event );
269 void onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse );
270 void onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse );
272 void handleTerrainNavigationWheelZoom();
278 double sampleDepthBuffer(
const QImage &buffer,
int px,
int py );
280 bool screenPointToWorldPos( QPoint position, Qt3DRender::QCamera *cameraBefore,
double &depth, QVector3D &worldPosition );
287 Qt3DRender::QCamera *mCamera =
nullptr;
294 bool mMousePressed =
false;
295 Qt3DInput::QMouseEvent::Buttons mPressedButton = Qt3DInput::QMouseEvent::Buttons::NoButton;
297 bool mDepthBufferIsReady =
false;
298 QImage mDepthBufferImage;
300 QPoint mMiddleButtonClickPos;
301 bool mRotationCenterCalculated =
false;
302 QVector3D mRotationCenter;
303 double mRotationDistanceFromCenter;
304 double mRotationPitch = 0;
305 double mRotationYaw = 0;
306 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeRotation;
308 QPoint mDragButtonClickPos;
309 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeDrag;
310 bool mDragPointCalculated =
false;
311 QVector3D mDragPoint;
314 bool mIsInZoomInState =
false;
315 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeZoom;
316 bool mZoomPointCalculated =
false;
317 QVector3D mZoomPoint;
319 Qt3DInput::QMouseHandler *mMouseHandler =
nullptr;
320 Qt3DInput::QKeyboardHandler *mKeyboardHandler =
nullptr;
323 double mCameraMovementSpeed = 5.0;
325 QSet< int > mDepressedKeys;
326 bool mCaptureFpsMouseMovements =
false;
327 bool mIgnoreNextMouseMove =
false;
328 QTimer *mFpsNavTimer =
nullptr;
330 double mCumulatedWheelY = 0;
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.
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)