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 );
 
   81  camera->setUpVector( QVector3D( 0, 0, -1 ) );
 
   82  camera->setPosition( QVector3D( mCenterPoint.
x(), mDistanceFromCenterPoint + mCenterPoint.
y(), mCenterPoint.
z() ) );
 
   83  camera->setViewCenter( QVector3D( mCenterPoint.
x(), mCenterPoint.
y(), mCenterPoint.
z() ) );
 
   84  camera->rotateAboutViewCenter( QQuaternion::fromEulerAngles( mPitchAngle, mHeadingAngle, 0 ) );
 
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.
 
double y() const
Returns Y coordinate.
 
double z() const
Returns Z coordinate.
 
double x() const
Returns X coordinate.