16 #ifndef QGSCAMERACONTROLLER_H
17 #define QGSCAMERACONTROLLER_H
23 #include <Qt3DCore/QEntity>
24 #include <Qt3DInput/QMouseEvent>
29 class QKeyboardDevice;
30 class QKeyboardHandler;
49 class QgsTerrainEntity;
63 Q_PROPERTY( Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged )
64 Q_PROPERTY( QRect viewport READ viewport WRITE setViewport NOTIFY viewportChanged )
73 Q_ENUM( NavigationMode )
82 Q_ENUM( VerticalAxisInversion )
89 Qt3DRender::QCamera *
camera()
const {
return mCamera; }
109 void setCameraMovementSpeed(
double movementSpeed );
128 void setTerrainEntity( QgsTerrainEntity *te );
131 void setCamera( Qt3DRender::QCamera *camera );
133 void setViewport( QRect viewport );
135 void frameTriggered(
float dt );
138 void resetView(
float distance );
141 void setViewFromTop(
float worldX,
float worldY,
float distance,
float yaw = 0 );
152 void setLookingAtPoint(
const QgsVector3D &point,
float distance,
float pitch,
float yaw );
170 float distance()
const {
return mCameraPose.distanceFromCenterPoint(); }
177 float pitch()
const {
return mCameraPose.pitchAngle(); }
184 float yaw()
const {
return mCameraPose.headingAngle(); }
187 QDomElement writeXml( QDomDocument &doc )
const;
189 void readXml(
const QDomElement &elem );
192 void zoom(
float factor );
194 void tiltUpAroundViewCenter(
float deltaPitch );
196 void rotateAroundViewCenter(
float deltaYaw );
198 void setCameraHeadingAngle(
float angle );
200 void moveView(
float tx,
float ty );
207 bool willHandleKeyEvent( QKeyEvent *event );
218 void rotateCamera(
float diffPitch,
float diffYaw );
219 void updateCameraFromPose(
bool centerPointChanged =
false );
220 void moveCameraPositionBy(
const QVector3D &posDiff );
242 void onPositionChanged( Qt3DInput::QMouseEvent *mouse );
243 void onWheel( Qt3DInput::QWheelEvent *wheel );
244 void onMousePressed( Qt3DInput::QMouseEvent *mouse );
245 void onMouseReleased( Qt3DInput::QMouseEvent *mouse );
246 void onKeyPressed( Qt3DInput::QKeyEvent *event );
247 void onKeyReleased( Qt3DInput::QKeyEvent *event );
248 void onPickerMousePressed( Qt3DRender::QPickEvent *pick );
249 void applyFlyModeKeyMovements();
252 void onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event );
253 void onKeyPressedTerrainNavigation( Qt3DInput::QKeyEvent *event );
254 void onPositionChangedFlyNavigation( Qt3DInput::QMouseEvent *mouse );
255 void onPositionChangedTerrainNavigation( Qt3DInput::QMouseEvent *mouse );
259 Qt3DRender::QCamera *mCamera =
nullptr;
263 float mLastPressedHeight = 0;
265 QPointer<QgsTerrainEntity> mTerrainEntity;
272 bool mMousePressed =
false;
273 Qt3DInput::QMouseEvent::Buttons mPressedButton = Qt3DInput::QMouseEvent::Buttons::NoButton;
276 Qt3DInput::QMouseDevice *mMouseDevice =
nullptr;
277 Qt3DInput::QKeyboardDevice *mKeyboardDevice =
nullptr;
279 Qt3DInput::QMouseHandler *mMouseHandler =
nullptr;
280 Qt3DInput::QKeyboardHandler *mKeyboardHandler =
nullptr;
281 NavigationMode mCameraNavigationMode = NavigationMode::TerrainBasedNavigation;
283 double mCameraMovementSpeed = 5.0;
285 QSet< int > mDepressedKeys;
286 bool mCaptureFpsMouseMovements =
false;
287 bool mIgnoreNextMouseMove =
false;
288 QTimer *mFpsNavTimer =
nullptr;
QgsCameraController::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera controller.
QgsCameraPose cameraPose() const
Returns camera pose.
QRect viewport() const
Returns viewport rectangle.
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.
float yaw() const
Returns yaw angle in degrees.
void navigationModeHotKeyPressed(QgsCameraController::NavigationMode mode)
Emitted when the navigation mode is changed using the hotkey ctrl + ~.
float distance() const
Returns distance of the camera from the point it is looking at.
VerticalAxisInversion
Vertical axis inversion options.
@ WhenDragging
Invert vertical axis movements when dragging in first person modes.
@ Always
Always invert vertical axis movements.
@ Never
Never invert vertical axis movements.
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.
QgsCameraController::VerticalAxisInversion verticalAxisInversion() const
Returns the vertical axis inversion behavior.
NavigationMode
The navigation mode used by the camera.
@ TerrainBasedNavigation
The default navigation based on the terrain.
void viewportChanged()
Emitted when viewport rectangle has been updated.
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)