|
QGroundControl
Ground Control Station for MAVLink Drones
|
#include <GeoMapCamera.h>
Inheritance diagram for GeoMapCamera:
Collaboration diagram for GeoMapCamera:Classes | |
| struct | PickRay |
Public Types | |
| enum class | Mode { Mode2D , Mode3D } |
Signals | |
| void | centerChanged () |
| void | headingChanged () |
| void | tiltChanged () |
| void | distanceChanged () |
| void | centerElevationChanged () |
| void | viewportSizeChanged () |
| void | fieldOfViewChanged () |
| void | verticalFieldOfViewChanged () |
| void | unitsPerPixelAtUnitDistanceChanged () |
| void | modeChanged () |
| void | scenePoseChanged () |
Public Member Functions | |
| GeoMapCamera (QObject *parent=nullptr) | |
| QGeoCoordinate | center () const |
| void | setCenter (const QGeoCoordinate ¢er) |
| bool | isPositioned () const |
| qreal | heading () const |
| void | setHeading (qreal heading) |
| qreal | tilt () const |
| void | setTilt (qreal tilt) |
| qreal | distance () const |
| void | setDistance (qreal distance) |
| qreal | centerElevation () const |
| void | setCenterElevation (qreal elevation) |
| QSizeF | viewportSize () const |
| void | setViewportSize (const QSizeF &size) |
| qreal | fieldOfView () const |
| void | setFieldOfView (qreal fov) |
| qreal | verticalFieldOfView () const |
| qreal | unitsPerPixelAtUnitDistance () const |
| bool | isTopDown () const |
| Mode | mode () const |
| void | setMode (Mode mode) |
| qreal | default3DTilt () const |
| Q_INVOKABLE void | reset () |
| Restore the default pose at the current center (heading 0, tilt 0, default distance) | |
| Q_INVOKABLE void | lookAt (const QGeoCoordinate ¢er, qreal heading, qreal tilt, qreal distance) |
| Set the full pose in one call. tilt/distance are clamped. | |
| Q_INVOKABLE void | goTo2D () |
| Q_INVOKABLE void | goTo3D () |
| Q_INVOKABLE void | beginPan (const QPointF &screenPos, double anchorZ=0.0) |
| Q_INVOKABLE void | panTo (const QPointF &screenPos) |
| Continue a pan gesture: the surface point picked at beginPan stays under the cursor. | |
| Q_INVOKABLE void | beginOrbit (const QPointF &screenPos, double anchorZ=0.0) |
| Start an orbit gesture at the given screen position (pixels); anchorZ as in beginPan. | |
| Q_INVOKABLE void | orbitTo (const QPointF &screenPos) |
| Q_INVOKABLE void | beginLook (const QPointF &screenPos) |
| Start a first-person look gesture at the given screen position (pixels) | |
| Q_INVOKABLE void | lookTo (const QPointF &screenPos) |
| Q_INVOKABLE void | rotateBy (qreal degrees, const QPointF &screenPos) |
| Q_INVOKABLE void | tiltBy (qreal degrees, const QPointF &screenPos) |
| Q_INVOKABLE void | zoom (qreal amount, const QPointF &screenPos) |
| Q_INVOKABLE void | zoomBy (qreal factor, const QPointF &screenPos) |
| Q_INVOKABLE qreal | sceneUnitsPerPixel () const |
| Q_INVOKABLE qreal | distanceForZoomLevel (qreal zoomLevel) const |
| Q_INVOKABLE qreal | zoomLevelForDistance (qreal distance) const |
| Q_INVOKABLE QGeoCoordinate | centerForCoordinateAtScreenPoint (const QGeoCoordinate &coordinate, const QPointF &screenPos, double worldZ=0.0, double centerElevation=qQNaN()) const |
| Q_INVOKABLE void | fitToRegion (const QGeoRectangle ®ion) |
| QVector3D | cameraPosition () const |
| QPointF | cameraGroundPosition () const |
| QPointF | sceneOrigin () const |
| void | setSceneOrigin (const QPointF &origin) |
| QVector3D | scenePosition () const |
| QQuaternion | sceneRotation () const |
| std::optional< PickRay > | pickRayAt (const QPointF &screenPos) const |
| std::optional< QPointF > | screenToGround (const QPointF &screenPos, double planeZ=0.0) const |
| Q_INVOKABLE QGeoCoordinate | coordinateAtScreenPoint (const QPointF &screenPos, double worldZ=0.0) const |
| std::optional< QPointF > | groundPointCapped (const QPointF &screenPos, double maxRange) const |
| std::optional< QPointF > | worldToScreen (const QPointF &worldGround, double worldZ=0.0) const |
Static Public Attributes | |
| static constexpr qreal | kMinDistance = 10.0 |
| static constexpr qreal | kMaxDistance = 40000000.0 |
| static constexpr qreal | kMinTilt = 0.0 |
| static constexpr qreal | kMaxTilt = 85.0 |
| static constexpr qreal | kDefaultDistance = 1500.0 |
| static constexpr qreal | kDefaultFieldOfView = 45.0 |
| static constexpr qreal | kDefault3DTilt = 55.0 |
Camera pose model for the GeoMap engine.
Owns the pose as (center, heading, tilt, distance) where center is a geographic coordinate on the ground plane. Implements cursor-anchored pan, orbit, rotate, tilt and zoom: the ground point under the cursor at gesture start stays under the cursor for the duration of the gesture.
Scene space is Web Mercator meters (TileMath), z up, ground plane z=0. Camera position convention (matches the Viewer3D orbit camera): cameraPosition = center + distance * (sin(tilt)sin(heading), -sin(tilt)cos(heading), cos(tilt)) tilt 0 = top-down, tilt kMaxTilt = most oblique 3D view. Angles in degrees.
Definition at line 35 of file GeoMapCamera.h.
|
strong |
Map mode: 2D locks tilt against gestures (the map stays top-down until the user explicitly switches to 3D). setTilt itself is not gated so the QML-side mode-transition animation can drive it.
| Enumerator | |
|---|---|
| Mode2D | |
| Mode3D | |
Definition at line 61 of file GeoMapCamera.h.
|
explicit |
Definition at line 108 of file GeoMapCamera.cc.
| void GeoMapCamera::beginLook | ( | const QPointF & | screenPos | ) |
Start a first-person look gesture at the given screen position (pixels)
Definition at line 520 of file GeoMapCamera.cc.
| void GeoMapCamera::beginOrbit | ( | const QPointF & | screenPos, |
| double | anchorZ = 0.0 |
||
| ) |
Start an orbit gesture at the given screen position (pixels); anchorZ as in beginPan.
Definition at line 486 of file GeoMapCamera.cc.
References screenToGround().
| void GeoMapCamera::beginPan | ( | const QPointF & | screenPos, |
| double | anchorZ = 0.0 |
||
| ) |
Start a pan gesture at the given screen position (pixels). anchorZ is the world-z (scene units) of the grabbed surface point: gestures must anchor to the rendered terrain surface, not the z=0 ground plane, or the map slides off the cursor over elevated terrain.
Definition at line 472 of file GeoMapCamera.cc.
References screenToGround().
| QPointF GeoMapCamera::cameraGroundPosition | ( | ) | const |
Ground projection of the camera position (world mercator meters) in double precision, for consumers whose math must not lose meters at world scale (LOD/culling distances).
Definition at line 254 of file GeoMapCamera.cc.
Referenced by SurfacePatchModel::analyzeSurface(), and SurfaceModel::update().
| QVector3D GeoMapCamera::cameraPosition | ( | ) | const |
Derived camera position in world space (mercator meters, z up). Float precision — for rendering/debug display; internal math is double.
Definition at line 247 of file GeoMapCamera.cc.
| QGeoCoordinate GeoMapCamera::center | ( | ) | const |
Definition at line 110 of file GeoMapCamera.cc.
References TileMath::worldToGeo().
Referenced by centerForCoordinateAtScreenPoint(), lookAt(), and setCenter().
|
signal |
Referenced by GeoScene::setCamera(), and SurfaceModel::SurfaceModel().
|
inline |
World-z of the look-at point (scene units). The camera orbits distance meters around the center at this height; normally driven from the terrain height at the center so close-zoom 3D never dives under the rendered surface. Ground-plane math (screenToGround, pan/zoom anchors) still intersects z=0, with rays cast from the elevated camera.
Definition at line 104 of file GeoMapCamera.h.
Referenced by SurfacePatchModel::analyzeSurface(), and centerForCoordinateAtScreenPoint().
|
signal |
Referenced by setCenterElevation(), and SurfaceModel::SurfaceModel().
| QGeoCoordinate GeoMapCamera::centerForCoordinateAtScreenPoint | ( | const QGeoCoordinate & | coordinate, |
| const QPointF & | screenPos, | ||
| double | worldZ = 0.0, |
||
| double | centerElevation = qQNaN() |
||
| ) | const |
Center that places coordinate at screenPos with the current heading/tilt/ distance (rigid translation solve on the horizontal plane at worldZ, the point's rendered height in world units — 0 for a ground point). Returns the current center when screenPos misses the plane or the viewport is not set. centerElevation overrides the pivot elevation for the solve — pass the elevation the pivot will settle at when it follows terrain to the new center; NaN uses the current centerElevation.
Definition at line 402 of file GeoMapCamera.cc.
References center(), centerElevation(), TileMath::geoToWorld(), verticalFieldOfView(), and TileMath::worldToGeo().
Referenced by GeoScene::centerForCoordinateAtScreenPoint().
| QGeoCoordinate GeoMapCamera::coordinateAtScreenPoint | ( | const QPointF & | screenPos, |
| double | worldZ = 0.0 |
||
| ) | const |
QML-facing screenToGround: geographic coordinate of the pick-ray hit on the horizontal plane at worldZ (scene units, same as screenToGround's planeZ). Invalid coordinate when the ray misses.
Definition at line 316 of file GeoMapCamera.cc.
References screenToGround(), and TileMath::worldToGeo().
|
inline |
Definition at line 135 of file GeoMapCamera.h.
References kDefault3DTilt.
|
inline |
Definition at line 95 of file GeoMapCamera.h.
Referenced by SurfacePatchModel::analyzeSurface(), fitToRegion(), lookAt(), setDistance(), SurfacePatchModel::surfaceCoordinateAtScreenPoint(), SurfaceModel::update(), and zoomLevelForDistance().
|
signal |
Referenced by setDistance(), and SurfaceModel::SurfaceModel().
| qreal GeoMapCamera::distanceForZoomLevel | ( | qreal | zoomLevel | ) | const |
Camera distance that renders the scene at the scale of a slippy-map zoom level (matches QtLocation map zoomLevel semantics when top-down). Clamped to the distance limits; returns the default distance when the viewport is not set.
Definition at line 379 of file GeoMapCamera.cc.
References kDefaultDistance, kMaxDistance, kMinDistance, TileMath::kTilePixels, verticalFieldOfView(), and TileMath::worldSize().
|
inline |
Definition at line 112 of file GeoMapCamera.h.
|
signal |
Referenced by setFieldOfView(), and SurfaceModel::SurfaceModel().
| void GeoMapCamera::fitToRegion | ( | const QGeoRectangle & | region | ) |
QtLocation Map.visibleRegion analog: centers on region and moves to the closest distance at which all of its corners (on the pivot plane) are on screen, keeping heading and tilt. No-op for an invalid region or when the viewport is not set.
Definition at line 429 of file GeoMapCamera.cc.
References distance(), TileMath::geoToWorld(), kMaxDistance, kMinDistance, setDistance(), and verticalFieldOfView().
|
inline |
|
inline |
Definition at line 151 of file GeoMapCamera.h.
References kDefault3DTilt, Mode3D, setMode(), and setTilt().
| std::optional< QPointF > GeoMapCamera::groundPointCapped | ( | const QPointF & | screenPos, |
| double | maxRange | ||
| ) | const |
Like screenToGround, but never fails for horizon misses: the result is capped at maxRange ground meters from the camera's ground position, along the ray's horizontal direction. Used for visible-region estimation. Returns std::nullopt only when the viewport is not set.
Definition at line 325 of file GeoMapCamera.cc.
References verticalFieldOfView().
Referenced by SurfacePatchModel::analyzeSurface().
|
inline |
Definition at line 87 of file GeoMapCamera.h.
Referenced by lookAt(), and setHeading().
|
signal |
Referenced by setHeading(), and SurfaceModel::SurfaceModel().
|
inline |
False until the camera is explicitly positioned (setCenter/lookAt). The construction-default pose is null island; consumers must not treat it as a real location (e.g. by fetching terrain there).
Definition at line 85 of file GeoMapCamera.h.
Referenced by SurfaceModel::update().
|
inline |
Pose predicate: the camera currently looks straight down (tilt ~0). Distinct from mode(): Mode2D can be mid-transition with tilt > 0, and a Mode3D user can gesture tilt down to 0.
Definition at line 129 of file GeoMapCamera.h.
| void GeoMapCamera::lookAt | ( | const QGeoCoordinate & | center, |
| qreal | heading, | ||
| qreal | tilt, | ||
| qreal | distance | ||
| ) |
Set the full pose in one call. tilt/distance are clamped.
Definition at line 239 of file GeoMapCamera.cc.
References center(), distance(), heading(), setCenter(), setDistance(), setHeading(), setTilt(), and tilt().
| void GeoMapCamera::lookTo | ( | const QPointF & | screenPos | ) |
Continue a look gesture: rotate the view about the camera position picked at beginLook, which stays fixed while heading/tilt (and thus center and distance) change (Google Earth Ctrl+drag first-person perspective). Same drag ratios as orbitTo. 2D mode locks tilt, leaving a rotation about the camera's vertical axis.
Definition at line 530 of file GeoMapCamera.cc.
References height, kMaxDistance, kMaxTilt, kMinDistance, kMinTilt, Mode3D, setDistance(), setHeading(), and setTilt().
|
inline |
Definition at line 131 of file GeoMapCamera.h.
Referenced by setMode().
|
signal |
Referenced by setMode().
| void GeoMapCamera::orbitTo | ( | const QPointF & | screenPos | ) |
Continue an orbit gesture: rotate rigidly about the surface point picked at beginOrbit, which stays pinned to its on-screen position from gesture start. Full viewport width of drag = 360 deg heading, full height = 180 deg tilt.
Definition at line 496 of file GeoMapCamera.cc.
References Mode3D, setHeading(), and setTilt().
| void GeoMapCamera::panTo | ( | const QPointF & | screenPos | ) |
Continue a pan gesture: the surface point picked at beginPan stays under the cursor.
Definition at line 478 of file GeoMapCamera.cc.
| std::optional< GeoMapCamera::PickRay > GeoMapCamera::pickRayAt | ( | const QPointF & | screenPos | ) | const |
Pick ray through screenPos (pixels), for consumers that intersect it with something other than a horizontal plane (e.g. the terrain surface). std::nullopt when the viewport is not set.
Definition at line 286 of file GeoMapCamera.cc.
References verticalFieldOfView().
Referenced by SurfacePatchModel::surfaceCoordinateAtScreenPoint().
| void GeoMapCamera::reset | ( | ) |
Restore the default pose at the current center (heading 0, tilt 0, default distance)
Definition at line 232 of file GeoMapCamera.cc.
References kDefaultDistance, kMinTilt, setDistance(), setHeading(), and setTilt().
| void GeoMapCamera::rotateBy | ( | qreal | degrees, |
| const QPointF & | screenPos | ||
| ) |
Rotate the camera rigidly by degrees about the ground point under screenPos (positive = counterclockwise heading change). Used for two-finger twist gestures.
Definition at line 565 of file GeoMapCamera.cc.
References screenToGround(), and setHeading().
|
inline |
World-space reference origin for scene coordinates (set by the renderer, normally bound to GeoScene::sceneOrigin)
Definition at line 239 of file GeoMapCamera.h.
|
signal |
Emitted whenever scenePosition/sceneRotation may have changed (any pose component or the scene origin)
Referenced by setCenterElevation(), setDistance(), setHeading(), setSceneOrigin(), and setTilt().
| QVector3D GeoMapCamera::scenePosition | ( | ) | const |
Camera position in scene coordinates (world minus sceneOrigin, z up), for binding to the View3D camera node
Definition at line 269 of file GeoMapCamera.cc.
| QQuaternion GeoMapCamera::sceneRotation | ( | ) | const |
Camera orientation for the View3D camera node: identity = top-down with north up (matches the pose convention R = Rz(heading) * Rx(tilt))
Definition at line 278 of file GeoMapCamera.cc.
| qreal GeoMapCamera::sceneUnitsPerPixel | ( | ) | const |
Ground-plane world meters spanned by one horizontal pixel at screen center. Returns 0 when the viewport size is not set.
Definition at line 364 of file GeoMapCamera.cc.
References screenToGround().
| std::optional< QPointF > GeoMapCamera::screenToGround | ( | const QPointF & | screenPos, |
| double | planeZ = 0.0 |
||
| ) | const |
Intersect the pick ray through screenPos (pixels) with the horizontal plane at planeZ (scene units, default the ground plane z=0). Returns the hit point in world meters, or std::nullopt when the ray misses (at/above the horizon or the plane is behind the camera) or the viewport is not set.
Definition at line 297 of file GeoMapCamera.cc.
References verticalFieldOfView().
Referenced by beginOrbit(), beginPan(), coordinateAtScreenPoint(), rotateBy(), sceneUnitsPerPixel(), tiltBy(), and zoomBy().
| void GeoMapCamera::setCenter | ( | const QGeoCoordinate & | center | ) |
Definition at line 115 of file GeoMapCamera.cc.
References center(), and TileMath::geoToWorld().
Referenced by lookAt().
| void GeoMapCamera::setCenterElevation | ( | qreal | elevation | ) |
Definition at line 167 of file GeoMapCamera.cc.
References centerElevationChanged(), and scenePoseChanged().
| void GeoMapCamera::setDistance | ( | qreal | distance | ) |
Definition at line 156 of file GeoMapCamera.cc.
References distance(), distanceChanged(), kMaxDistance, kMinDistance, and scenePoseChanged().
Referenced by fitToRegion(), lookAt(), lookTo(), reset(), and zoomBy().
| void GeoMapCamera::setFieldOfView | ( | qreal | fov | ) |
Definition at line 193 of file GeoMapCamera.cc.
References fieldOfViewChanged(), unitsPerPixelAtUnitDistanceChanged(), and verticalFieldOfViewChanged().
| void GeoMapCamera::setHeading | ( | qreal | heading | ) |
Definition at line 134 of file GeoMapCamera.cc.
References heading(), headingChanged(), and scenePoseChanged().
Referenced by lookAt(), lookTo(), orbitTo(), reset(), and rotateBy().
| void GeoMapCamera::setMode | ( | Mode | mode | ) |
Definition at line 222 of file GeoMapCamera.cc.
References mode(), and modeChanged().
| void GeoMapCamera::setSceneOrigin | ( | const QPointF & | origin | ) |
Definition at line 260 of file GeoMapCamera.cc.
References scenePoseChanged().
| void GeoMapCamera::setTilt | ( | qreal | tilt | ) |
Definition at line 145 of file GeoMapCamera.cc.
References kMaxTilt, kMinTilt, scenePoseChanged(), tilt(), and tiltChanged().
Referenced by goTo2D(), goTo3D(), lookAt(), lookTo(), orbitTo(), reset(), and tiltBy().
| void GeoMapCamera::setViewportSize | ( | const QSizeF & | size | ) |
Definition at line 179 of file GeoMapCamera.cc.
References unitsPerPixelAtUnitDistanceChanged(), verticalFieldOfView(), verticalFieldOfViewChanged(), and viewportSizeChanged().
|
inline |
Definition at line 91 of file GeoMapCamera.h.
Referenced by SurfacePatchModel::analyzeSurface(), lookAt(), setTilt(), and SurfaceModel::update().
| void GeoMapCamera::tiltBy | ( | qreal | degrees, |
| const QPointF & | screenPos | ||
| ) |
Tilt the camera by degrees (clamped), keeping the ground point under screenPos fixed on screen. Used for two-finger vertical swipe gestures.
Definition at line 575 of file GeoMapCamera.cc.
References Mode3D, screenToGround(), and setTilt().
|
signal |
Referenced by setTilt(), and SurfaceModel::SurfaceModel().
| qreal GeoMapCamera::unitsPerPixelAtUnitDistance | ( | ) | const |
Scene units spanned by one pixel per unit of camera distance; multiply by a point's camera distance for its units-per-pixel (constant apparent size scaling). Returns 0 when the viewport size is not set.
Definition at line 214 of file GeoMapCamera.cc.
References verticalFieldOfView().
|
signal |
Referenced by setFieldOfView(), and setViewportSize().
| qreal GeoMapCamera::verticalFieldOfView | ( | ) | const |
fieldOfView applied to the larger viewport axis (Cesium-style): on wide viewports the vertical FOV narrows instead of the horizontal FOV exploding into fisheye distortion. All projection math uses this.
Definition at line 205 of file GeoMapCamera.cc.
Referenced by centerForCoordinateAtScreenPoint(), distanceForZoomLevel(), fitToRegion(), groundPointCapped(), pickRayAt(), screenToGround(), setViewportSize(), unitsPerPixelAtUnitDistance(), worldToScreen(), and zoomLevelForDistance().
|
signal |
Referenced by setFieldOfView(), and setViewportSize().
|
inline |
Definition at line 108 of file GeoMapCamera.h.
Referenced by SurfacePatchModel::analyzeSurface(), and SurfaceModel::update().
|
signal |
Referenced by setViewportSize(), and SurfaceModel::SurfaceModel().
| std::optional< QPointF > GeoMapCamera::worldToScreen | ( | const QPointF & | worldGround, |
| double | worldZ = 0.0 |
||
| ) | const |
Projects a world-space point (mercator meters, z in scene units) to screen pixels. Double precision throughout. Returns std::nullopt when the point is at or behind the camera plane or the viewport is not set.
Definition at line 354 of file GeoMapCamera.cc.
References verticalFieldOfView().
Referenced by GeoScene::screenPositionFor(), and GeoMapSpriteLayer::updatePaintNode().
| void GeoMapCamera::zoom | ( | qreal | amount, |
| const QPointF & | screenPos | ||
| ) |
Zoom toward/away from the ground point under screenPos. amount is in wheel angleDelta units (positive = zoom in). Distance is clamped.
Definition at line 587 of file GeoMapCamera.cc.
References zoomBy().
| void GeoMapCamera::zoomBy | ( | qreal | factor, |
| const QPointF & | screenPos | ||
| ) |
Scale the camera distance by factor (e.g. 0.5 halves the distance), keeping the ground point under screenPos fixed on screen. Used for pinch gestures.
Definition at line 593 of file GeoMapCamera.cc.
References screenToGround(), and setDistance().
Referenced by zoom().
| qreal GeoMapCamera::zoomLevelForDistance | ( | qreal | distance | ) | const |
Slippy-map zoom level rendered at the given camera distance — the inverse of distanceForZoomLevel. distance is clamped to the distance limits. Returns 0 when the viewport is not set.
Definition at line 389 of file GeoMapCamera.cc.
References distance(), kMaxDistance, kMinDistance, TileMath::kTilePixels, verticalFieldOfView(), and TileMath::worldSize().
|
staticconstexpr |
Definition at line 77 of file GeoMapCamera.h.
Referenced by default3DTilt(), and goTo3D().
|
staticconstexpr |
Definition at line 72 of file GeoMapCamera.h.
Referenced by distanceForZoomLevel(), and reset().
|
staticconstexpr |
Definition at line 76 of file GeoMapCamera.h.
|
staticconstexpr |
Definition at line 69 of file GeoMapCamera.h.
Referenced by distanceForZoomLevel(), fitToRegion(), lookTo(), setDistance(), and zoomLevelForDistance().
|
staticconstexpr |
Definition at line 71 of file GeoMapCamera.h.
|
staticconstexpr |
Definition at line 68 of file GeoMapCamera.h.
Referenced by distanceForZoomLevel(), fitToRegion(), lookTo(), setDistance(), and zoomLevelForDistance().
|
staticconstexpr |