16#ifndef QGSCAMERACONTROLLER_H
17#define QGSCAMERACONTROLLER_H
21#include <Qt3DCore/QEntity>
22#include <Qt3DInput/QMouseEvent>
29 class QKeyboardHandler;
51class QgsCameraController4Test;
80 Qt3DRender::QCamera *
camera()
const {
return mCamera; }
99 void setCameraMovementSpeed(
double movementSpeed );
114 void frameTriggered(
float dt );
117 void resetView(
float distance );
120 void setViewFromTop(
float worldX,
float worldY,
float distance,
float yaw = 0 );
131 void setLookingAtPoint(
const QgsVector3D &point,
float distance,
float pitch,
float yaw );
150 float distance()
const {
return mCameraPose.distanceFromCenterPoint(); }
157 float pitch()
const {
return mCameraPose.pitchAngle(); }
164 float yaw()
const {
return mCameraPose.headingAngle(); }
167 QDomElement writeXml( QDomDocument &doc )
const;
169 void readXml(
const QDomElement &elem );
172 void zoom(
float factor );
174 void tiltUpAroundViewCenter(
float deltaPitch );
176 void rotateAroundViewCenter(
float deltaYaw );
178 void setCameraHeadingAngle(
float angle );
180 void moveView(
float tx,
float ty );
186 void walkView(
double tx,
double ty,
double tz );
194 void rotateCamera(
float diffPitch,
float diffYaw );
201 bool willHandleKeyEvent( QKeyEvent *event );
215 void depthBufferCaptured(
const QImage &depthImage );
223 void updateCameraFromPose();
224 void moveCameraPositionBy(
const QVector3D &posDiff );
226 QWindow *window()
const;
259 void onPositionChanged( Qt3DInput::QMouseEvent *mouse );
260 void onWheel( Qt3DInput::QWheelEvent *wheel );
261 void onMousePressed( Qt3DInput::QMouseEvent *mouse );
262 void onMouseReleased( Qt3DInput::QMouseEvent *mouse );
263 void onKeyPressed( Qt3DInput::QKeyEvent *event );
264 void onKeyReleased( Qt3DInput::QKeyEvent *event );
265 void applyFlyModeKeyMovements();
268 void onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event );
269 void onKeyPressedTerrainNavigation( Qt3DInput::QKeyEvent *event );
270 void onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse );
271 void onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse );
273 void handleTerrainNavigationWheelZoom();
279 double sampleDepthBuffer(
const QImage &buffer,
int px,
int py );
283 bool screenPointToWorldPos( QPoint position, Qt3DRender::QCamera *cameraBefore,
double &depth, QVector3D &worldPosition );
290 Qt3DRender::QCamera *mCamera =
nullptr;
297 bool mMousePressed =
false;
298 Qt3DInput::QMouseEvent::Buttons mPressedButton = Qt3DInput::QMouseEvent::Buttons::NoButton;
300 bool mDepthBufferIsReady =
false;
301 QImage mDepthBufferImage;
303 QPoint mMiddleButtonClickPos;
304 bool mRotationCenterCalculated =
false;
305 QVector3D mRotationCenter;
306 double mRotationDistanceFromCenter;
307 double mRotationPitch = 0;
308 double mRotationYaw = 0;
309 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeRotation;
311 QPoint mDragButtonClickPos;
312 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeDrag;
313 bool mDragPointCalculated =
false;
314 QVector3D mDragPoint;
317 bool mIsInZoomInState =
false;
318 std::unique_ptr< Qt3DRender::QCamera > mCameraBeforeZoom;
319 bool mZoomPointCalculated =
false;
320 QVector3D mZoomPoint;
322 Qt3DInput::QMouseHandler *mMouseHandler =
nullptr;
323 Qt3DInput::QKeyboardHandler *mKeyboardHandler =
nullptr;
326 double mCameraMovementSpeed = 5.0;
328 QSet< int > mDepressedKeys;
329 bool mCaptureFpsMouseMovements =
false;
330 bool mIgnoreNextMouseMove =
false;
331 QTimer *mFpsNavTimer =
nullptr;
333 double mCumulatedWheelY = 0;
335 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.
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)