QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgscamerapose.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscamerapose.cpp
3  --------------------------------------
4  Date : July 2018
5  Copyright : (C) 2018 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgscamerapose.h"
17 
18 #include <Qt3DRender/QCamera>
19 
20 #include <QDomDocument>
21 
22 QDomElement QgsCameraPose::writeXml( QDomDocument &doc ) const
23 {
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 );
31  return elemCamera;
32 }
33 
34 void QgsCameraPose::readXml( const QDomElement &elem )
35 {
36  double x = elem.attribute( QStringLiteral( "x" ) ).toDouble();
37  double y = elem.attribute( QStringLiteral( "y" ) ).toDouble();
38  double z = elem.attribute( QStringLiteral( "z" ) ).toDouble();
39  mCenterPoint = QgsVector3D( x, y, z );
40 
41  mDistanceFromCenterPoint = elem.attribute( QStringLiteral( "dist" ) ).toFloat();
42  mPitchAngle = elem.attribute( QStringLiteral( "pitch" ) ).toFloat();
43  mHeadingAngle = elem.attribute( QStringLiteral( "heading" ) ).toFloat();
44 }
45 
46 void QgsCameraPose::updateCamera( Qt3DRender::QCamera *camera )
47 {
48  // basic scene setup:
49  // - x grows to the right
50  // - z grows to the bottom
51  // - y grows towards camera
52  // so a point on the plane (x',y') is transformed to (x,-z) in our 3D world
53  camera->setUpVector( QVector3D( 0, 0, -1 ) );
54  camera->setPosition( QVector3D( mCenterPoint.x(), mDistanceFromCenterPoint + mCenterPoint.y(), mCenterPoint.z() ) );
55  camera->setViewCenter( QVector3D( mCenterPoint.x(), mCenterPoint.y(), mCenterPoint.z() ) );
56  camera->rotateAboutViewCenter( QQuaternion::fromEulerAngles( mPitchAngle, mHeadingAngle, 0 ) );
57 }
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:31
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written using writeXml()
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a new DOM element and returns it.
void updateCamera(Qt3DRender::QCamera *camera)
Update Qt3D camera view matrix based on the pose.
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49