summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-05-30 17:42:56 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-31 15:49:14 +0200
commit7f750d898f26312ab76f716c8f9b69089cebe576 (patch)
tree732d6338d3f332923e493eaf259c9d77efa0f455 /src
parent76efd5b9713431984c143bf2b861f196dd05acb8 (diff)
CameraController usable from QML
Configuration QML element with controlledCamera property which has to be set to as valid Camera element we want to control. Slight hack (behind the scene) to make that work. Will be cleaned up on the next iteration. Change-Id: I794ee1c26207178f94765c873331bce19efaab9f Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/cameracontroller.h2
-rw-r--r--src/core/core-components/camera.h6
-rw-r--r--src/core/window.cpp2
-rw-r--r--src/core/window.h2
-rw-r--r--src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp11
-rw-r--r--src/quick3d/quick3d/items/items.pri2
-rw-r--r--src/quick3d/quick3d/items/quick3dconfiguration.cpp76
-rw-r--r--src/quick3d/quick3d/items/quick3dconfiguration.h79
-rw-r--r--src/quick3d/quick3d/quickwindow.cpp23
-rw-r--r--src/quick3d/quick3d/quickwindow.h7
10 files changed, 199 insertions, 11 deletions
diff --git a/src/core/cameracontroller.h b/src/core/cameracontroller.h
index eed68de78..b28e44698 100644
--- a/src/core/cameracontroller.h
+++ b/src/core/cameracontroller.h
@@ -59,7 +59,7 @@ namespace Qt3D
class Camera;
class Entity;
-class CameraController : public QObject
+class QT3DCORESHARED_EXPORT CameraController : public QObject
{
Q_OBJECT
Q_PROPERTY( float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged )
diff --git a/src/core/core-components/camera.h b/src/core/core-components/camera.h
index 25981541a..de4d17107 100644
--- a/src/core/core-components/camera.h
+++ b/src/core/core-components/camera.h
@@ -56,14 +56,12 @@ namespace Qt3D {
class CameraPrivate;
class CameraLens;
class Transform;
-class LookAtTransform;
class QT3DCORESHARED_EXPORT Camera : public EntityNode
{
Q_OBJECT
- // TODO Move view matrix out of the camera and use Transform component (once it exists)
- Q_PROPERTY(Qt3D::CameraLens* lens READ lens WRITE setLens NOTIFY lensChanged)
- Q_PROPERTY(Qt3D::Transform* transform READ transform WRITE setTransform NOTIFY transformChanged)
+ Q_PROPERTY(Qt3D::CameraLens *lens READ lens WRITE setLens NOTIFY lensChanged)
+ Q_PROPERTY(Qt3D::Transform *transform READ transform WRITE setTransform NOTIFY transformChanged)
public:
explicit Camera(Node *parent = 0);
diff --git a/src/core/window.cpp b/src/core/window.cpp
index d835f0c63..76610606e 100644
--- a/src/core/window.cpp
+++ b/src/core/window.cpp
@@ -77,7 +77,7 @@ Window::Window(QScreen *screen)
m_aspectEngine->initialize();
m_aspectEngine->setWindow(this);
- m_controller = new CameraController;
+ m_controller = new CameraController();
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(16);
diff --git a/src/core/window.h b/src/core/window.h
index 93304ed47..3b26368cb 100644
--- a/src/core/window.h
+++ b/src/core/window.h
@@ -69,7 +69,7 @@ public:
QSharedPointer<QObject> rootObject() { return m_root; }
void registerAspect(AbstractAspect *aspect);
- void setCamera(Camera *camera);
+ virtual void setCamera(Camera *camera);
protected:
virtual void keyPressEvent(QKeyEvent *e);
diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
index 503106129..5ca63962a 100644
--- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
+++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp
@@ -55,18 +55,24 @@
#include <Qt3DCore/qabstracttechnique.h>
#include <Qt3DCore/qabstractmesh.h>
#include <Qt3DCore/qabstractrenderpass.h>
+#include <Qt3DQuick/quick3dconfiguration.h>
QT_BEGIN_NAMESPACE
void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
{
- qmlRegisterUncreatableType<Qt3D::Node>(uri, 2, 0, "Node_priv", "");
+ qmlRegisterUncreatableType<Qt3D::Node>(uri, 2, 0, "Node_private", "");
+ qmlRegisterUncreatableType<Qt3D::Transform>(uri, 2, 0, "Transform_private", "");
qmlRegisterInterface<Qt3D::QAbstractEffect>("QAbstractEffect");
qmlRegisterUncreatableType<Qt3D::QAbstractMesh>(uri, 2, 0, "QAbstractMesh", "");
qmlRegisterUncreatableType<Qt3D::QAbstractMaterial>(uri, 2, 0, "QAbstractMaterial", "");
qmlRegisterUncreatableType<Qt3D::QAbstractTechnique>(uri, 2, 0, "QAbstractTechnique", "");
qmlRegisterUncreatableType<Qt3D::QAbstractRenderPass>(uri, 2, 0, "QAbstractRenderPass", "");
+ qmlRegisterType<Qt3D::Quick::Quick3DConfiguration>(uri, 2, 0, "Configuration");
+ qmlRegisterType<Qt3D::Quick::Quick3DEntity>(uri, 2, 0, "Entity");
+ qmlRegisterType<Qt3D::Quick::Quick3DTransform>(uri, 2, 0, "Transform");
+ qmlRegisterType<Qt3D::Quick::Quick3DNode>(uri, 2, 0, "Node");
qmlRegisterType<Qt3D::Component>(uri, 2, 0, "Component");
qmlRegisterType<Qt3D::Camera>(uri, 2, 0, "Camera");
qmlRegisterType<Qt3D::CameraLens>(uri, 2, 0, "CameraLens");
@@ -75,9 +81,6 @@ void Qt3DQuick3DCorePlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3D::RotateTransform>(uri, 2, 0, "Rotate");
qmlRegisterType<Qt3D::LookAtTransform>(uri, 2, 0, "LookAt");
qmlRegisterType<Qt3D::ScaleTransform>(uri, 2, 0, "Scale");
- qmlRegisterType<Qt3D::Quick::Quick3DEntity>(uri, 2, 0, "Entity");
- qmlRegisterType<Qt3D::Quick::Quick3DTransform>(uri, 2, 0, "Transform");
- qmlRegisterType<Qt3D::Quick::Quick3DNode>(uri, 2, 0, "Node");
}
QT_END_NAMESPACE
diff --git a/src/quick3d/quick3d/items/items.pri b/src/quick3d/quick3d/items/items.pri
index 19db4cb55..199532964 100644
--- a/src/quick3d/quick3d/items/items.pri
+++ b/src/quick3d/quick3d/items/items.pri
@@ -2,10 +2,12 @@ HEADERS += \
$$PWD/quick3dnode.h \
$$PWD/quick3dentity.h \
$$PWD/quick3dtransform.h \
+ $$PWD/quick3dconfiguration.h
SOURCES += \
$$PWD/quick3dnode.cpp \
$$PWD/quick3dentity.cpp \
$$PWD/quick3dtransform.cpp \
+ $$PWD/quick3dconfiguration.cpp
INCLUDEPATH += $$PWD
diff --git a/src/quick3d/quick3d/items/quick3dconfiguration.cpp b/src/quick3d/quick3d/items/quick3dconfiguration.cpp
new file mode 100644
index 000000000..7a24022d7
--- /dev/null
+++ b/src/quick3d/quick3d/items/quick3dconfiguration.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quick3dconfiguration.h"
+#include "quickwindow.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Quick {
+
+Quick3DConfiguration::Quick3DConfiguration(QObject *parent)
+ : QObject(parent)
+ , m_camera(Q_NULLPTR)
+{
+}
+
+void Quick3DConfiguration::setControlledCamera(Camera *camera)
+{
+ if (m_camera != camera) {
+ m_camera = camera;
+ emit controlledCameraChanged();
+ Qt3D::Quick::QuickWindow::getInstance()->setCamera(camera);
+ }
+}
+
+Camera *Quick3DConfiguration::controlledCamera() const
+{
+ return m_camera;
+}
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3d/items/quick3dconfiguration.h b/src/quick3d/quick3d/items/quick3dconfiguration.h
new file mode 100644
index 000000000..768892487
--- /dev/null
+++ b/src/quick3d/quick3d/items/quick3dconfiguration.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QUICK_QUICK3DCONFIGURATION_H
+#define QT3D_QUICK_QUICK3DCONFIGURATION_H
+
+#include <Qt3DQuick/qt3dquick_global.h>
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class Camera;
+
+namespace Quick {
+
+class QT3DQUICKSHARED_EXPORT Quick3DConfiguration : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3D::Camera *controlledCamera READ controlledCamera WRITE setControlledCamera NOTIFY controlledCameraChanged)
+public:
+ explicit Quick3DConfiguration(QObject *parent = 0);
+
+ void setControlledCamera(Camera *camera);
+ Camera *controlledCamera() const;
+
+Q_SIGNALS:
+ void controlledCameraChanged();
+
+private:
+ Camera *m_camera;
+};
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QUICK_QUICK3DCONFIGURATION_H
diff --git a/src/quick3d/quick3d/quickwindow.cpp b/src/quick3d/quick3d/quickwindow.cpp
index 339084acf..43922ba01 100644
--- a/src/quick3d/quick3d/quickwindow.cpp
+++ b/src/quick3d/quick3d/quickwindow.cpp
@@ -43,7 +43,10 @@
#include <Qt3DCore/qaspectengine.h>
#include <QQmlComponent>
+#include <QQmlContext>
#include <QDebug>
+#include <QTimer>
+#include "cameracontroller.h"
QT_BEGIN_NAMESPACE
@@ -51,10 +54,16 @@ namespace Qt3D {
namespace Quick {
+QuickWindow *QuickWindow::m_instance = Q_NULLPTR;
+
QuickWindow::QuickWindow(QScreen *screen)
: Window(screen)
, m_engine(new QQmlEngine)
{
+
+ // HACKED TO BE ABLE TO ASSIGN CAMERA TO CONTROLLER
+ // FROM QML EASILY
+ QuickWindow::m_instance = this;
}
QuickWindow::~QuickWindow()
@@ -99,6 +108,20 @@ void QuickWindow::setSource(const QUrl& source)
}
}
+void QuickWindow::setCamera(Camera *camera)
+{
+ Window::setCamera(camera);
+ if (m_camera) {
+ m_controller->setCamera(m_camera);
+ m_updateTimer->start();
+ }
+}
+
+QuickWindow *QuickWindow::getInstance()
+{
+ return QuickWindow::m_instance;
+}
+
void QuickWindow::continueExecute()
{
qDebug() << Q_FUNC_INFO;
diff --git a/src/quick3d/quick3d/quickwindow.h b/src/quick3d/quick3d/quickwindow.h
index f104fe7c0..59207448d 100644
--- a/src/quick3d/quick3d/quickwindow.h
+++ b/src/quick3d/quick3d/quickwindow.h
@@ -56,6 +56,8 @@ class QAspectEngine;
namespace Quick {
+class Quick3DConfiguration;
+
class QT3DQUICKSHARED_EXPORT QuickWindow : public Qt3D::Window
{
Q_OBJECT
@@ -68,6 +70,10 @@ public:
Status status() const;
void setSource(const QUrl& url);
+ void setCamera(Camera *camera);
+ static QuickWindow *getInstance();
+
+
Q_SIGNALS:
void statusChanged(Status);
@@ -78,6 +84,7 @@ private:
QScopedPointer<QQmlEngine> m_engine;
QSharedPointer<QQmlComponent> m_component;
+ static QuickWindow *m_instance;
};
} // Quick