summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-01-15 15:09:44 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-01-16 17:17:49 +0000
commitb0404a42ced2ea5a583e1c6ddc22940ffdc1e48e (patch)
treeb073c3c680e388bda00228b204743b092b11de6a /src/render
parent8656b95ffb67efe7dd1cc3a65b12d277e83e1d22 (diff)
Move QCamera/QCameraLens to Qt3DRender
Also get rid of Qt3DRender::QWindow and of the hard codes camera controller. Change-Id: I307735d01caf97b7a690b28de8dc99fc9866c35f Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render')
-rw-r--r--src/render/backend/cameralens.cpp2
-rw-r--r--src/render/backend/entity.cpp2
-rw-r--r--src/render/backend/renderer.cpp2
-rw-r--r--src/render/frontend/qcamera.cpp486
-rw-r--r--src/render/frontend/qcamera.h173
-rw-r--r--src/render/frontend/qcamera_p.h (renamed from src/render/frontend/qwindow_p.h)55
-rw-r--r--src/render/frontend/qcameralens.cpp476
-rw-r--r--src/render/frontend/qcameralens.h137
-rw-r--r--src/render/frontend/qcameralens_p.h129
-rw-r--r--src/render/frontend/qrenderaspect.cpp4
-rw-r--r--src/render/frontend/qwindow.cpp188
-rw-r--r--src/render/frontend/qwindow.h84
-rw-r--r--src/render/frontend/render-frontend.pri13
13 files changed, 1442 insertions, 309 deletions
diff --git a/src/render/backend/cameralens.cpp b/src/render/backend/cameralens.cpp
index 3d039f298..34ba8f399 100644
--- a/src/render/backend/cameralens.cpp
+++ b/src/render/backend/cameralens.cpp
@@ -38,7 +38,7 @@
#include <Qt3DRender/private/renderlogging_p.h>
#include <Qt3DCore/qtransform.h>
-#include <Qt3DCore/qcameralens.h>
+#include <Qt3DRender/qcameralens.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DCore/qscenepropertychange.h>
diff --git a/src/render/backend/entity.cpp b/src/render/backend/entity.cpp
index e1fc32160..36e7654b3 100644
--- a/src/render/backend/entity.cpp
+++ b/src/render/backend/entity.cpp
@@ -50,7 +50,7 @@
#include <Qt3DRender/qcomputejob.h>
#include <Qt3DRender/private/geometryrenderermanager_p.h>
-#include <Qt3DCore/qcameralens.h>
+#include <Qt3DRender/qcameralens.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DCore/qscenepropertychange.h>
#include <Qt3DCore/qtransform.h>
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index aa511fc70..81bf16a18 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -77,7 +77,7 @@
#include <Qt3DRender/private/geometryrenderermanager_p.h>
#include <Qt3DRender/private/openglvertexarrayobject_p.h>
-#include <Qt3DCore/qcameralens.h>
+#include <Qt3DRender/qcameralens.h>
#include <Qt3DCore/private/qeventfilterservice_p.h>
#include <Qt3DCore/private/qabstractaspectjobmanager_p.h>
diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp
new file mode 100644
index 000000000..e2aa2f4e1
--- /dev/null
+++ b/src/render/frontend/qcamera.cpp
@@ -0,0 +1,486 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcamera.h"
+#include "qcamera_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+/*!
+ \class Qt3DRender::QCameraPrivate
+ \internal
+*/
+QCameraPrivate::QCameraPrivate()
+ : Qt3DCore::QEntityPrivate()
+ , m_position(0.0f, 0.0f, 0.0f)
+ , m_viewCenter(0.0f, 0.0f, -100.0f)
+ , m_upVector(0.0f, 1.0f, 0.0f)
+ , m_cameraToCenter(m_viewCenter - m_position)
+ , m_viewMatrixDirty(false)
+ , m_lens(new QCameraLens())
+ , m_transform(new Qt3DCore::QTransform())
+{
+}
+
+/*!
+ \qmltype Camera
+ \instantiates Qt3DRender::QCamera
+ \inherits Entity
+ \inqmlmodule Qt3D.Core
+ \since 5.5
+*/
+
+QCamera::QCamera(Qt3DCore::QNode *parent)
+ : Qt3DCore::QEntity(*new QCameraPrivate, parent)
+{
+ QObject::connect(d_func()->m_lens, SIGNAL(projectionTypeChanged(QCameraLens::ProjectionType)), this, SIGNAL(projectionTypeChanged(QCameraLens::ProjectionType)));
+ QObject::connect(d_func()->m_lens, SIGNAL(nearPlaneChanged(float)), this, SIGNAL(nearPlaneChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(farPlaneChanged(float)), this, SIGNAL(farPlaneChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(fieldOfViewChanged(float)), this, SIGNAL(fieldOfViewChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(aspectRatioChanged(float)), this, SIGNAL(aspectRatioChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(leftChanged(float)), this, SIGNAL(leftChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(rightChanged(float)), this, SIGNAL(rightChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(bottomChanged(float)), this, SIGNAL(bottomChanged(float)));
+ 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_transform, SIGNAL(matrixChanged(const QMatrix4x4 &)), this, SIGNAL(viewMatrixChanged(const QMatrix4x4 &)));
+ addComponent(d_func()->m_lens);
+ addComponent(d_func()->m_transform);
+}
+
+QCamera::~QCamera()
+{
+ QNode::cleanup();
+}
+
+/*! \internal */
+QCamera::QCamera(QCameraPrivate &dd, Qt3DCore::QNode *parent)
+ : Qt3DCore::QEntity(dd, parent)
+{
+ QObject::connect(d_func()->m_lens, SIGNAL(projectionTypeChanged(QCameraLens::ProjectionType)), this, SIGNAL(projectionTypeChanged(QCameraLens::ProjectionType)));
+ QObject::connect(d_func()->m_lens, SIGNAL(nearPlaneChanged(float)), this, SIGNAL(nearPlaneChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(farPlaneChanged(float)), this, SIGNAL(farPlaneChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(fieldOfViewChanged(float)), this, SIGNAL(fieldOfViewChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(aspectRatioChanged(float)), this, SIGNAL(aspectRatioChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(leftChanged(float)), this, SIGNAL(leftChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(rightChanged(float)), this, SIGNAL(rightChanged(float)));
+ QObject::connect(d_func()->m_lens, SIGNAL(bottomChanged(float)), this, SIGNAL(bottomChanged(float)));
+ 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_transform, SIGNAL(matrixChanged(const QMatrix4x4 &)), this, SIGNAL(viewMatrixChanged(const QMatrix4x4 &)));
+ addComponent(d_func()->m_lens);
+ addComponent(d_func()->m_transform);
+}
+
+QCameraLens *QCamera::lens() const
+{
+ Q_D(const QCamera);
+ return d->m_lens;
+}
+
+Qt3DCore::QTransform *QCamera::transform() const
+{
+ Q_D(const QCamera);
+ return d->m_transform;
+}
+
+void QCamera::translate(const QVector3D &vLocal, CameraTranslationOption option)
+{
+ 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
+ const QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
+ vWorld += vLocal.x() * x;
+ }
+
+ if (!qFuzzyIsNull(vLocal.y()))
+ vWorld += vLocal.y() * upVector();
+
+ if (!qFuzzyIsNull(vLocal.z()))
+ vWorld += vLocal.z() * viewVector.normalized();
+
+ // Update the camera position using the calculated world vector
+ setPosition(position() + vWorld);
+
+ // May be also update the view center coordinates
+ if (option == TranslateViewCenter)
+ setViewCenter(viewCenter() + vWorld);
+
+ // Refresh the camera -> view center vector
+ 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
+ // camera to view center vector and the old up vector.
+ // 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
+ const QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized();
+ setUpVector(QVector3D::crossProduct(x, viewVector).normalized());
+}
+
+void QCamera::translateWorld(const QVector3D &vWorld, CameraTranslationOption option)
+{
+ // Update the camera position using the calculated world vector
+ setPosition(position() + vWorld);
+
+ // May be also update the view center coordinates
+ if (option == TranslateViewCenter)
+ setViewCenter(viewCenter() + vWorld);
+}
+
+QQuaternion QCamera::tiltRotation(float angle) const
+{
+ const QVector3D viewVector = viewCenter() - position();
+ const QVector3D xBasis = QVector3D::crossProduct(upVector(), viewVector.normalized()).normalized();
+ return QQuaternion::fromAxisAndAngle(xBasis, -angle);
+}
+
+QQuaternion QCamera::panRotation(float angle) const
+{
+ return QQuaternion::fromAxisAndAngle(upVector(), angle);
+}
+
+QQuaternion QCamera::rollRotation(float angle) const
+{
+ QVector3D viewVector = viewCenter() - position();
+ return QQuaternion::fromAxisAndAngle(viewVector, -angle);
+}
+
+QQuaternion QCamera::rotation(float angle, const QVector3D &axis) const
+{
+ return QQuaternion::fromAxisAndAngle(axis, angle);
+}
+
+void QCamera::tilt(float angle)
+{
+ QQuaternion q = tiltRotation(angle);
+ rotate(q);
+}
+
+void QCamera::pan(float angle)
+{
+ QQuaternion q = panRotation(-angle);
+ rotate(q);
+}
+
+void QCamera::pan(float angle, const QVector3D &axis)
+{
+ QQuaternion q = rotation(-angle, axis);
+ rotate(q);
+}
+
+void QCamera::roll(float angle)
+{
+ QQuaternion q = rollRotation(-angle);
+ rotate(q);
+}
+
+void QCamera::tiltAboutViewCenter(float angle)
+{
+ QQuaternion q = tiltRotation(-angle);
+ rotateAboutViewCenter(q);
+}
+
+void QCamera::panAboutViewCenter(float angle)
+{
+ QQuaternion q = panRotation(angle);
+ rotateAboutViewCenter(q);
+}
+
+void QCamera::panAboutViewCenter(float angle, const QVector3D &axis)
+{
+ QQuaternion q = rotation(angle, axis);
+ rotateAboutViewCenter(q);
+}
+
+void QCamera::rollAboutViewCenter(float angle)
+{
+ QQuaternion q = rollRotation(angle);
+ rotateAboutViewCenter(q);
+}
+
+void QCamera::rotate(const QQuaternion& q)
+{
+ setUpVector(q * upVector());
+ QVector3D viewVector = viewCenter() - position();
+ QVector3D cameraToCenter = q * viewVector;
+ setViewCenter(position() + cameraToCenter);
+}
+
+void QCamera::rotateAboutViewCenter(const QQuaternion& q)
+{
+ setUpVector(q * upVector());
+ QVector3D viewVector = viewCenter() - position();
+ QVector3D cameraToCenter = q * viewVector;
+ setPosition(viewCenter() - cameraToCenter);
+ setViewCenter(position() + cameraToCenter);
+}
+
+void QCamera::setProjectionType(QCameraLens::ProjectionType type)
+{
+ Q_D(QCamera);
+ d->m_lens->setProjectionType(type);
+}
+
+/*!
+ \qmlproperty enumeration Qt3DCore::Camera::projectionType
+
+ Holds the type of the camera projection (orthogonal or perspective).
+
+ \value CameraLens.OrthographicProjection Orthographic projection
+ \value CameraLens.PerspectiveProjection Perspective projection
+*/
+QCameraLens::ProjectionType QCamera::projectionType() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->projectionType();
+}
+
+void QCamera::setNearPlane(float nearPlane)
+{
+ Q_D(QCamera);
+ d->m_lens->setNearPlane(nearPlane);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::nearPlane
+*/
+float QCamera::nearPlane() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->nearPlane();
+}
+
+void QCamera::setFarPlane(float farPlane)
+{
+ Q_D(QCamera);
+ d->m_lens->setFarPlane(farPlane);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::farPlane
+*/
+float QCamera::farPlane() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->farPlane();
+}
+
+void QCamera::setFieldOfView(float fieldOfView)
+{
+ Q_D(QCamera);
+ d->m_lens->setFieldOfView(fieldOfView);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::fieldOfView
+*/
+float QCamera::fieldOfView() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->fieldOfView();
+}
+
+void QCamera::setAspectRatio(float aspectRatio)
+{
+ Q_D(QCamera);
+ d->m_lens->setAspectRatio(aspectRatio);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::aspectRatio
+*/
+float QCamera::aspectRatio() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->aspectRatio();
+}
+
+void QCamera::setLeft(float left)
+{
+ Q_D(QCamera);
+ d->m_lens->setLeft(left);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::left
+*/
+float QCamera::left() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->left();
+}
+
+void QCamera::setRight(float right)
+{
+ Q_D(QCamera);
+ d->m_lens->setRight(right);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::right
+*/
+float QCamera::right() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->right();
+}
+
+void QCamera::setBottom(float bottom)
+{
+ Q_D(QCamera);
+ d->m_lens->setBottom(bottom);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::bottom
+*/
+float QCamera::bottom() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->bottom();
+}
+
+void QCamera::setTop(float top)
+{
+ Q_D(QCamera);
+ d->m_lens->setTop(top);
+}
+
+/*!
+ \qmlproperty float Qt3DCore::Camera::top
+*/
+float QCamera::top() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->top();
+}
+
+/*!
+ \qmlproperty matrix4x4 Qt3DCore::Camera::projectionMatrix
+ \readonly
+*/
+QMatrix4x4 QCamera::projectionMatrix() const
+{
+ Q_D(const QCamera);
+ return d->m_lens->projectionMatrix();
+}
+
+void QCamera::setPosition(const QVector3D &position)
+{
+ Q_D(QCamera);
+ d->m_position = position;
+ d->m_cameraToCenter = d->m_viewCenter - position;
+ d->m_viewMatrixDirty = true;
+ emit positionChanged(position);
+ emit viewVectorChanged(d->m_cameraToCenter);
+ d->updateViewMatrix();
+}
+
+/*!
+ \qmlproperty vector3d Qt3DCore::Camera::position
+*/
+QVector3D QCamera::position() const
+{
+ Q_D(const QCamera);
+ return d->m_position;
+}
+
+void QCamera::setUpVector(const QVector3D &upVector)
+{
+ Q_D(QCamera);
+ d->m_upVector = upVector;
+ d->m_viewMatrixDirty = true;
+ emit upVectorChanged(upVector);
+ d->updateViewMatrix();
+}
+
+/*!
+ \qmlproperty vector3d Qt3DCore::Camera::upVector
+*/
+QVector3D QCamera::upVector() const
+{
+ Q_D(const QCamera);
+ return d->m_upVector;
+}
+
+void QCamera::setViewCenter(const QVector3D &viewCenter)
+{
+ Q_D(QCamera);
+ d->m_viewCenter = viewCenter;
+ d->m_cameraToCenter = viewCenter - d->m_position;
+ d->m_viewMatrixDirty = true;
+ emit viewCenterChanged(viewCenter);
+ emit viewVectorChanged(d->m_cameraToCenter);
+ d->updateViewMatrix();
+}
+
+/*!
+ \qmlproperty vector3d Qt3DCore::Camera::viewCenter
+*/
+QVector3D QCamera::viewCenter() const
+{
+ Q_D(const QCamera);
+ return d->m_viewCenter;
+}
+
+/*!
+ \qmlproperty vector3d Qt3DCore::Camera::viewVector
+*/
+QVector3D QCamera::viewVector() const
+{
+ Q_D(const QCamera);
+ return d->m_cameraToCenter;
+}
+
+/*!
+ \qmlproperty matrix4x4 Qt3DCore::Camera::viewMatrix
+*/
+QMatrix4x4 QCamera::viewMatrix() const
+{
+ Q_D(const QCamera);
+ return d->m_transform->matrix();
+}
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/frontend/qcamera.h b/src/render/frontend/qcamera.h
new file mode 100644
index 000000000..737b7415a
--- /dev/null
+++ b/src/render/frontend/qcamera.h
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_CAMERA_H
+#define QT3DRENDER_CAMERA_H
+
+#include <Qt3DCore/qentity.h>
+#include <Qt3DRender/qt3drender_global.h>
+#include <Qt3DRender/qcameralens.h>
+#include <QMatrix4x4>
+#include <QQuaternion>
+#include <QVector3D>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+class QEntity;
+class QTransform;
+}
+
+namespace Qt3DRender {
+
+class QCameraPrivate;
+
+class QT3DRENDERSHARED_EXPORT QCamera : public Qt3DCore::QEntity
+{
+ Q_OBJECT
+ // CameraLens
+ Q_PROPERTY(Qt3DRender::QCameraLens::ProjectionType projectionType READ projectionType WRITE setProjectionType NOTIFY projectionTypeChanged)
+ Q_PROPERTY(float nearPlane READ nearPlane WRITE setNearPlane NOTIFY nearPlaneChanged)
+ Q_PROPERTY(float farPlane READ farPlane WRITE setFarPlane NOTIFY farPlaneChanged)
+ Q_PROPERTY(float fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
+ Q_PROPERTY(float aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
+ Q_PROPERTY(float left READ left WRITE setLeft NOTIFY leftChanged)
+ Q_PROPERTY(float right READ right WRITE setRight NOTIFY rightChanged)
+ Q_PROPERTY(float bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
+ Q_PROPERTY(float top READ top WRITE setTop NOTIFY topChanged)
+ Q_PROPERTY(QMatrix4x4 projectionMatrix READ projectionMatrix NOTIFY projectionMatrixChanged)
+ // LookAt
+ 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 viewMatrix READ viewMatrix NOTIFY viewMatrixChanged)
+
+public:
+ explicit QCamera(QNode *parent = 0);
+ ~QCamera();
+
+ enum CameraTranslationOption {
+ TranslateViewCenter,
+ DontTranslateViewCenter
+ };
+ Q_ENUM(CameraTranslationOption)
+
+ QCameraLens *lens() const;
+ Qt3DCore::QTransform *transform() const;
+
+ QQuaternion tiltRotation(float angle) const;
+ QQuaternion panRotation(float angle) const;
+ QQuaternion rollRotation(float angle) const;
+ QQuaternion rotation(float angle, const QVector3D &axis) const;
+
+ // Translate relative to camera orientation axes
+ Q_INVOKABLE void translate(const QVector3D& vLocal, CameraTranslationOption option = TranslateViewCenter);
+
+ // Translate relative to world axes
+ Q_INVOKABLE void translateWorld(const QVector3D& vWorld, CameraTranslationOption option = TranslateViewCenter);
+
+ Q_INVOKABLE void tilt(float angle);
+ Q_INVOKABLE void pan(float angle);
+ Q_INVOKABLE void pan(float angle, const QVector3D &axis);
+ Q_INVOKABLE void roll(float angle);
+
+ Q_INVOKABLE void tiltAboutViewCenter(float angle);
+ Q_INVOKABLE void panAboutViewCenter(float angle);
+ Q_INVOKABLE void panAboutViewCenter(float angle, const QVector3D &axis);
+ Q_INVOKABLE void rollAboutViewCenter(float angle);
+
+ Q_INVOKABLE void rotate(const QQuaternion& q);
+ Q_INVOKABLE void rotateAboutViewCenter(const QQuaternion& q);
+
+ QCameraLens::ProjectionType projectionType() const;
+ float nearPlane() const;
+ float farPlane() const;
+ float fieldOfView() const;
+ float aspectRatio() const;
+ float left() const;
+ float right() const;
+ float bottom() const;
+ float top() const;
+ QMatrix4x4 projectionMatrix() const;
+ QVector3D position() const;
+ QVector3D upVector() const;
+ QVector3D viewCenter() const;
+ QVector3D viewVector() const;
+ QMatrix4x4 viewMatrix() const;
+
+public Q_SLOTS:
+ void setProjectionType(QCameraLens::ProjectionType type);
+ void setNearPlane(float nearPlane);
+ void setFarPlane(float farPlane);
+ void setFieldOfView(float fieldOfView);
+ void setAspectRatio(float aspectRatio);
+ void setLeft(float left);
+ void setRight(float right);
+ void setBottom(float bottom);
+ void setTop(float top);
+ void setPosition(const QVector3D &position);
+ void setUpVector(const QVector3D &upVector);
+ void setViewCenter(const QVector3D &viewCenter);
+
+Q_SIGNALS:
+ void projectionTypeChanged(QCameraLens::ProjectionType projectionType);
+ void nearPlaneChanged(float nearPlane);
+ void farPlaneChanged(float farPlane);
+ void fieldOfViewChanged(float fieldOfView);
+ void aspectRatioChanged(float aspectRatio);
+ void leftChanged(float left);
+ void rightChanged(float right);
+ void bottomChanged(float bottom);
+ void topChanged(float top);
+ void projectionMatrixChanged(const QMatrix4x4 &projectionMatrix);
+ void positionChanged(const QVector3D &position);
+ void upVectorChanged(const QVector3D &upVector);
+ void viewCenterChanged(const QVector3D &viewCenter);
+ void viewVectorChanged(const QVector3D &viewVector);
+ void viewMatrixChanged(const QMatrix4x4 &viewMatrix);
+
+protected:
+ Q_DECLARE_PRIVATE(QCamera)
+ QT3D_CLONEABLE(QCamera)
+ QCamera(QCameraPrivate &dd, QNode *parent = 0);
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_CAMERA_H
diff --git a/src/render/frontend/qwindow_p.h b/src/render/frontend/qcamera_p.h
index b824bc787..5ecb1a047 100644
--- a/src/render/frontend/qwindow_p.h
+++ b/src/render/frontend/qcamera_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
@@ -34,8 +34,8 @@
**
****************************************************************************/
-#ifndef QT3DRENDER_QWINDOW_P_H
-#define QT3DRENDER_QWINDOW_P_H
+#ifndef QT3DRENDER_CAMERA_P_H
+#define QT3DRENDER_CAMERA_P_H
//
// W A R N I N G
@@ -48,41 +48,42 @@
// We mean it.
//
-#include <QtGui/private/qwindow_p.h>
+#include <Qt3DRender/qcameralens.h>
+#include <Qt3DCore/qtransform.h>
+#include <private/qentity_p.h>
QT_BEGIN_NAMESPACE
-namespace Qt3DCore {
-class QAspectEngine;
-class QCamera;
-class QEntity;
-}
-
namespace Qt3DRender {
-class QWindow;
-class QFrameGraph;
-class QRenderAspect;
-
-class QWindowPrivate : public ::QWindowPrivate
+class QCameraPrivate : public Qt3DCore::QEntityPrivate
{
public:
- QWindowPrivate();
+ QCameraPrivate();
+
+ Q_DECLARE_PUBLIC(QCamera)
+
+ void updateViewMatrix()
+ {
+ QMatrix4x4 m;
+ m.lookAt(m_position, m_viewCenter, m_upVector);
+ m_transform->setMatrix(m);
+ }
- Q_DECLARE_PUBLIC(QWindow)
- bool m_initialized;
- Qt3DCore::QEntity *m_root;
- Qt3DCore::QEntity * m_userRoot;
- Qt3DCore::QCamera *m_defaultCamera;
- QFrameGraph *m_frameGraph;
- QScopedPointer<Qt3DCore::QAspectEngine> m_engine;
- QRenderAspect *m_renderAspect;
+ QVector3D m_position;
+ QVector3D m_viewCenter;
+ QVector3D m_upVector;
+
+ QVector3D m_cameraToCenter; // The vector from the camera position to the view center
+ bool m_viewMatrixDirty;
+
+ // Components
+ QCameraLens *m_lens;
+ Qt3DCore::QTransform *m_transform;
};
} // namespace Qt3DRender
QT_END_NAMESPACE
-
-#endif // QT3DRENDER_QWINDOW_P_H
-
+#endif // QT3DRENDER_CAMERA_P_H
diff --git a/src/render/frontend/qcameralens.cpp b/src/render/frontend/qcameralens.cpp
new file mode 100644
index 000000000..3eb9619ec
--- /dev/null
+++ b/src/render/frontend/qcameralens.cpp
@@ -0,0 +1,476 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcameralens.h"
+#include "qcameralens_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+/*!
+ \class Qt3DRender::QCameraLensPrivate
+ \internal
+*/
+QCameraLensPrivate::QCameraLensPrivate()
+ : Qt3DCore::QComponentPrivate()
+ , m_projectionType(QCameraLens::OrthographicProjection)
+ , m_nearPlane(0.1f)
+ , m_farPlane(1024.0f)
+ , m_fieldOfView(25.0f)
+ , m_aspectRatio(1.0f)
+ , m_left(-0.5f)
+ , m_right(0.5f)
+ , m_bottom(-0.5f)
+ , m_top(0.5f)
+{
+}
+
+QCameraLens::QCameraLens(QNode *parent)
+ : Qt3DCore::QComponent(*new QCameraLensPrivate, parent)
+{
+ Q_D(QCameraLens);
+ d->updateProjectionMatrix();
+}
+
+QCameraLens::~QCameraLens()
+{
+ QNode::cleanup();
+}
+
+void QCameraLens::copy(const QNode *ref)
+{
+ QComponent::copy(ref);
+ const QCameraLens *lens = static_cast<const QCameraLens*>(ref);
+ d_func()->m_projectionType = lens->d_func()->m_projectionType;
+ d_func()->m_nearPlane = lens->d_func()->m_nearPlane;
+ d_func()->m_farPlane = lens->d_func()->m_farPlane;
+ d_func()->m_fieldOfView = lens->d_func()->m_fieldOfView;
+ d_func()->m_aspectRatio = lens->d_func()->m_aspectRatio;
+ d_func()->m_left = lens->d_func()->m_left;
+ d_func()->m_right = lens->d_func()->m_right;
+ d_func()->m_bottom = lens->d_func()->m_bottom;
+ d_func()->m_top = lens->d_func()->m_top;
+ d_func()->m_projectionMatrix = lens->d_func()->m_projectionMatrix;
+}
+
+/*! \class Qt3DRender::QCameraLens
+ * \inmodule Qt3DCore
+ *
+ * \brief Qt3DRender::QCameraLens specifies the projection matrix that will be used to
+ * define a Camera for a 3D scene.
+ *
+ * \since 5.5
+ */
+QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent)
+ : QComponent(dd, parent)
+{
+ Q_D(QCameraLens);
+ d->updateOrthographicProjection();
+}
+
+/*!
+ * Sets the lens' projection type \a projectionType.
+ *
+ * \note Qt3DRender::QCameraLens::Frustum and
+ * Qt3DRender::QCameraLens::PerspectiveProjection are two different ways of
+ * specifying the same projection.
+ */
+void QCameraLens::setProjectionType(QCameraLens::ProjectionType projectionType)
+{
+ Q_D(QCameraLens);
+ if (d->m_projectionType != projectionType) {
+ d->m_projectionType = projectionType;
+ emit projectionTypeChanged(projectionType);
+ d->updateProjectionMatrix();
+ }
+}
+
+/*!
+ * Returns the lens' projection type.
+ */
+QCameraLens::ProjectionType QCameraLens::projectionType() const
+{
+ Q_D(const QCameraLens);
+ return d->m_projectionType;
+}
+
+/*!
+ * Defines an orthographic projection based on \a left, \a right, \a bottom, \a
+ * top, \a nearPlane, \a farPlane.
+ */
+void QCameraLens::setOrthographicProjection(float left, float right,
+ float bottom, float top,
+ float nearPlane, float farPlane)
+{
+ Q_D(QCameraLens);
+ bool block = blockNotifications(true);
+ setLeft(left);
+ setRight(right);
+ setBottom(bottom);
+ setTop(top);
+ setNearPlane(nearPlane);
+ setFarPlane(farPlane);
+ setProjectionType(OrthographicProjection);
+ blockNotifications(block);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Defines an orthographic projection based on \a left, \a right, \a bottom, \a
+ * top, \a nearPlane, \a farPlane.
+ */
+void QCameraLens::setFrustumProjection(float left, float right,
+ float bottom, float top,
+ float nearPlane, float farPlane)
+{
+ Q_D(QCameraLens);
+ bool block = blockNotifications(true);
+ setLeft(left);
+ setRight(right);
+ setBottom(bottom);
+ setTop(top);
+ setNearPlane(nearPlane);
+ setFarPlane(farPlane);
+ setProjectionType(FrustumProjection);
+ blockNotifications(block);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Defines a perspective projection based on \a fieldOfView, \a aspectRatio, \a
+ * nearPlane, \a farPlane.
+ */
+void QCameraLens::setPerspectiveProjection(float fieldOfView, float aspectRatio,
+ float nearPlane, float farPlane)
+{
+ Q_D(QCameraLens);
+ bool block = blockNotifications(true);
+ setFieldOfView(fieldOfView);
+ setAspectRatio(aspectRatio);
+ setNearPlane(nearPlane);
+ setFarPlane(farPlane);
+ setProjectionType(PerspectiveProjection);
+ blockNotifications(block);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Sets the projection's near plane to \a nearPlane. This triggers a projection
+ * matrix update.
+ */
+void QCameraLens::setNearPlane(float nearPlane)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_nearPlane, nearPlane))
+ return;
+ d->m_nearPlane = nearPlane;
+ emit nearPlaneChanged(nearPlane);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the projection's near plane.
+ */
+float QCameraLens::nearPlane() const
+{
+ Q_D(const QCameraLens);
+ return d->m_nearPlane;
+}
+
+/*!
+ * Sets the projection's far plane to \a farPlane. This triggers a projection
+ * matrix update.
+ */
+void QCameraLens::setFarPlane(float farPlane)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_farPlane, farPlane))
+ return;
+ d->m_farPlane = farPlane;
+ emit farPlaneChanged(farPlane);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the projection's far plane.
+ */
+float QCameraLens::farPlane() const
+{
+ Q_D(const QCameraLens);
+ return d->m_farPlane;
+}
+
+/*!
+ * Sets the projection's field of view to \a fieldOfView degrees. This triggers
+ * a projection matrix update.
+ *
+ * \note this has no effect if the projection type is not
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setFieldOfView(float fieldOfView)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_fieldOfView, fieldOfView))
+ return;
+ d->m_fieldOfView = fieldOfView;
+ emit fieldOfViewChanged(fieldOfView);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the projection's field of view in degrees.
+ *
+ * \note: The return value may be undefined if the projection type is not
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::fieldOfView() const
+{
+ Q_D(const QCameraLens);
+ return d->m_fieldOfView;
+}
+
+/*!
+ * Sets the projection's aspect ratio to \a aspectRatio. This triggers a projection
+ * matrix update.
+ *
+ * \note this has no effect if the projection type is not
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setAspectRatio(float aspectRatio)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_aspectRatio, aspectRatio))
+ return;
+ d->m_aspectRatio = aspectRatio;
+ emit aspectRatioChanged(aspectRatio);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the projection's aspect ratio.
+ *
+ * \note: The return value may be undefined if the projection type is not
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::aspectRatio() const
+{
+ Q_D(const QCameraLens);
+ return d->m_aspectRatio;
+}
+
+/*!
+ * Sets the projection's lower left window coordinate to \a left. This
+ * triggers a projection matrix update.
+ *
+ * \note this has no effect if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setLeft(float left)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_left, left))
+ return;
+ d->m_left = left;
+ emit leftChanged(left);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the lower left window coordinate of the projection.
+ *
+ * \note The return value may be undefined if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::left() const
+{
+ Q_D(const QCameraLens);
+ return d->m_left;
+}
+
+/*!
+ * Sets the projection's upper right window coordinate to \a right. This triggers
+ * a projection matrix update.
+ *
+ * \note this has no effect if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setRight(float right)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_right, right))
+ return;
+ d->m_right = right;
+ emit rightChanged(right);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the upper right window coordinate of the projection.
+ *
+ * \note The return value may be undefined if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::right() const
+{
+ Q_D(const QCameraLens);
+ return d->m_right;
+}
+
+/*!
+ * Sets the projection's bottom window coordinate to \a bottom. This triggers a
+ * projection matrix update.
+ *
+ * \note this has no effect if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setBottom(float bottom)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_bottom, bottom))
+ return;
+ d->m_bottom = bottom;
+ emit bottomChanged(bottom);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the bottom window coordinate of the projection.
+ *
+ * \note The return value may be undefined if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::bottom() const
+{
+ Q_D(const QCameraLens);
+ return d->m_bottom;
+}
+
+/*!
+ * Sets the projection's top window coordinate to \a top. This triggers a
+ * projection matrix update.
+ *
+ * \note this has no effect if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+void QCameraLens::setTop(float top)
+{
+ Q_D(QCameraLens);
+ if (qFuzzyCompare(d->m_top, top))
+ return;
+ d->m_top = top;
+ emit topChanged(top);
+ d->updateProjectionMatrix();
+}
+
+/*!
+ * Returns the bottom window coordinate of the projection.
+ *
+ * \note The return value may be undefined if the projection type is
+ * Qt3DRender::QCameraLens::PerspectiveProjection.
+ */
+float QCameraLens::top() const
+{
+ Q_D(const QCameraLens);
+ return d->m_top;
+}
+
+/*!
+ * Returns the projection matrix.
+ */
+QMatrix4x4 QCameraLens::projectionMatrix() const
+{
+ Q_D(const QCameraLens);
+ return d->m_projectionMatrix;
+}
+
+} // Qt3DRender
+
+/*!
+ \qmltype CameraLens
+ \instantiates Qt3DRender::QCameraLens
+ \inqmlmodule Qt3D.Core
+ \inherits Component3D
+ \since 5.5
+*/
+
+/*!
+ \qmlproperty enumeration Qt3DCore::CameraLens::projectionType
+
+ Holds the type of the camera projection (orthogonal or perspective).
+
+ \value CameraLens.OrthographicProjection Orthogonal projection
+ \value CameraLens.PerspectiveProjection Perspective projection
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::nearPlane
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::farPlane
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::fieldOfView
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::aspectRatio
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::left
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::right
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::bottom
+*/
+
+/*!
+ \qmlproperty float Qt3DCore::CameraLens::top
+*/
+
+/*!
+ \qmlproperty matrix4x4 Qt3DCore::CameraLens::projectionMatrix
+ \readonly
+*/
+
+QT_END_NAMESPACE
diff --git a/src/render/frontend/qcameralens.h b/src/render/frontend/qcameralens.h
new file mode 100644
index 000000000..6663bfb5c
--- /dev/null
+++ b/src/render/frontend/qcameralens.h
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_CAMERALENS_H
+#define QT3DRENDER_CAMERALENS_H
+
+#include <Qt3DCore/qcomponent.h>
+#include <Qt3DRender/qt3drender_global.h>
+
+#include <QMatrix4x4>
+#include <QQuaternion>
+#include <QVector3D>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QCameraLensPrivate;
+
+class QT3DRENDERSHARED_EXPORT QCameraLens : public Qt3DCore::QComponent
+{
+ Q_OBJECT
+ Q_PROPERTY(ProjectionType projectionType READ projectionType WRITE setProjectionType NOTIFY projectionTypeChanged)
+ Q_PROPERTY(float nearPlane READ nearPlane WRITE setNearPlane NOTIFY nearPlaneChanged)
+ Q_PROPERTY(float farPlane READ farPlane WRITE setFarPlane NOTIFY farPlaneChanged)
+ Q_PROPERTY(float fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
+ Q_PROPERTY(float aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
+ Q_PROPERTY(float left READ left WRITE setLeft NOTIFY leftChanged)
+ Q_PROPERTY(float right READ right WRITE setRight NOTIFY rightChanged)
+ Q_PROPERTY(float bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
+ Q_PROPERTY(float top READ top WRITE setTop NOTIFY topChanged)
+ Q_PROPERTY(QMatrix4x4 projectionMatrix READ projectionMatrix NOTIFY projectionMatrixChanged)
+
+public:
+ explicit QCameraLens(QNode *parent = 0);
+ ~QCameraLens();
+
+ enum ProjectionType {
+ OrthographicProjection,
+ PerspectiveProjection,
+ FrustumProjection
+ };
+ Q_ENUM(ProjectionType)
+
+ ProjectionType projectionType() const;
+ float nearPlane() const;
+ float farPlane() const;
+ float fieldOfView() const;
+ float aspectRatio() const;
+ float left() const;
+ float right() const;
+ float bottom() const;
+ float top() const;
+
+ QMatrix4x4 projectionMatrix() const;
+
+ void setOrthographicProjection(float left, float right,
+ float bottom, float top,
+ float nearPlane, float farPlane);
+
+ void setFrustumProjection(float left, float right,
+ float bottom, float top,
+ float nearPlane, float farPlane);
+
+ void setPerspectiveProjection(float fieldOfView, float aspect,
+ float nearPlane, float farPlane);
+
+public Q_SLOTS:
+ void setProjectionType(ProjectionType projectionType);
+ void setNearPlane(float nearPlane);
+ void setFarPlane(float farPlane);
+ void setFieldOfView(float fieldOfView);
+ void setAspectRatio(float aspectRatio);
+ void setLeft(float left);
+ void setRight(float right);
+ void setBottom(float bottom);
+ void setTop(float top);
+
+Q_SIGNALS:
+ void projectionTypeChanged(QCameraLens::ProjectionType projectionType);
+ void nearPlaneChanged(float nearPlane);
+ void farPlaneChanged(float farPlane);
+ void fieldOfViewChanged(float fieldOfView);
+ void aspectRatioChanged(float aspectRatio);
+ void leftChanged(float left);
+ void rightChanged(float right);
+ void bottomChanged(float bottom);
+ void topChanged(float top);
+ void projectionMatrixChanged(const QMatrix4x4 &projectionMatrix);
+
+protected:
+ QCameraLens(QCameraLensPrivate &dd, QNode *parent = 0);
+ void copy(const QNode *ref) Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QCameraLens)
+ QT3D_CLONEABLE(QCameraLens)
+};
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_CAMERALENS_H
diff --git a/src/render/frontend/qcameralens_p.h b/src/render/frontend/qcameralens_p.h
new file mode 100644
index 000000000..f201f75e3
--- /dev/null
+++ b/src/render/frontend/qcameralens_p.h
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_CAMERALENS_P_H
+#define QT3DRENDER_CAMERALENS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DCore/private/qcomponent_p.h>
+#include "qcameralens.h"
+
+#include <Qt3DCore/qscenepropertychange.h>
+
+#include <QtGui/qmatrix4x4.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QCameraLensPrivate : public Qt3DCore::QComponentPrivate
+{
+public:
+ QCameraLensPrivate();
+
+ inline void updateProjectionMatrix()
+ {
+ switch (m_projectionType) {
+ case QCameraLens::OrthographicProjection:
+ updateOrthographicProjection();
+ break;
+ case QCameraLens::PerspectiveProjection:
+ updatePerpectiveProjection();
+ break;
+ case QCameraLens::FrustumProjection:
+ updateFrustumProjection();
+ break;
+ }
+ }
+
+ Q_DECLARE_PUBLIC(QCameraLens)
+
+ QCameraLens::ProjectionType m_projectionType;
+
+ float m_nearPlane;
+ float m_farPlane;
+
+ float m_fieldOfView;
+ float m_aspectRatio;
+
+ float m_left;
+ float m_right;
+ float m_bottom;
+ float m_top;
+
+ mutable QMatrix4x4 m_projectionMatrix;
+
+private:
+ inline void updatePerpectiveProjection()
+ {
+ Q_Q(QCameraLens);
+ m_projectionMatrix.setToIdentity();
+ m_projectionMatrix.perspective(m_fieldOfView, m_aspectRatio, m_nearPlane, m_farPlane);
+ Q_EMIT q->projectionMatrixChanged(m_projectionMatrix);
+ }
+
+ inline void updateOrthographicProjection()
+ {
+ Q_Q(QCameraLens);
+ m_projectionMatrix.setToIdentity();
+ m_projectionMatrix.ortho(m_left, m_right, m_bottom, m_top, m_nearPlane, m_farPlane);
+ Q_EMIT q->projectionMatrixChanged(m_projectionMatrix);
+ }
+
+ inline void updateFrustumProjection()
+ {
+ Q_Q(QCameraLens);
+ m_projectionMatrix.setToIdentity();
+ m_projectionMatrix.frustum(m_left, m_right, m_bottom, m_top, m_nearPlane, m_farPlane);
+ Q_EMIT q->projectionMatrixChanged(m_projectionMatrix);
+ }
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_CAMERALENS_P_H
diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp
index 7ca1170c4..15fbe4384 100644
--- a/src/render/frontend/qrenderaspect.cpp
+++ b/src/render/frontend/qrenderaspect.cpp
@@ -63,7 +63,7 @@
#include <Qt3DRender/qshaderdata.h>
#include <Qt3DRender/qstateset.h>
#include <Qt3DRender/qnodraw.h>
-#include <Qt3DCore/qcameralens.h>
+#include <Qt3DRender/qcameralens.h>
#include <Qt3DRender/qattribute.h>
#include <Qt3DRender/qbuffer.h>
#include <Qt3DRender/qgeometry.h>
@@ -248,7 +248,7 @@ void QRenderAspect::registerBackendTypes()
registerBackendType<QShaderProgram>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::Shader, Render::ShaderManager>(d->m_nodeManagers->shaderManager())));
registerBackendType<QEffect>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::Effect, Render::EffectManager>(d->m_nodeManagers->effectManager())));
registerBackendType<QAnnotation>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::Annotation, Render::CriterionManager>(d->m_nodeManagers->criterionManager())));
- registerBackendType<Qt3DCore::QCameraLens>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::CameraLens, Render::CameraManager>(d->m_nodeManagers->cameraManager())));
+ registerBackendType<Qt3DRender::QCameraLens>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::CameraLens, Render::CameraManager>(d->m_nodeManagers->cameraManager())));
registerBackendType<QLayer>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::Layer, Render::LayerManager>(d->m_nodeManagers->layerManager())));
registerBackendType<QRenderPass>(QBackendNodeFunctorPtr(new Render::NodeFunctor<Render::RenderPass, Render::RenderPassManager>(d->m_nodeManagers->renderPassManager())));
registerBackendType<QAbstractSceneLoader>(QBackendNodeFunctorPtr(new Render::RenderSceneFunctor(d->m_nodeManagers->sceneManager())));
diff --git a/src/render/frontend/qwindow.cpp b/src/render/frontend/qwindow.cpp
deleted file mode 100644
index 1d7889cdb..000000000
--- a/src/render/frontend/qwindow.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwindow.h"
-#include "qwindow_p.h"
-
-#include <Qt3DCore/qaspectengine.h>
-#include <Qt3DCore/qentity.h>
-#include <Qt3DCore/qcamera.h>
-#include <Qt3DRender/qframegraph.h>
-#include <Qt3DRender/qrenderaspect.h>
-#include <Qt3DRender/qforwardrenderer.h>
-#include <QOpenGLContext>
-
-QT_BEGIN_NAMESPACE
-
-using namespace Qt3DCore;
-
-namespace Qt3DRender {
-
-QWindowPrivate::QWindowPrivate()
- : ::QWindowPrivate()
- , m_initialized(false)
- , m_root(new QEntity())
- , m_userRoot(Q_NULLPTR)
- , m_defaultCamera(new QCamera())
- , m_frameGraph(Q_NULLPTR)
- , m_engine(new QAspectEngine())
- , m_renderAspect(new QRenderAspect())
-{
- m_engine->registerAspect(m_renderAspect);
-
- // TO DO: Find a nice way to set the camera on the controller which is in
- // the input aspect
-}
-
-QWindow::QWindow(::QWindow *parent)
- : ::QWindow(*new QWindowPrivate(), parent)
-{
- setSurfaceType(QSurface::OpenGLSurface);
-
- resize(1024, 768);
-
- QSurfaceFormat format;
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
- format.setVersion(4, 3);
- format.setProfile(QSurfaceFormat::CoreProfile);
- }
- format.setDepthBufferSize(24);
- format.setSamples(4);
- format.setStencilBufferSize(8);
- setFormat(format);
- create();
-}
-
-QWindow::QWindow(QWindowPrivate &dd, ::QWindow *parent)
- : ::QWindow(dd, parent)
-{
- setSurfaceType(QSurface::OpenGLSurface);
-
- resize(1024, 768);
-
- QSurfaceFormat format;
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
- format.setVersion(4, 3);
- format.setProfile(QSurfaceFormat::CoreProfile);
- }
- format.setDepthBufferSize(24);
- format.setSamples(4);
- format.setStencilBufferSize(8);
- setFormat(format);
- create();
-}
-
-void QWindow::resizeEvent(QResizeEvent *)
-{
- Q_D(QWindow);
- d->m_defaultCamera->setAspectRatio(float(width()) / float(height()));
-}
-
-QWindow::~QWindow()
-{
-}
-
-void QWindow::setFrameGraph(QFrameGraph *frameGraph)
-{
- Q_ASSERT(!isVisible());
- Q_D(QWindow);
- d->m_frameGraph = frameGraph;
-}
-
-QFrameGraph *QWindow::frameGraph() const
-{
- Q_D(const QWindow);
- return d->m_frameGraph;
-}
-
-Qt3DCore::QCamera *QWindow::defaultCamera()
-{
- Q_D(const QWindow);
- return d->m_defaultCamera;
-}
-
-void QWindow::registerAspect(Qt3DCore::QAbstractAspect *aspect)
-{
- Q_ASSERT(!isVisible());
- Q_D(QWindow);
- d->m_engine->registerAspect(aspect);
-}
-
-void QWindow::registerAspect(const QString &name)
-{
- Q_ASSERT(!isVisible());
- Q_D(QWindow);
- d->m_engine->registerAspect(name);
-}
-
-void QWindow::setRootEntity(Qt3DCore::QEntity *root)
-{
- Q_ASSERT(!isVisible());
- Q_D(QWindow);
- d->m_userRoot = root;
-}
-
-void QWindow::showEvent(QShowEvent *event)
-{
- Q_D(QWindow);
-
- if (!d->m_initialized) {
- if (d->m_userRoot != Q_NULLPTR)
- d->m_userRoot->setParent(d->m_root);
-
- if (d->m_frameGraph == Q_NULLPTR) {
- d->m_frameGraph = new QFrameGraph();
- QForwardRenderer *forwardRenderer = new QForwardRenderer();
- forwardRenderer->setCamera(d->m_defaultCamera);
- d->m_frameGraph->setActiveFrameGraph(forwardRenderer);
- }
-
- QVariantMap data;
- data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(this)));
- data.insert(QStringLiteral("eventSource"), QVariant::fromValue(this));
- d->m_engine->setData(data);
-
- d->m_root->addComponent(d->m_frameGraph);
- d->m_engine->setRootEntity(d->m_root);
- d->m_initialized = true;
- }
-
- ::QWindow::showEvent(event);
-}
-
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
diff --git a/src/render/frontend/qwindow.h b/src/render/frontend/qwindow.h
deleted file mode 100644
index 2a904de5e..000000000
--- a/src/render/frontend/qwindow.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DRENDER_QWINDOW_H
-#define QT3DRENDER_QWINDOW_H
-
-#include <QtGui/qwindow.h>
-#include <Qt3DRender/qt3drender_global.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DCore {
-class QAbstractAspect;
-class QCamera;
-class QEntity;
-}
-
-namespace Qt3DRender {
-
-class QWindowPrivate;
-class QFrameGraph;
-
-class QT3DRENDERSHARED_EXPORT QWindow : public ::QWindow
-{
-public:
- explicit QWindow(::QWindow *parent = Q_NULLPTR);
- ~QWindow();
-
- void setFrameGraph(QFrameGraph *frameGraph);
- QFrameGraph *frameGraph() const;
- Qt3DCore::QCamera *defaultCamera();
-
- void registerAspect(Qt3DCore::QAbstractAspect *aspect);
- void registerAspect(const QString &name);
-
- void setRootEntity(Qt3DCore::QEntity *root);
-
-protected:
- QWindow(QWindowPrivate &dd, ::QWindow *parent = Q_NULLPTR);
- void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
- void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
-
-private:
- Q_DECLARE_PRIVATE(QWindow)
-};
-
-} // namespace Qt3DRender
-
-QT_END_NAMESPACE
-
-#endif // QT3DRENDER_QWINDOW_H
diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri
index 06dd7e3f5..01bf3e3f2 100644
--- a/src/render/frontend/render-frontend.pri
+++ b/src/render/frontend/render-frontend.pri
@@ -11,12 +11,14 @@ HEADERS += \
$$PWD/qrenderattachment_p.h \
$$PWD/qrendertarget.h \
$$PWD/qrendertarget_p.h \
- $$PWD/qwindow.h \
- $$PWD/qwindow_p.h \
$$PWD/sphere_p.h \
$$PWD/qboundingvolumedebug.h \
$$PWD/qcomputejob.h \
- $$PWD/qcomputejob_p.h
+ $$PWD/qcomputejob_p.h \
+ $$PWD/qcamera_p.h \
+ $$PWD/qcamera.h \
+ $$PWD/qcameralens.h \
+ $$PWD/qcameralens_p.h
SOURCES += \
$$PWD/qabstractfunctor.cpp \
@@ -26,6 +28,7 @@ SOURCES += \
$$PWD/qlayer.cpp \
$$PWD/qrenderattachment.cpp \
$$PWD/qrendertarget.cpp \
- $$PWD/qwindow.cpp \
$$PWD/qboundingvolumedebug.cpp \
- $$PWD/qcomputejob.cpp
+ $$PWD/qcomputejob.cpp \
+ $$PWD/qcamera.cpp \
+ $$PWD/qcameralens.cpp