diff options
author | Andy Nichols <andy.nichols@qt.io> | 2018-01-23 10:00:46 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2018-01-23 10:07:17 +0100 |
commit | d6d1a9367f7a1e7b4dbe5c0400ae2148ed30fc6d (patch) | |
tree | 6a1b1ded546e8c48ce4f5012186089e8da87dab2 /src/render/frontend | |
parent | 598acd70a44f787a3e72c586576bfc028d5af02d (diff) | |
parent | 6b662b93048ee29d6684010cee7e59e9c4248bd1 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Change-Id: I2167d8d1d0050c7ca94180785a59f8753badaab4
Diffstat (limited to 'src/render/frontend')
-rw-r--r-- | src/render/frontend/qcamera.cpp | 67 | ||||
-rw-r--r-- | src/render/frontend/qcamera_p.h | 8 |
2 files changed, 52 insertions, 23 deletions
diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp index 13d689e0e..73ec2c71f 100644 --- a/src/render/frontend/qcamera.cpp +++ b/src/render/frontend/qcamera.cpp @@ -59,7 +59,28 @@ QCameraPrivate::QCameraPrivate() , m_lens(new QCameraLens()) , m_transform(new Qt3DCore::QTransform()) { - updateViewMatrix(); + updateViewMatrixAndTransform(false); +} + +void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) +{ + Q_Q(QCamera); + + const QVector3D viewDirection = (m_viewCenter - m_position).normalized(); + + QMatrix4x4 transformMatrix; + transformMatrix.translate(m_position); + + // Negative viewDirection because OpenGL convention is looking down -Z + transformMatrix.rotate(QQuaternion::fromDirection(-viewDirection, m_upVector.normalized())); + + m_transform->setMatrix(transformMatrix); + + QMatrix4x4 viewMatrix; + viewMatrix.lookAt(m_position, m_viewCenter, m_upVector); + m_viewMatrix = viewMatrix; + if (doEmit) + emit q->viewMatrixChanged(); } /*! @@ -292,29 +313,35 @@ QCameraPrivate::QCameraPrivate() /*! * \qmlproperty vector3d Qt3D.Render::Camera::position - * Holds the current position of the camera. + * Holds the current position of the camera in coordinates relative to + * the parent entity. */ /*! * \qmlproperty vector3d Qt3D.Render::Camera::upVector - * Holds the current up vector of the camera. + * Holds the current up vector of the camera in coordinates relative to + * the parent entity. */ /*! * \qmlproperty vector3d Qt3D.Render::Camera::viewCenter - * Holds the current view center of the camera. + * Holds the current view center of the camera in coordinates relative to + * the parent entity. * \readonly */ /*! * \qmlproperty vector3d Qt3D.Render::Camera::viewVector - * Holds the camera's view vector. + * Holds the camera's view vector in coordinates relative to + * the parent entity. * \readonly */ /*! * \qmlproperty matrix4x4 Qt3D.Render::Camera::viewMatrix - * Holds the camera's view matrix. + * \deprecated + * Holds the camera's view matrix in coordinates relative + * to the parent entity. * \readonly */ @@ -384,27 +411,33 @@ QCameraPrivate::QCameraPrivate() /*! * \property QCamera::position - * Holds the camera's position. + * Holds the camera's position in coordinates relative to + * the parent entity. */ /*! * \property QCamera::upVector - * Holds the camera's up vector. + * Holds the camera's up vector in coordinates relative to + * the parent entity. */ /*! * \property QCamera::viewCenter - * Holds the camera's view center. + * Holds the camera's view center in coordinates relative to + * the parent entity. */ /*! * \property QCamera::viewVector - * Holds the camera's view vector. + * Holds the camera's view vector in coordinates relative to + * the parent entity. */ /*! * \property QCamera::viewMatrix - * Holds the camera's view matrix. + * \deprecated + * Holds the camera's view matrix in coordinates relative to + * the parent entity. */ /*! @@ -426,7 +459,7 @@ QCamera::QCamera(Qt3DCore::QNode *parent) QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged(const QMatrix4x4 &)), this, SIGNAL(projectionMatrixChanged(const QMatrix4x4 &))); QObject::connect(d_func()->m_lens, SIGNAL(exposureChanged(float)), this, SIGNAL(exposureChanged(float))); QObject::connect(d_func()->m_lens, &QCameraLens::viewSphere, this, &QCamera::viewSphere); - QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(viewMatrixChanged())); + addComponent(d_func()->m_lens); addComponent(d_func()->m_transform); } @@ -455,7 +488,7 @@ QCamera::QCamera(QCameraPrivate &dd, Qt3DCore::QNode *parent) QObject::connect(d_func()->m_lens, SIGNAL(topChanged(float)), this, SIGNAL(topChanged(float))); QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged(const QMatrix4x4 &)), this, SIGNAL(projectionMatrixChanged(const QMatrix4x4 &))); QObject::connect(d_func()->m_lens, &QCameraLens::viewSphere, this, &QCamera::viewSphere); - QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(viewMatrixChanged())); + addComponent(d_func()->m_lens); addComponent(d_func()->m_transform); } @@ -894,7 +927,7 @@ void QCamera::setPosition(const QVector3D &position) d->m_viewMatrixDirty = true; emit positionChanged(position); emit viewVectorChanged(d->m_cameraToCenter); - d->updateViewMatrix(); + d->updateViewMatrixAndTransform(); } } @@ -914,7 +947,7 @@ void QCamera::setUpVector(const QVector3D &upVector) d->m_upVector = upVector; d->m_viewMatrixDirty = true; emit upVectorChanged(upVector); - d->updateViewMatrix(); + d->updateViewMatrixAndTransform(); } } @@ -936,7 +969,7 @@ void QCamera::setViewCenter(const QVector3D &viewCenter) d->m_viewMatrixDirty = true; emit viewCenterChanged(viewCenter); emit viewVectorChanged(d->m_cameraToCenter); - d->updateViewMatrix(); + d->updateViewMatrixAndTransform(); } } @@ -955,7 +988,7 @@ QVector3D QCamera::viewVector() const QMatrix4x4 QCamera::viewMatrix() const { Q_D(const QCamera); - return d->m_transform->matrix(); + return d->m_viewMatrix; } } // Qt3DRender diff --git a/src/render/frontend/qcamera_p.h b/src/render/frontend/qcamera_p.h index 2ef53818c..1e8464d05 100644 --- a/src/render/frontend/qcamera_p.h +++ b/src/render/frontend/qcamera_p.h @@ -67,12 +67,7 @@ public: Q_DECLARE_PUBLIC(QCamera) - void updateViewMatrix() - { - QMatrix4x4 m; - m.lookAt(m_position, m_viewCenter, m_upVector); - m_transform->setMatrix(m); - } + void updateViewMatrixAndTransform(bool doEmit = true); QVector3D m_position; QVector3D m_viewCenter; @@ -84,6 +79,7 @@ public: // Components QCameraLens *m_lens; Qt3DCore::QTransform *m_transform; + QMatrix4x4 m_viewMatrix; }; } // namespace Qt3DRender |