QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
Viewer3DCameraController Class Reference

#include <Viewer3DCameraController.h>

+ Inheritance diagram for Viewer3DCameraController:
+ Collaboration diagram for Viewer3DCameraController:

Signals

void orbitCenterChanged ()
 
void headingChanged ()
 
void tiltChanged ()
 
void distanceChanged ()
 
void viewportSizeChanged ()
 
void fieldOfViewChanged ()
 

Public Member Functions

 Viewer3DCameraController (QObject *parent=nullptr)
 
QVector3D orbitCenter () const
 
void setOrbitCenter (const QVector3D &center)
 
qreal heading () const
 
void setHeading (qreal heading)
 
qreal tilt () const
 
void setTilt (qreal tilt)
 
qreal distance () const
 
void setDistance (qreal distance)
 
QSizeF viewportSize () const
 
void setViewportSize (const QSizeF &size)
 
qreal fieldOfView () const
 
void setFieldOfView (qreal fov)
 
Q_INVOKABLE void reset ()
 Restore the default pose (center origin, heading 0, tilt 0, default distance)
 
Q_INVOKABLE void lookAt (const QVector3D &center, qreal heading, qreal tilt, qreal distance)
 Set the full pose in one call. tilt/distance are clamped.
 
Q_INVOKABLE void beginPan (const QPointF &screenPos)
 Start a pan gesture at the given screen position (pixels)
 
Q_INVOKABLE void panTo (const QPointF &screenPos)
 Continue a pan gesture: the ground point picked at beginPan stays under the cursor.
 
Q_INVOKABLE void beginOrbit (const QPointF &screenPos)
 Start an orbit gesture at the given screen position (pixels)
 
Q_INVOKABLE void orbitTo (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
 
QVector3D cameraPosition () const
 Derived camera position in scene space.
 
std::optional< QVector3D > screenToGround (const QPointF &screenPos) const
 

Static Public Attributes

static constexpr qreal kMinDistance = 50.0
 
static constexpr qreal kMaxDistance = 50000.0
 
static constexpr qreal kMinTilt = 0.0
 
static constexpr qreal kMaxTilt = 85.0
 
static constexpr qreal kDefaultDistance = 1500.0
 
static constexpr qreal kDefaultFieldOfView = 60.0
 

Friends

class Viewer3DCameraControllerTest
 

Detailed Description

Gazebo-style orbit camera controller for the 3D viewer.

Owns the camera pose as (orbitCenter, heading, tilt, distance) and implements cursor-anchored pan, orbit and zoom: the ground point under the cursor at gesture start stays under the cursor for the duration of the gesture.

Coordinate conventions (scene space, z-up): cameraPosition = orbitCenter + distance * (sin(tilt)sin(heading), -sin(tilt)cos(heading), cos(tilt)) tilt 0 = top-down, tilt 90 = horizontal. Angles in degrees.

Definition at line 28 of file Viewer3DCameraController.h.

Constructor & Destructor Documentation

◆ Viewer3DCameraController()

Viewer3DCameraController::Viewer3DCameraController ( QObject *  parent = nullptr)
explicit

Definition at line 34 of file Viewer3DCameraController.cc.

Member Function Documentation

◆ beginOrbit()

void Viewer3DCameraController::beginOrbit ( const QPointF &  screenPos)

Start an orbit gesture at the given screen position (pixels)

Definition at line 128 of file Viewer3DCameraController.cc.

References screenToGround().

◆ beginPan()

void Viewer3DCameraController::beginPan ( const QPointF &  screenPos)

Start a pan gesture at the given screen position (pixels)

Definition at line 105 of file Viewer3DCameraController.cc.

References screenToGround().

◆ cameraPosition()

QVector3D Viewer3DCameraController::cameraPosition ( ) const

Derived camera position in scene space.

Definition at line 246 of file Viewer3DCameraController.cc.

Referenced by screenToGround().

◆ distance()

qreal Viewer3DCameraController::distance ( ) const
inline

Definition at line 63 of file Viewer3DCameraController.h.

Referenced by lookAt(), and setDistance().

◆ distanceChanged

void Viewer3DCameraController::distanceChanged ( )
signal

Referenced by setDistance().

◆ fieldOfView()

qreal Viewer3DCameraController::fieldOfView ( ) const
inline

Definition at line 71 of file Viewer3DCameraController.h.

◆ fieldOfViewChanged

void Viewer3DCameraController::fieldOfViewChanged ( )
signal

Referenced by setFieldOfView().

◆ heading()

qreal Viewer3DCameraController::heading ( ) const
inline

Definition at line 55 of file Viewer3DCameraController.h.

Referenced by lookAt(), and setHeading().

◆ headingChanged

void Viewer3DCameraController::headingChanged ( )
signal

Referenced by setHeading().

◆ lookAt()

void Viewer3DCameraController::lookAt ( const QVector3D &  center,
qreal  heading,
qreal  tilt,
qreal  distance 
)

Set the full pose in one call. tilt/distance are clamped.

Definition at line 97 of file Viewer3DCameraController.cc.

References distance(), heading(), setDistance(), setHeading(), setOrbitCenter(), setTilt(), and tilt().

Referenced by reset().

◆ orbitCenter()

QVector3D Viewer3DCameraController::orbitCenter ( ) const
inline

Definition at line 51 of file Viewer3DCameraController.h.

◆ orbitCenterChanged

void Viewer3DCameraController::orbitCenterChanged ( )
signal

Referenced by setOrbitCenter().

◆ orbitTo()

void Viewer3DCameraController::orbitTo ( const QPointF &  screenPos)

Continue an orbit gesture: rotate rigidly about the ground point picked at beginOrbit. Full viewport width of drag = 360 deg yaw, full height = 180 deg tilt (Gazebo behavior).

Definition at line 141 of file Viewer3DCameraController.cc.

◆ panTo()

void Viewer3DCameraController::panTo ( const QPointF &  screenPos)

Continue a pan gesture: the ground point picked at beginPan stays under the cursor.

Definition at line 114 of file Viewer3DCameraController.cc.

References screenToGround(), and setOrbitCenter().

◆ reset()

void Viewer3DCameraController::reset ( )

Restore the default pose (center origin, heading 0, tilt 0, default distance)

Definition at line 92 of file Viewer3DCameraController.cc.

References kDefaultDistance, and lookAt().

◆ rotateBy()

void Viewer3DCameraController::rotateBy ( qreal  degrees,
const QPointF &  screenPos 
)

Rotate the camera rigidly by degrees about the ground point under screenPos (positive = counterclockwise heading change). The anchored scene point stays put on screen. Used for two-finger twist gestures.

Definition at line 156 of file Viewer3DCameraController.cc.

References screenToGround().

◆ sceneUnitsPerPixel()

qreal Viewer3DCameraController::sceneUnitsPerPixel ( ) const

Scene units spanned by one horizontal pixel on the ground plane at screen center. Returns 0 when the viewport size is not set.

Definition at line 235 of file Viewer3DCameraController.cc.

◆ screenToGround()

std::optional< QVector3D > Viewer3DCameraController::screenToGround ( const QPointF &  screenPos) const

Intersect the pick ray through screenPos (pixels) with the ground plane z=0. Returns std::nullopt when the ray misses (at/above the horizon) or the viewport is not set.

Definition at line 251 of file Viewer3DCameraController.cc.

References cameraPosition().

Referenced by beginOrbit(), beginPan(), panTo(), rotateBy(), tiltBy(), and zoomBy().

◆ setDistance()

void Viewer3DCameraController::setDistance ( qreal  distance)

Definition at line 64 of file Viewer3DCameraController.cc.

References distance(), distanceChanged(), kMaxDistance, and kMinDistance.

Referenced by lookAt(), and zoomBy().

◆ setFieldOfView()

void Viewer3DCameraController::setFieldOfView ( qreal  fov)

Definition at line 83 of file Viewer3DCameraController.cc.

References fieldOfViewChanged().

◆ setHeading()

void Viewer3DCameraController::setHeading ( qreal  heading)

Definition at line 45 of file Viewer3DCameraController.cc.

References heading(), and headingChanged().

Referenced by lookAt().

◆ setOrbitCenter()

void Viewer3DCameraController::setOrbitCenter ( const QVector3D &  center)

Definition at line 36 of file Viewer3DCameraController.cc.

References orbitCenterChanged().

Referenced by lookAt(), panTo(), and zoomBy().

◆ setTilt()

void Viewer3DCameraController::setTilt ( qreal  tilt)

Definition at line 54 of file Viewer3DCameraController.cc.

References kMaxTilt, kMinTilt, tilt(), and tiltChanged().

Referenced by lookAt().

◆ setViewportSize()

void Viewer3DCameraController::setViewportSize ( const QSizeF &  size)

Definition at line 74 of file Viewer3DCameraController.cc.

References viewportSizeChanged().

◆ tilt()

qreal Viewer3DCameraController::tilt ( ) const
inline

Definition at line 59 of file Viewer3DCameraController.h.

Referenced by lookAt(), and setTilt().

◆ tiltBy()

void Viewer3DCameraController::tiltBy ( qreal  degrees,
const QPointF &  screenPos 
)

Tilt the camera rigidly by degrees (clamped) about the ground point under screenPos. The anchored scene point stays put on screen. Used for two-finger vertical swipe gestures.

Definition at line 166 of file Viewer3DCameraController.cc.

References screenToGround().

◆ tiltChanged

void Viewer3DCameraController::tiltChanged ( )
signal

Referenced by setTilt().

◆ viewportSize()

QSizeF Viewer3DCameraController::viewportSize ( ) const
inline

Definition at line 67 of file Viewer3DCameraController.h.

◆ viewportSizeChanged

void Viewer3DCameraController::viewportSizeChanged ( )
signal

Referenced by setViewportSize().

◆ zoom()

void Viewer3DCameraController::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 203 of file Viewer3DCameraController.cc.

References kMaxDistance, kMinDistance, and zoomBy().

◆ zoomBy()

void Viewer3DCameraController::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 215 of file Viewer3DCameraController.cc.

References kMaxDistance, kMinDistance, screenToGround(), setDistance(), and setOrbitCenter().

Referenced by zoom().

Friends And Related Symbol Documentation

◆ Viewer3DCameraControllerTest

friend class Viewer3DCameraControllerTest
friend

Definition at line 39 of file Viewer3DCameraController.h.

Member Data Documentation

◆ kDefaultDistance

constexpr qreal Viewer3DCameraController::kDefaultDistance = 1500.0
staticconstexpr

Definition at line 48 of file Viewer3DCameraController.h.

Referenced by reset().

◆ kDefaultFieldOfView

constexpr qreal Viewer3DCameraController::kDefaultFieldOfView = 60.0
staticconstexpr

Definition at line 49 of file Viewer3DCameraController.h.

◆ kMaxDistance

constexpr qreal Viewer3DCameraController::kMaxDistance = 50000.0
staticconstexpr

Definition at line 45 of file Viewer3DCameraController.h.

Referenced by setDistance(), zoom(), and zoomBy().

◆ kMaxTilt

constexpr qreal Viewer3DCameraController::kMaxTilt = 85.0
staticconstexpr

Definition at line 47 of file Viewer3DCameraController.h.

Referenced by setTilt().

◆ kMinDistance

constexpr qreal Viewer3DCameraController::kMinDistance = 50.0
staticconstexpr

Definition at line 44 of file Viewer3DCameraController.h.

Referenced by setDistance(), zoom(), and zoomBy().

◆ kMinTilt

constexpr qreal Viewer3DCameraController::kMinTilt = 0.0
staticconstexpr

Definition at line 46 of file Viewer3DCameraController.h.

Referenced by setTilt().


The documentation for this class was generated from the following files: