QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
Viewer3DCameraController.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QObject>
13#include <QtCore/QPointF>
14#include <QtCore/QSizeF>
15#include <QtGui/QVector3D>
16#include <QtQmlIntegration/QtQmlIntegration>
17#include <optional>
18
28class Viewer3DCameraController : public QObject
29{
30 Q_OBJECT
31 QML_ELEMENT
32 Q_PROPERTY(QVector3D orbitCenter READ orbitCenter WRITE setOrbitCenter NOTIFY orbitCenterChanged)
33 Q_PROPERTY(qreal heading READ heading WRITE setHeading NOTIFY headingChanged)
34 Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged)
35 Q_PROPERTY(qreal distance READ distance WRITE setDistance NOTIFY distanceChanged)
36 Q_PROPERTY(QSizeF viewportSize READ viewportSize WRITE setViewportSize NOTIFY viewportSizeChanged)
37 Q_PROPERTY(qreal fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
38
40
41public:
42 explicit Viewer3DCameraController(QObject* parent = nullptr);
43
44 static constexpr qreal kMinDistance = 50.0;
45 static constexpr qreal kMaxDistance = 50000.0;
46 static constexpr qreal kMinTilt = 0.0;
47 static constexpr qreal kMaxTilt = 85.0;
48 static constexpr qreal kDefaultDistance = 1500.0;
49 static constexpr qreal kDefaultFieldOfView = 60.0;
50
51 QVector3D orbitCenter() const { return _orbitCenter; }
52
53 void setOrbitCenter(const QVector3D& center);
54
55 qreal heading() const { return _heading; }
56
57 void setHeading(qreal heading);
58
59 qreal tilt() const { return _tilt; }
60
61 void setTilt(qreal tilt);
62
63 qreal distance() const { return _distance; }
64
65 void setDistance(qreal distance);
66
67 QSizeF viewportSize() const { return _viewportSize; }
68
69 void setViewportSize(const QSizeF& size);
70
71 qreal fieldOfView() const { return _fieldOfView; }
72
73 void setFieldOfView(qreal fov);
74
76 Q_INVOKABLE void reset();
77
79 Q_INVOKABLE void lookAt(const QVector3D& center, qreal heading, qreal tilt, qreal distance);
80
82 Q_INVOKABLE void beginPan(const QPointF& screenPos);
84 Q_INVOKABLE void panTo(const QPointF& screenPos);
85
87 Q_INVOKABLE void beginOrbit(const QPointF& screenPos);
90 Q_INVOKABLE void orbitTo(const QPointF& screenPos);
91
95 Q_INVOKABLE void rotateBy(qreal degrees, const QPointF& screenPos);
96
100 Q_INVOKABLE void tiltBy(qreal degrees, const QPointF& screenPos);
101
104 Q_INVOKABLE void zoom(qreal amount, const QPointF& screenPos);
105
108 Q_INVOKABLE void zoomBy(qreal factor, const QPointF& screenPos);
109
112 Q_INVOKABLE qreal sceneUnitsPerPixel() const;
113
115 QVector3D cameraPosition() const;
116
119 std::optional<QVector3D> screenToGround(const QPointF& screenPos) const;
120
121signals:
128
129private:
130 QVector3D _orbitCenter;
131 qreal _heading = 0.0;
132 qreal _tilt = 0.0;
133 qreal _distance = kDefaultDistance;
134 QSizeF _viewportSize;
135 qreal _fieldOfView = kDefaultFieldOfView;
136
137 QVector3D _panAnchor;
138 bool _panAnchorValid = false;
139 QVector3D _orbitAnchor;
140 bool _orbitAnchorValid = false;
141 QPointF _lastOrbitPos;
142
145 void _rotateAboutAnchor(const QVector3D& anchor, qreal headingDelta, qreal tiltDelta);
146};
Q_INVOKABLE void beginOrbit(const QPointF &screenPos)
Start an orbit gesture at the given screen position (pixels)
Q_INVOKABLE void zoomBy(qreal factor, const QPointF &screenPos)
void setOrbitCenter(const QVector3D &center)
std::optional< QVector3D > screenToGround(const QPointF &screenPos) const
Q_INVOKABLE void orbitTo(const QPointF &screenPos)
Q_INVOKABLE void lookAt(const QVector3D &center, qreal heading, qreal tilt, qreal distance)
Set the full pose in one call. tilt/distance are clamped.
static constexpr qreal kMinTilt
Q_INVOKABLE void rotateBy(qreal degrees, const QPointF &screenPos)
static constexpr qreal kDefaultDistance
Q_INVOKABLE void zoom(qreal amount, const QPointF &screenPos)
static constexpr qreal kMaxDistance
Q_INVOKABLE void reset()
Restore the default pose (center origin, heading 0, tilt 0, default distance)
Q_INVOKABLE void beginPan(const QPointF &screenPos)
Start a pan gesture at the given screen position (pixels)
static constexpr qreal kMinDistance
Q_INVOKABLE void panTo(const QPointF &screenPos)
Continue a pan gesture: the ground point picked at beginPan stays under the cursor.
static constexpr qreal kMaxTilt
QVector3D cameraPosition() const
Derived camera position in scene space.
void setViewportSize(const QSizeF &size)
Q_INVOKABLE void tiltBy(qreal degrees, const QPointF &screenPos)
Q_INVOKABLE qreal sceneUnitsPerPixel() const
static constexpr qreal kDefaultFieldOfView