18#include <Qt3DRender/QCamera>
20#include <QDomDocument>
24 QDomElement elemCamera = doc.createElement( QStringLiteral(
"camera-pose" ) );
25 elemCamera.setAttribute( QStringLiteral(
"x" ), mCenterPoint.
x() );
26 elemCamera.setAttribute( QStringLiteral(
"y" ), mCenterPoint.
y() );
27 elemCamera.setAttribute( QStringLiteral(
"z" ), mCenterPoint.
z() );
28 elemCamera.setAttribute( QStringLiteral(
"dist" ), mDistanceFromCenterPoint );
29 elemCamera.setAttribute( QStringLiteral(
"pitch" ), mPitchAngle );
30 elemCamera.setAttribute( QStringLiteral(
"heading" ), mHeadingAngle );
36 const double x = elem.attribute( QStringLiteral(
"x" ) ).toDouble();
37 const double y = elem.attribute( QStringLiteral(
"y" ) ).toDouble();
38 const double z = elem.attribute( QStringLiteral(
"z" ) ).toDouble();
41 mDistanceFromCenterPoint = elem.attribute( QStringLiteral(
"dist" ) ).toFloat();
42 mPitchAngle = elem.attribute( QStringLiteral(
"pitch" ) ).toFloat();
43 mHeadingAngle = elem.attribute( QStringLiteral(
"heading" ) ).toFloat();
49 if ( std::isnan( point.
x() ) || std::isnan( point.
y() ) || std::isnan( point.
z() ) )
50 qWarning() <<
"Not updating camera position: it cannot be NaN!";
57 mDistanceFromCenterPoint = std::max( distance, 10.0f );
67#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
68 mPitchAngle = std::clamp( pitch, 0.2f, 179.8f );
70 mPitchAngle = std::clamp( pitch, 0.0f, 180.0f );
78 QQuaternion q = QQuaternion::fromEulerAngles( 0, 0, mHeadingAngle ) * QQuaternion::fromEulerAngles( mPitchAngle, 0, 0 );
79 QVector3D cameraToCenter = q * QVector3D( 0, 0, -mDistanceFromCenterPoint );
80 camera->setUpVector( q * QVector3D( 0, 1, 0 ) );
81 camera->setPosition( mCenterPoint.
toVector3D() - cameraToCenter );
82 camera->setViewCenter( mCenterPoint.
toVector3D() );
void setPitchAngle(float pitch)
Sets pitch angle in degrees.
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element and returns it.
void setCenterPoint(const QgsVector3D &point)
Sets center point (towards which point the camera is looking)
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
void setDistanceFromCenterPoint(float distance)
Sets distance of the camera from the center point.
void updateCamera(Qt3DRender::QCamera *camera)
Update Qt3D camera view matrix based on the pose.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
QVector3D toVector3D() const
Converts the current object to QVector3D.
double x() const
Returns X coordinate.