summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2015-03-12 10:54:22 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2015-03-12 08:23:10 +0000
commitfad6a4ed38a52693fd4bbfbadd71458a27c96ad2 (patch)
tree42de43f80ba790cf852acc30526a3216b3c6a977 /src
parentce0ab1fd2dc9a6b9cec63a3aed6b4b599fcd77b4 (diff)
[QCamera] Minor refactoring & clean-up
This is a preparation step for dropping QLookAtTransform. Also get rid of unused viewVector and matrix properties. Change-Id: I48e2be2c63f8eb6f7fafc63ea470721ac14d14f9 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/core-components/qcamera.cpp76
-rw-r--r--src/core/core-components/qcamera.h13
-rw-r--r--src/core/core-components/qcamera_p.h3
3 files changed, 27 insertions, 65 deletions
diff --git a/src/core/core-components/qcamera.cpp b/src/core/core-components/qcamera.cpp
index c96f58db6..6ca15a7bc 100644
--- a/src/core/core-components/qcamera.cpp
+++ b/src/core/core-components/qcamera.cpp
@@ -36,9 +36,6 @@
#include "qcamera.h"
#include "qcamera_p.h"
-#include "qcameralens.h"
-#include <qtransform.h>
-#include <qlookattransform.h>
QT_BEGIN_NAMESPACE
@@ -67,9 +64,7 @@ QCamera::QCamera(QNode *parent) :
QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged()), this, SIGNAL(projectionMatrixChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(positionChanged()), this, SIGNAL(positionChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(upVectorChanged()), this, SIGNAL(upVectorChanged()));
- QObject::connect(d_func()->m_lookAt, SIGNAL(viewVectorChanged()), this, SIGNAL(viewVectorChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(viewCenterChanged()), this, SIGNAL(viewCenterChanged()));
- QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(matrixChanged()));
d_func()->m_transform->addTransform(d_func()->m_lookAt);
addComponent(d_func()->m_lens);
addComponent(d_func()->m_transform);
@@ -90,9 +85,7 @@ QCamera::QCamera(QCameraPrivate &dd, QNode *parent)
QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged()), this, SIGNAL(projectionMatrixChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(positionChanged()), this, SIGNAL(positionChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(upVectorChanged()), this, SIGNAL(upVectorChanged()));
- QObject::connect(d_func()->m_lookAt, SIGNAL(viewVectorChanged()), this, SIGNAL(viewVectorChanged()));
QObject::connect(d_func()->m_lookAt, SIGNAL(viewCenterChanged()), this, SIGNAL(viewCenterChanged()));
- QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(matrixChanged()));
d_func()->m_transform->addTransform(d_func()->m_lookAt);
addComponent(d_func()->m_lens);
addComponent(d_func()->m_transform);
@@ -118,32 +111,32 @@ QLookAtTransform *QCamera::lookAt() const
void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option )
{
- Q_D(QCamera);
+ QVector3D viewVector = viewCenter() - position(); // From "camera" position to view center
// Calculate the amount to move by in world coordinates
QVector3D vWorld;
if ( !qFuzzyIsNull( vLocal.x() ) )
{
// Calculate the vector for the local x axis
- QVector3D x = QVector3D::crossProduct(d->m_lookAt->viewVector(), d->m_lookAt->upVector()).normalized();
+ QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
vWorld += vLocal.x() * x;
}
if ( !qFuzzyIsNull( vLocal.y() ) )
- vWorld += vLocal.y() * d->m_lookAt->upVector();
+ vWorld += vLocal.y() * upVector();
if ( !qFuzzyIsNull( vLocal.z() ) )
- vWorld += vLocal.z() * d->m_lookAt->viewVector().normalized();
+ vWorld += vLocal.z() * viewVector.normalized();
// Update the camera position using the calculated world vector
- d->m_lookAt->setPosition(d->m_lookAt->position() + vWorld);
+ setPosition(position() + vWorld);
// May be also update the view center coordinates
if ( option == TranslateViewCenter )
- d->m_lookAt->setViewCenter(d->m_lookAt->viewCenter() + vWorld);
+ setViewCenter(viewCenter() + vWorld);
// Refresh the camera -> view center vector
- d->m_lookAt->setViewVector(d->m_lookAt->viewCenter() - d->m_lookAt->position());
+ viewVector = viewCenter() - position();
// Calculate a new up vector. We do this by:
// 1) Calculate a new local x-direction vector from the cross product of the new
@@ -151,43 +144,36 @@ void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option
// 2) The local x vector is the normal to the plane in which the new up vector
// must lay. So we can take the cross product of this normal and the new
// x vector. The new normal vector forms the last part of the orthonormal basis
- QVector3D x = QVector3D::crossProduct( d->m_lookAt->viewVector(), d->m_lookAt->upVector() ).normalized();
- d->m_lookAt->setUpVector(QVector3D::crossProduct( x, d->m_lookAt->viewVector() ).normalized());
+ QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
+ setUpVector(QVector3D::crossProduct(x, viewVector).normalized());
}
void QCamera::translateWorld(const QVector3D& vWorld , CameraTranslationOption option )
{
- Q_D(QCamera);
-
// Update the camera position using the calculated world vector
- d->m_lookAt->setPosition(d->m_lookAt->position() + vWorld);
+ setPosition(position() + vWorld);
// May be also update the view center coordinates
if ( option == TranslateViewCenter )
- d->m_lookAt->setViewCenter(d->m_lookAt->viewCenter() + vWorld);
-
- // Refresh the camera -> view center vector
- d->m_lookAt->setViewVector(d->m_lookAt->viewCenter() - d->m_lookAt->position());
+ setViewCenter(viewCenter() + vWorld);
}
QQuaternion QCamera::tiltRotation(float angle) const
{
- Q_D(const QCamera);
- QVector3D xBasis = QVector3D::crossProduct( d->m_lookAt->upVector(),
- d->m_lookAt->viewVector().normalized() ).normalized();
+ QVector3D viewVector = viewCenter() - position();
+ QVector3D xBasis = QVector3D::crossProduct(upVector(), viewVector.normalized()).normalized();
return QQuaternion::fromAxisAndAngle( xBasis, -angle );
}
QQuaternion QCamera::panRotation(float angle) const
{
- Q_D(const QCamera);
- return QQuaternion::fromAxisAndAngle( d->m_lookAt->upVector(), angle );
+ return QQuaternion::fromAxisAndAngle(upVector(), angle);
}
QQuaternion QCamera::rollRotation(float angle) const
{
- Q_D(const QCamera);
- return QQuaternion::fromAxisAndAngle( d->m_lookAt->viewVector(), -angle );
+ QVector3D viewVector = viewCenter() - position();
+ return QQuaternion::fromAxisAndAngle(viewVector, -angle);
}
void QCamera::tilt( const float& angle )
@@ -228,19 +214,19 @@ void QCamera::rollAboutViewCenter( const float& angle )
void QCamera::rotate( const QQuaternion& q )
{
- Q_D(QCamera);
- d->m_lookAt->setUpVector(q.rotatedVector(d->m_lookAt->upVector()));
- QVector3D cameraToCenter = q.rotatedVector(d->m_lookAt->viewVector());
- d->m_lookAt->setViewCenter(d->m_lookAt->position() + cameraToCenter);
+ setUpVector(q * upVector());
+ QVector3D viewVector = viewCenter() - position();
+ QVector3D cameraToCenter = q * viewVector;
+ setViewCenter(position() + cameraToCenter);
}
void QCamera::rotateAboutViewCenter( const QQuaternion& q )
{
- Q_D(QCamera);
- d->m_lookAt->setUpVector(q.rotatedVector(d->m_lookAt->upVector()));
- QVector3D cameraToCenter = q.rotatedVector(d->m_lookAt->viewVector());
- d->m_lookAt->setPosition(d->m_lookAt->viewCenter() - cameraToCenter);
- d->m_lookAt->setViewCenter(d->m_lookAt->position() + cameraToCenter);
+ setUpVector(q * upVector());
+ QVector3D viewVector = viewCenter() - position();
+ QVector3D cameraToCenter = q * viewVector;
+ setPosition(viewCenter() - cameraToCenter);
+ setViewCenter(position() + cameraToCenter);
}
void QCamera::setProjectionType(QCameraLens::ProjectionType type)
@@ -394,18 +380,6 @@ QVector3D QCamera::viewCenter() const
return d->m_lookAt->viewCenter();
}
-QVector3D QCamera::viewVector() const
-{
- Q_D(const QCamera);
- return d->m_lookAt->viewVector();
-}
-
-QMatrix4x4 QCamera::matrix() const
-{
- Q_D(const QCamera);
- return d->m_transform->matrix();
-}
-
} // Qt3D
QT_END_NAMESPACE
diff --git a/src/core/core-components/qcamera.h b/src/core/core-components/qcamera.h
index edb8598e0..9c3ac338f 100644
--- a/src/core/core-components/qcamera.h
+++ b/src/core/core-components/qcamera.h
@@ -38,9 +38,7 @@
#define QT3D_CAMERA_H
#include <Qt3DCore/qentity.h>
-#include <Qt3DCore/qt3dcore_global.h>
#include <Qt3DCore/qcameralens.h>
-#include <Qt3DCore/qlookattransform.h>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector3D>
@@ -49,9 +47,10 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
-class QCameraPrivate;
+class QLookAtTransform;
class QTransform;
+class QCameraPrivate;
class QT3DCORESHARED_EXPORT QCamera : public QEntity
{
Q_OBJECT
@@ -70,8 +69,6 @@ class QT3DCORESHARED_EXPORT QCamera : public QEntity
Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(QVector3D upVector READ upVector WRITE setUpVector NOTIFY upVectorChanged)
Q_PROPERTY(QVector3D viewCenter READ viewCenter WRITE setViewCenter NOTIFY viewCenterChanged)
- Q_PROPERTY(QVector3D viewVector READ viewVector NOTIFY viewVectorChanged)
- Q_PROPERTY(QMatrix4x4 matrix READ matrix NOTIFY matrixChanged)
public:
explicit QCamera(QNode *parent = 0);
@@ -145,10 +142,6 @@ public:
void setViewCenter(const QVector3D &viewCenter);
QVector3D viewCenter() const;
- QVector3D viewVector() const;
-
- QMatrix4x4 matrix() const;
-
Q_SIGNALS:
void projectionTypeChanged();
void nearPlaneChanged();
@@ -163,8 +156,6 @@ Q_SIGNALS:
void positionChanged();
void upVectorChanged();
void viewCenterChanged();
- void viewVectorChanged();
- void matrixChanged();
protected:
Q_DECLARE_PRIVATE(QCamera)
diff --git a/src/core/core-components/qcamera_p.h b/src/core/core-components/qcamera_p.h
index 05e3a9ecf..e0b4c332d 100644
--- a/src/core/core-components/qcamera_p.h
+++ b/src/core/core-components/qcamera_p.h
@@ -37,9 +37,6 @@
#ifndef QT3D_CAMERA_P_H
#define QT3D_CAMERA_P_H
-#include <QMatrix4x4>
-#include <QVector3D>
-
#include <Qt3DCore/qcameralens.h>
#include <Qt3DCore/qlookattransform.h>
#include <Qt3DCore/qtransform.h>