summaryrefslogtreecommitdiffstats
path: root/src/extras
diff options
context:
space:
mode:
Diffstat (limited to 'src/extras')
-rw-r--r--src/extras/defaults/defaults.pri12
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller.cpp252
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller.h100
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller_p.h133
-rw-r--r--src/extras/defaults/qorbitcontrol.cpp320
-rw-r--r--src/extras/defaults/qorbitcontrol.h91
-rw-r--r--src/extras/defaults/qorbitcontrol_p.h135
-rw-r--r--src/extras/defaults/qt3dwindow.cpp179
-rw-r--r--src/extras/defaults/qt3dwindow.h142
-rw-r--r--src/extras/extras.pro2
10 files changed, 1363 insertions, 3 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri
index 1560f55ec..6ff23403b 100644
--- a/src/extras/defaults/defaults.pri
+++ b/src/extras/defaults/defaults.pri
@@ -22,7 +22,12 @@ HEADERS += \
$$PWD/qgoochmaterial.h \
$$PWD/qgoochmaterial_p.h \
$$PWD/qphongalphamaterial.h \
- $$PWD/qphongalphamaterial_p.h
+ $$PWD/qphongalphamaterial_p.h \
+ $$PWD/qt3dwindow.h \
+ $$PWD/qorbitcontrol.h \
+ $$PWD/qorbitcontrol_p.h \
+ $$PWD/qfirstpersoncameracontroller.h \
+ $$PWD/qfirstpersoncameracontroller_p.h
SOURCES += \
$$PWD/qphongmaterial.cpp \
@@ -35,5 +40,8 @@ SOURCES += \
$$PWD/qpervertexcolormaterial.cpp \
$$PWD/qskyboxentity.cpp \
$$PWD/qgoochmaterial.cpp \
- $$PWD/qphongalphamaterial.cpp
+ $$PWD/qphongalphamaterial.cpp \
+ $$PWD/qt3dwindow.cpp \
+ $$PWD/qorbitcontrol.cpp \
+ $$PWD/qfirstpersoncameracontroller.cpp
diff --git a/src/extras/defaults/qfirstpersoncameracontroller.cpp b/src/extras/defaults/qfirstpersoncameracontroller.cpp
new file mode 100644
index 000000000..57cf3ba88
--- /dev/null
+++ b/src/extras/defaults/qfirstpersoncameracontroller.cpp
@@ -0,0 +1,252 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qfirstpersoncameracontroller_p.h"
+#include "qfirstpersoncameracontroller.h"
+#include <Qt3DRender/QCamera>
+#include <Qt3DInput/QAxis>
+#include <Qt3DInput/QAxisInput>
+#include <Qt3DInput/QAction>
+#include <Qt3DInput/QActionInput>
+#include <Qt3DInput/QLogicalDevice>
+#include <Qt3DInput/QKeyboardDevice>
+#include <Qt3DInput/QMouseDevice>
+#include <Qt3DInput/QMouseEvent>
+#include <Qt3DLogic/QFrameAction>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+QFirstPersonCameraControllerPrivate::QFirstPersonCameraControllerPrivate()
+ : Qt3DCore::QEntityPrivate()
+ , m_camera(Q_NULLPTR)
+ , m_leftMouseButtonAction(new Qt3DInput::QAction())
+ , m_fineMotionAction(new Qt3DInput::QAction())
+ , m_rxAxis(new Qt3DInput::QAxis())
+ , m_ryAxis(new Qt3DInput::QAxis())
+ , m_txAxis(new Qt3DInput::QAxis())
+ , m_tyAxis(new Qt3DInput::QAxis())
+ , m_tzAxis(new Qt3DInput::QAxis())
+ , m_leftMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_fineMotionKeyInput(new Qt3DInput::QActionInput())
+ , m_mouseRxInput(new Qt3DInput::QAxisInput())
+ , m_mouseRyInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTxPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTyPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTzPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTxNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTyNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTzNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardDevice(new Qt3DInput::QKeyboardDevice())
+ , m_mouseDevice(new Qt3DInput::QMouseDevice())
+ , m_logicalDevice(new Qt3DInput::QLogicalDevice())
+ , m_frameAction(new Qt3DLogic::QFrameAction())
+ , m_linearSpeed(10.0f)
+ , m_lookSpeed(180.0f)
+ , m_firstPersonUp(QVector3D(0.0f, 1.0f, 0.0f))
+{}
+
+void QFirstPersonCameraControllerPrivate::init()
+{
+ //// Actions
+
+ // Left Mouse Button Action
+ m_leftMouseButtonInput->setButtons(QVariantList() << Qt::LeftButton);
+ m_leftMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_leftMouseButtonAction->addInput(m_leftMouseButtonInput);
+
+ // Fine Motion Action
+ m_fineMotionKeyInput->setButtons(QVariantList() << Qt::Key_Shift);
+ m_fineMotionKeyInput->setSourceDevice(m_keyboardDevice);
+ m_fineMotionAction->addInput(m_fineMotionKeyInput);
+
+ //// Axes
+
+ // Mouse X
+ m_mouseRxInput->setAxis(Qt3DInput::QMouseDevice::X);
+ m_mouseRxInput->setSourceDevice(m_mouseDevice);
+ m_rxAxis->addInput(m_mouseRxInput);
+
+ // Mouse Y
+ m_mouseRyInput->setAxis(Qt3DInput::QMouseDevice::Y);
+ m_mouseRyInput->setSourceDevice(m_mouseDevice);
+ m_ryAxis->addInput(m_mouseRyInput);
+
+ // Keyboard Pos Tx
+ m_keyboardTxPosInput->setButtons(QVariantList() << Qt::Key_Right);
+ m_keyboardTxPosInput->setScale(1.0f);
+ m_keyboardTxPosInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxPosInput);
+
+ // Keyboard Pos Ty
+ m_keyboardTyPosInput->setButtons(QVariantList() << Qt::Key_PageUp);
+ m_keyboardTyPosInput->setScale(1.0f);
+ m_keyboardTyPosInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyPosInput);
+
+ // Keyboard Pos Tz
+ m_keyboardTzPosInput->setButtons(QVariantList() << Qt::Key_Up);
+ m_keyboardTzPosInput->setScale(1.0f);
+ m_keyboardTzPosInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzPosInput);
+
+ // Keyboard Neg Tx
+ m_keyboardTxNegInput->setButtons(QVariantList() << Qt::Key_Left);
+ m_keyboardTxNegInput->setScale(-1.0f);
+ m_keyboardTxNegInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxNegInput);
+
+ // Keyboard Neg Ty
+ m_keyboardTyNegInput->setButtons(QVariantList() << Qt::Key_PageDown);
+ m_keyboardTyNegInput->setScale(-1.0f);
+ m_keyboardTyNegInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyNegInput);
+
+ // Keyboard Neg Tz
+ m_keyboardTzNegInput->setButtons(QVariantList() << Qt::Key_Down);
+ m_keyboardTzNegInput->setScale(-1.0f);
+ m_keyboardTzNegInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzNegInput);
+
+ //// Logical Device
+
+ m_logicalDevice->addAction(m_fineMotionAction);
+ m_logicalDevice->addAction(m_leftMouseButtonAction);
+ m_logicalDevice->addAxis(m_rxAxis);
+ m_logicalDevice->addAxis(m_ryAxis);
+ m_logicalDevice->addAxis(m_txAxis);
+ m_logicalDevice->addAxis(m_tyAxis);
+ m_logicalDevice->addAxis(m_tzAxis);
+
+ Q_Q(QFirstPersonCameraController);
+ //// FrameAction
+
+ QObject::connect(m_frameAction, SIGNAL(triggered(float)),
+ q, SLOT(_q_onTriggered(float)));
+
+ q->addComponent(m_frameAction);
+ q->addComponent(m_logicalDevice);
+}
+
+void QFirstPersonCameraControllerPrivate::_q_onTriggered(float dt)
+{
+ if (m_camera != Q_NULLPTR) {
+ m_camera->translate(QVector3D(m_txAxis->value() * m_linearSpeed,
+ m_tyAxis->value() * m_linearSpeed,
+ m_tzAxis->value() * m_linearSpeed) * dt);
+ if (m_leftMouseButtonAction->isActive()) {
+ m_camera->pan(m_rxAxis->value() * m_lookSpeed * dt, m_firstPersonUp);
+ m_camera->tilt(m_ryAxis->value() * m_lookSpeed * dt);
+ }
+ }
+}
+
+QFirstPersonCameraController::QFirstPersonCameraController(Qt3DCore::QNode *parent)
+ : Qt3DCore::QEntity(*new QFirstPersonCameraControllerPrivate, parent)
+{
+ Q_D(QFirstPersonCameraController);
+ d->init();
+}
+
+QFirstPersonCameraController::~QFirstPersonCameraController()
+{
+}
+
+Qt3DRender::QCamera *QFirstPersonCameraController::camera() const
+{
+ Q_D(const QFirstPersonCameraController);
+ return d->m_camera;
+}
+
+float QFirstPersonCameraController::linearSpeed() const
+{
+ Q_D(const QFirstPersonCameraController);
+ return d->m_linearSpeed;
+}
+
+float QFirstPersonCameraController::lookSpeed() const
+{
+ Q_D(const QFirstPersonCameraController);
+ return d->m_lookSpeed;
+}
+
+void QFirstPersonCameraController::setCamera(Qt3DRender::QCamera *camera)
+{
+ Q_D(QFirstPersonCameraController);
+ if (d->m_camera != camera) {
+ d->m_camera = camera;
+ emit cameraChanged();
+ }
+}
+
+void QFirstPersonCameraController::setLinearSpeed(float linearSpeed)
+{
+ Q_D(QFirstPersonCameraController);
+ if (d->m_linearSpeed != linearSpeed) {
+ d->m_linearSpeed = linearSpeed;
+ emit linearSpeedChanged();
+ }
+}
+
+void QFirstPersonCameraController::setLookSpeed(float lookSpeed)
+{
+ Q_D(QFirstPersonCameraController);
+ if (d->m_lookSpeed != lookSpeed) {
+ d->m_lookSpeed = lookSpeed;
+ emit lookSpeedChanged();
+ }
+}
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#include "moc_qfirstpersoncameracontroller.cpp"
diff --git a/src/extras/defaults/qfirstpersoncameracontroller.h b/src/extras/defaults/qfirstpersoncameracontroller.h
new file mode 100644
index 000000000..358f69160
--- /dev/null
+++ b/src/extras/defaults/qfirstpersoncameracontroller.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_H
+#define QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_H
+
+#include <Qt3DExtras/qt3dextras_global.h>
+#include <Qt3DCore/QEntity>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DExtras {
+
+class QFirstPersonCameraControllerPrivate;
+
+class QT3DEXTRASSHARED_EXPORT QFirstPersonCameraController : public Qt3DCore::QEntity
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
+ Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
+ Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
+
+public:
+ explicit QFirstPersonCameraController(Qt3DCore::QNode *parent = Q_NULLPTR);
+ ~QFirstPersonCameraController();
+
+ Qt3DRender::QCamera *camera() const;
+ float linearSpeed() const;
+ float lookSpeed() const;
+
+ void setCamera(Qt3DRender::QCamera *camera);
+ void setLinearSpeed(float linearSpeed);
+ void setLookSpeed(float lookSpeed);
+
+Q_SIGNALS:
+ void cameraChanged();
+ void linearSpeedChanged();
+ void lookSpeedChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QFirstPersonCameraController)
+ Q_PRIVATE_SLOT(d_func(), void _q_onTriggered(float))
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_H
diff --git a/src/extras/defaults/qfirstpersoncameracontroller_p.h b/src/extras/defaults/qfirstpersoncameracontroller_p.h
new file mode 100644
index 000000000..e93b0bc33
--- /dev/null
+++ b/src/extras/defaults/qfirstpersoncameracontroller_p.h
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_P_H
+#define QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_P_H
+
+#include <Qt3DCore/private/qentity_p.h>
+#include <QVector3D>
+#include "qfirstpersoncameracontroller.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DLogic {
+class QFrameAction;
+}
+
+namespace Qt3DInput {
+
+class QKeyboardDevice;
+class QMouseDevice;
+class QLogicalDevice;
+class QAction;
+class QActionInput;
+class QAxis;
+class QAxisInput;
+class QAxisActionHandler;
+
+}
+
+namespace Qt3DExtras {
+
+class QFirstPersonCameraControllerPrivate : public Qt3DCore::QEntityPrivate
+{
+public:
+ QFirstPersonCameraControllerPrivate();
+
+ void init();
+
+ Qt3DRender::QCamera *m_camera;
+
+ Qt3DInput::QAction *m_leftMouseButtonAction;
+ Qt3DInput::QAction *m_fineMotionAction;
+
+ Qt3DInput::QAxis *m_rxAxis;
+ Qt3DInput::QAxis *m_ryAxis;
+ Qt3DInput::QAxis *m_txAxis;
+ Qt3DInput::QAxis *m_tyAxis;
+ Qt3DInput::QAxis *m_tzAxis;
+
+ Qt3DInput::QActionInput *m_leftMouseButtonInput;
+ Qt3DInput::QActionInput *m_fineMotionKeyInput;
+
+ Qt3DInput::QAxisInput *m_mouseRxInput;
+ Qt3DInput::QAxisInput *m_mouseRyInput;
+ Qt3DInput::QAxisInput *m_keyboardTxPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTyPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTzPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTxNegInput;
+ Qt3DInput::QAxisInput *m_keyboardTyNegInput;
+ Qt3DInput::QAxisInput *m_keyboardTzNegInput;
+
+ Qt3DInput::QKeyboardDevice *m_keyboardDevice;
+ Qt3DInput::QMouseDevice *m_mouseDevice;
+
+ Qt3DInput::QLogicalDevice *m_logicalDevice;
+
+ Qt3DLogic::QFrameAction *m_frameAction;
+
+ float m_linearSpeed;
+ float m_lookSpeed;
+ QVector3D m_firstPersonUp;
+
+ void _q_onTriggered(float);
+
+ Q_DECLARE_PUBLIC(QFirstPersonCameraController)
+};
+
+} // Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_P_H
diff --git a/src/extras/defaults/qorbitcontrol.cpp b/src/extras/defaults/qorbitcontrol.cpp
new file mode 100644
index 000000000..65810e1a0
--- /dev/null
+++ b/src/extras/defaults/qorbitcontrol.cpp
@@ -0,0 +1,320 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "qorbitcontrol_p.h"
+#include "qorbitcontrol.h"
+#include <QtGlobal>
+#include <Qt3DRender/QCamera>
+#include <Qt3DInput/QAxis>
+#include <Qt3DInput/QAxisInput>
+#include <Qt3DInput/QAction>
+#include <Qt3DInput/QActionInput>
+#include <Qt3DInput/QLogicalDevice>
+#include <Qt3DInput/QKeyboardDevice>
+#include <Qt3DInput/QMouseDevice>
+#include <Qt3DInput/QMouseEvent>
+#include <Qt3DLogic/QFrameAction>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+/*!
+ * \class QOrbitControl::QOrbitControl
+ * \internal
+ */
+
+QOrbitControlPrivate::QOrbitControlPrivate()
+ : Qt3DCore::QEntityPrivate()
+ , m_camera(Q_NULLPTR)
+ , m_leftMouseButtonAction(new Qt3DInput::QAction())
+ , m_rightMouseButtonAction(new Qt3DInput::QAction())
+ , m_altButtonAction(new Qt3DInput::QAction())
+ , m_shiftButtonAction(new Qt3DInput::QAction())
+ , m_rxAxis(new Qt3DInput::QAxis())
+ , m_ryAxis(new Qt3DInput::QAxis())
+ , m_txAxis(new Qt3DInput::QAxis())
+ , m_tyAxis(new Qt3DInput::QAxis())
+ , m_tzAxis(new Qt3DInput::QAxis())
+ , m_leftMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_rightMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_altButtonInput(new Qt3DInput::QActionInput())
+ , m_shiftButtonInput(new Qt3DInput::QActionInput())
+ , m_mouseRxInput(new Qt3DInput::QAxisInput())
+ , m_mouseRyInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTxPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTyPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTzPosInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTxNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTyNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardTzNegInput(new Qt3DInput::QAxisInput())
+ , m_keyboardDevice(new Qt3DInput::QKeyboardDevice())
+ , m_mouseDevice(new Qt3DInput::QMouseDevice())
+ , m_logicalDevice(new Qt3DInput::QLogicalDevice())
+ , m_frameAction(new Qt3DLogic::QFrameAction())
+ , m_linearSpeed(10.0f)
+ , m_lookSpeed(180.0f)
+ , m_zoomInLimit(2.0f)
+ , m_cameraUp(QVector3D(0.0f, 1.0f, 0.0f))
+{}
+
+void QOrbitControlPrivate::init()
+{
+ //// Actions
+
+ // Left Mouse Button Action
+ m_leftMouseButtonInput->setButtons(QVariantList() << Qt::LeftButton);
+ m_leftMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_leftMouseButtonAction->addInput(m_leftMouseButtonInput);
+
+ // Right Mouse Button Action
+ m_rightMouseButtonInput->setButtons(QVariantList() << Qt::RightButton);
+ m_rightMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_rightMouseButtonAction->addInput(m_rightMouseButtonInput);
+
+ // Alt Button Action
+ m_altButtonInput->setButtons(QVariantList() << Qt::Key_Alt);
+ m_altButtonInput->setSourceDevice(m_keyboardDevice);
+ m_altButtonAction->addInput(m_altButtonInput);
+
+ // Shift Button Action
+ m_shiftButtonInput->setButtons(QVariantList() << Qt::Key_Shift);
+ m_shiftButtonInput->setSourceDevice(m_keyboardDevice);
+ m_shiftButtonAction->addInput(m_shiftButtonInput);
+
+ //// Axes
+
+ // Mouse X
+ m_mouseRxInput->setAxis(Qt3DInput::QMouseDevice::X);
+ m_mouseRxInput->setSourceDevice(m_mouseDevice);
+ m_rxAxis->addInput(m_mouseRxInput);
+
+ // Mouse Y
+ m_mouseRyInput->setAxis(Qt3DInput::QMouseDevice::Y);
+ m_mouseRyInput->setSourceDevice(m_mouseDevice);
+ m_ryAxis->addInput(m_mouseRyInput);
+
+ // Keyboard Pos Tx
+ m_keyboardTxPosInput->setButtons(QVariantList() << Qt::Key_Right);
+ m_keyboardTxPosInput->setScale(1.0f);
+ m_keyboardTxPosInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxPosInput);
+
+ // Keyboard Pos Tz
+ m_keyboardTzPosInput->setButtons(QVariantList() << Qt::Key_PageUp);
+ m_keyboardTzPosInput->setScale(1.0f);
+ m_keyboardTzPosInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzPosInput);
+
+ // Keyboard Pos Ty
+ m_keyboardTyPosInput->setButtons(QVariantList() << Qt::Key_Up);
+ m_keyboardTyPosInput->setScale(1.0f);
+ m_keyboardTyPosInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyPosInput);
+
+ // Keyboard Neg Tx
+ m_keyboardTxNegInput->setButtons(QVariantList() << Qt::Key_Left);
+ m_keyboardTxNegInput->setScale(-1.0f);
+ m_keyboardTxNegInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxNegInput);
+
+ // Keyboard Neg Tz
+ m_keyboardTzNegInput->setButtons(QVariantList() << Qt::Key_PageDown);
+ m_keyboardTzNegInput->setScale(-1.0f);
+ m_keyboardTzNegInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzNegInput);
+
+ // Keyboard Neg Ty
+ m_keyboardTyNegInput->setButtons(QVariantList() << Qt::Key_Down);
+ m_keyboardTyNegInput->setScale(-1.0f);
+ m_keyboardTyNegInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyNegInput);
+
+ //// Logical Device
+
+ m_logicalDevice->addAction(m_leftMouseButtonAction);
+ m_logicalDevice->addAction(m_rightMouseButtonAction);
+ m_logicalDevice->addAction(m_altButtonAction);
+ m_logicalDevice->addAction(m_shiftButtonAction);
+ m_logicalDevice->addAxis(m_rxAxis);
+ m_logicalDevice->addAxis(m_ryAxis);
+ m_logicalDevice->addAxis(m_txAxis);
+ m_logicalDevice->addAxis(m_tyAxis);
+ m_logicalDevice->addAxis(m_tzAxis);
+
+ Q_Q(QOrbitControl);
+ //// FrameAction
+
+ QObject::connect(m_frameAction, SIGNAL(triggered(float)),
+ q, SLOT(_q_onTriggered(float)));
+
+ q->addComponent(m_frameAction);
+ q->addComponent(m_logicalDevice);
+}
+
+float clampInputs(float input1, float input2)
+{
+ float axisValue = input1 + input2;
+ return (axisValue < -1) ? -1 : (axisValue > 1) ? 1 : axisValue;
+}
+
+float zoomDistance(QVector3D firstPoint, QVector3D secondPoint)
+{
+ return (secondPoint - firstPoint).lengthSquared();
+}
+
+void QOrbitControlPrivate::_q_onTriggered(float dt)
+{
+ if (m_camera != Q_NULLPTR) {
+ // Mouse input
+ if (m_leftMouseButtonAction->isActive()) {
+ if (m_rightMouseButtonAction->isActive()) {
+ if ( zoomDistance(m_camera->position(), m_camera->viewCenter()) > m_zoomInLimit * m_zoomInLimit) {
+ // Dolly up to limit
+ m_camera->translate(QVector3D(0, 0, m_ryAxis->value()), m_camera->DontTranslateViewCenter);
+ } else {
+ m_camera->translate(QVector3D(0, 0, -0.5), m_camera->DontTranslateViewCenter);
+ }
+ } else {
+ // Translate
+ m_camera->translate(QVector3D(clampInputs(m_rxAxis->value(), m_txAxis->value()) * m_linearSpeed,
+ clampInputs(m_ryAxis->value(), m_tyAxis->value()) * m_linearSpeed,
+ 0) * dt);
+ return;
+ }
+ }
+ else if (m_rightMouseButtonAction->isActive()) {
+ // Orbit
+ m_camera->panAboutViewCenter((m_rxAxis->value() * m_lookSpeed) * dt, m_cameraUp);
+ m_camera->tiltAboutViewCenter((m_ryAxis->value() * m_lookSpeed) * dt);
+ }
+ // Keyboard Input
+ if (m_altButtonAction->isActive()) {
+ // Orbit
+ m_camera->panAboutViewCenter((m_txAxis->value() * m_lookSpeed) * dt, m_cameraUp);
+ m_camera->tiltAboutViewCenter((m_tyAxis->value() * m_lookSpeed) * dt);
+ } else if (m_shiftButtonAction->isActive()) {
+ if (zoomDistance(m_camera->position(), m_camera->viewCenter()) > m_zoomInLimit * m_zoomInLimit) {
+ // Dolly
+ m_camera->translate(QVector3D(0, 0, m_tyAxis->value()), m_camera->DontTranslateViewCenter);
+ } else {
+ m_camera->translate(QVector3D(0, 0, -0.5), m_camera->DontTranslateViewCenter);
+ }
+ } else {
+ // Translate
+ m_camera->translate(QVector3D(clampInputs(m_leftMouseButtonAction->isActive() ? m_rxAxis->value() : 0, m_txAxis->value()) * m_linearSpeed,
+ clampInputs(m_leftMouseButtonAction->isActive() ? m_ryAxis->value() : 0, m_tyAxis->value()) * m_linearSpeed,
+ m_tzAxis->value() * m_linearSpeed) * dt);
+ }
+ }
+}
+
+QOrbitControl::QOrbitControl(Qt3DCore::QNode *parent)
+ : Qt3DCore::QEntity(*new QOrbitControlPrivate, parent)
+{
+ Q_D(QOrbitControl);
+ d->init();
+}
+
+QOrbitControl::~QOrbitControl()
+{
+}
+
+Qt3DRender::QCamera *QOrbitControl::camera() const
+{
+ Q_D(const QOrbitControl);
+ return d->m_camera;
+}
+
+float QOrbitControl::linearSpeed() const
+{
+ Q_D(const QOrbitControl);
+ return d->m_linearSpeed;
+}
+
+float QOrbitControl::lookSpeed() const
+{
+ Q_D(const QOrbitControl);
+ return d->m_lookSpeed;
+}
+
+float QOrbitControl::zoomInLimit() const
+{
+ Q_D(const QOrbitControl);
+ return d->m_zoomInLimit;
+}
+
+void QOrbitControl::setCamera(Qt3DRender::QCamera *camera)
+{
+ Q_D(QOrbitControl);
+ if (d->m_camera != camera) {
+ d->m_camera = camera;
+ emit cameraChanged();
+ }
+}
+
+void QOrbitControl::setLinearSpeed(float linearSpeed)
+{
+ Q_D(QOrbitControl);
+ if (d->m_linearSpeed != linearSpeed) {
+ d->m_linearSpeed = linearSpeed;
+ emit linearSpeedChanged();
+ }
+}
+
+void QOrbitControl::setLookSpeed(float lookSpeed)
+{
+ Q_D(QOrbitControl);
+ if (d->m_lookSpeed != lookSpeed) {
+ d->m_lookSpeed = lookSpeed;
+ emit lookSpeedChanged();
+ }
+}
+
+void QOrbitControl::setZoomInLimit(float zoomInLimit)
+{
+ Q_D(QOrbitControl);
+ if (d->m_zoomInLimit != zoomInLimit) {
+ d->m_zoomInLimit = zoomInLimit;
+ emit zoomInLimitChanged();
+ }
+}
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#include "moc_qorbitcontrol.cpp"
diff --git a/src/extras/defaults/qorbitcontrol.h b/src/extras/defaults/qorbitcontrol.h
new file mode 100644
index 000000000..2fb0c0bb9
--- /dev/null
+++ b/src/extras/defaults/qorbitcontrol.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 QT3DEXTRAS_QORBITCONTROL_H
+#define QT3DEXTRAS_QORBITCONTROL_H
+
+#include <Qt3DExtras/qt3dextras_global.h>
+#include <Qt3DCore/QEntity>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DExtras {
+
+class QOrbitControlPrivate;
+
+class QT3DEXTRASSHARED_EXPORT QOrbitControl : public Qt3DCore::QEntity
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
+ Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
+ Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
+ Q_PROPERTY(float zoomInLimit READ zoomInLimit WRITE setZoomInLimit NOTIFY zoomInLimitChanged)
+
+public:
+ explicit QOrbitControl(Qt3DCore::QNode *parent = nullptr);
+ ~QOrbitControl();
+
+ float clampInputs(float input1, float input2);
+ Qt3DRender::QCamera *camera() const;
+ float linearSpeed() const;
+ float lookSpeed() const;
+ float zoomInLimit() const;
+
+ void setCamera(Qt3DRender::QCamera *camera);
+ void setLinearSpeed(float linearSpeed);
+ void setLookSpeed(float lookSpeed);
+ void setZoomInLimit(float zoomInLimit);
+
+Q_SIGNALS:
+ void cameraChanged();
+ void linearSpeedChanged();
+ void lookSpeedChanged();
+ void zoomInLimitChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QOrbitControl)
+ Q_PRIVATE_SLOT(d_func(), void _q_onTriggered(float))
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QORBITCONTROL_H
diff --git a/src/extras/defaults/qorbitcontrol_p.h b/src/extras/defaults/qorbitcontrol_p.h
new file mode 100644
index 000000000..e37ca50f6
--- /dev/null
+++ b/src/extras/defaults/qorbitcontrol_p.h
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** 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 QTINPUT_QORBITCONTROL_P_H
+#define QTINPUT_QORBITCONTROL_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/qentity_p.h>
+#include <QVector3D>
+#include "qorbitcontrol.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DLogic {
+class QFrameAction;
+}
+
+namespace Qt3DInput {
+
+class QKeyboardDevice;
+class QMouseDevice;
+class QLogicalDevice;
+class QAction;
+class QActionInput;
+class QAxis;
+class QAxisInput;
+class QAxisActionHandler;
+
+}
+
+namespace Qt3DExtras {
+
+class QOrbitControlPrivate : public Qt3DCore::QEntityPrivate
+{
+public:
+ QOrbitControlPrivate();
+
+ void init();
+
+ Qt3DRender::QCamera *m_camera;
+
+ Qt3DInput::QAction *m_leftMouseButtonAction;
+ Qt3DInput::QAction *m_rightMouseButtonAction;
+ Qt3DInput::QAction *m_altButtonAction;
+ Qt3DInput::QAction *m_shiftButtonAction;
+
+ Qt3DInput::QAxis *m_rxAxis;
+ Qt3DInput::QAxis *m_ryAxis;
+ Qt3DInput::QAxis *m_txAxis;
+ Qt3DInput::QAxis *m_tyAxis;
+ Qt3DInput::QAxis *m_tzAxis;
+
+ Qt3DInput::QActionInput *m_leftMouseButtonInput;
+ Qt3DInput::QActionInput *m_rightMouseButtonInput;
+ Qt3DInput::QActionInput *m_altButtonInput;
+ Qt3DInput::QActionInput *m_shiftButtonInput;
+
+ Qt3DInput::QAxisInput *m_mouseRxInput;
+ Qt3DInput::QAxisInput *m_mouseRyInput;
+ Qt3DInput::QAxisInput *m_keyboardTxPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTyPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTzPosInput;
+ Qt3DInput::QAxisInput *m_keyboardTxNegInput;
+ Qt3DInput::QAxisInput *m_keyboardTyNegInput;
+ Qt3DInput::QAxisInput *m_keyboardTzNegInput;
+
+ Qt3DInput::QKeyboardDevice *m_keyboardDevice;
+ Qt3DInput::QMouseDevice *m_mouseDevice;
+
+ Qt3DInput::QLogicalDevice *m_logicalDevice;
+
+ Qt3DLogic::QFrameAction *m_frameAction;
+
+ float m_linearSpeed;
+ float m_lookSpeed;
+ float m_zoomInLimit;
+ QVector3D m_cameraUp;
+
+ void _q_onTriggered(float);
+
+ Q_DECLARE_PUBLIC(QOrbitControl)
+};
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QORBITCONTROL_P_H
diff --git a/src/extras/defaults/qt3dwindow.cpp b/src/extras/defaults/qt3dwindow.cpp
new file mode 100644
index 000000000..eed9d8862
--- /dev/null
+++ b/src/extras/defaults/qt3dwindow.cpp
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qt3dwindow.h"
+
+#include <Qt3DExtras/qforwardrenderer.h>
+#include <Qt3DRender/qrendersettings.h>
+#include <Qt3DRender/qrenderaspect.h>
+#include <Qt3DInput/qinputaspect.h>
+#include <Qt3DInput/qinputsettings.h>
+#include <Qt3DLogic/qlogicaspect.h>
+
+#include <Qt3DCore/qaspectengine.h>
+#include <Qt3DRender/qcamera.h>
+#include <Qt3DCore/qentity.h>
+
+#include <QtGui/qopenglcontext.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+Qt3DWindow::Qt3DWindow(QScreen *screen)
+ : QWindow(screen)
+ , m_aspectEngine(new Qt3DCore::QAspectEngine)
+ , m_renderAspect(new Qt3DRender::QRenderAspect)
+ , m_inputAspect(new Qt3DInput::QInputAspect)
+ , m_logicAspect(new Qt3DLogic::QLogicAspect)
+ , m_renderSettings(new Qt3DRender::QRenderSettings)
+ , m_forwardRenderer(new Qt3DExtras::QForwardRenderer)
+ , m_defaultCamera(new Qt3DRender::QCamera)
+ , m_inputSettings(new Qt3DInput::QInputSettings)
+ , m_root(new Qt3DCore::QEntity)
+ , m_userRoot(nullptr)
+ , m_initialized(false)
+{
+ setSurfaceType(QSurface::OpenGLSurface);
+
+ resize(1024, 768);
+
+ QSurfaceFormat format;
+#ifdef QT_OPENGL_ES_2
+ format.setRenderableType(QSurfaceFormat::OpenGLES);
+#else
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
+ format.setVersion(4, 3);
+ format.setProfile(QSurfaceFormat::CoreProfile);
+ }
+#endif
+ format.setDepthBufferSize(24);
+ format.setSamples(4);
+ format.setStencilBufferSize(8);
+ setFormat(format);
+ create();
+
+ m_aspectEngine->registerAspect(m_renderAspect);
+ m_aspectEngine->registerAspect(m_inputAspect);
+ m_aspectEngine->registerAspect(m_logicAspect);
+
+ m_defaultCamera->setParent(m_root);
+ m_forwardRenderer->setCamera(m_defaultCamera);
+ m_forwardRenderer->setSurface(this);
+ m_renderSettings->setActiveFrameGraph(m_forwardRenderer);
+ m_inputSettings->setEventSource(this);
+}
+
+Qt3DWindow::~Qt3DWindow()
+{
+}
+
+void Qt3DWindow::registerAspect(Qt3DCore::QAbstractAspect *aspect)
+{
+ Q_ASSERT(!isVisible());
+ m_aspectEngine->registerAspect(aspect);
+}
+
+void Qt3DWindow::registerAspect(const QString &name)
+{
+ Q_ASSERT(!isVisible());
+ m_aspectEngine->registerAspect(name);
+}
+
+void Qt3DWindow::setRootEntity(Qt3DCore::QEntity *root)
+{
+ Q_ASSERT(!isVisible());
+ m_userRoot = root;
+}
+
+void Qt3DWindow::setActiveFrameGraph(Qt3DRender::QFrameGraphNode *activeFrameGraph)
+{
+ m_renderSettings->setActiveFrameGraph(activeFrameGraph);
+}
+
+Qt3DRender::QFrameGraphNode *Qt3DWindow::activeFrameGraph() const
+{
+ return m_renderSettings->activeFrameGraph();
+}
+
+Qt3DExtras::QForwardRenderer *Qt3DWindow::defaultFramegraph() const
+{
+ return m_forwardRenderer;
+}
+
+Qt3DRender::QCamera *Qt3DWindow::camera() const
+{
+ return m_defaultCamera;
+}
+
+void Qt3DWindow::showEvent(QShowEvent *e)
+{
+ if (!m_initialized) {
+ if (m_userRoot != nullptr)
+ m_userRoot->setParent(m_root);
+
+ m_root->addComponent(m_renderSettings);
+ m_root->addComponent(m_inputSettings);
+ m_aspectEngine->setRootEntity(Qt3DCore::QEntityPtr(m_root));
+
+ m_initialized = true;
+ }
+
+ QWindow::showEvent(e);
+}
+
+void Qt3DWindow::resizeEvent(QResizeEvent *)
+{
+ m_defaultCamera->setAspectRatio(float(width()) / float(height()));
+}
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
diff --git a/src/extras/defaults/qt3dwindow.h b/src/extras/defaults/qt3dwindow.h
new file mode 100644
index 000000000..1d73966de
--- /dev/null
+++ b/src/extras/defaults/qt3dwindow.h
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DWINDOW_H
+#define QT3DWINDOW_H
+
+#include <QWindow>
+#include <Qt3DExtras/qt3dextras_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+class QAspectEngine;
+class QAbstractAspect;
+class QEntity;
+}
+
+namespace Qt3DRender {
+class QCamera;
+class QFrameGraphNode;
+class QRenderAspect;
+class QRenderSettings;
+}
+
+namespace Qt3DExtras {
+class QForwardRenderer;
+}
+
+namespace Qt3DInput {
+class QInputAspect;
+class QInputSettings;
+}
+
+namespace Qt3DLogic {
+class QLogicAspect;
+}
+
+namespace Qt3DExtras {
+
+class QT3DEXTRASSHARED_EXPORT Qt3DWindow : public QWindow
+{
+ Q_OBJECT
+public:
+ Qt3DWindow(QScreen *screen = nullptr);
+ ~Qt3DWindow();
+
+ void registerAspect(Qt3DCore::QAbstractAspect *aspect);
+ void registerAspect(const QString &name);
+
+ void setRootEntity(Qt3DCore::QEntity *root);
+
+ void setActiveFrameGraph(Qt3DRender::QFrameGraphNode *activeFrameGraph);
+ Qt3DRender::QFrameGraphNode *activeFrameGraph() const;
+ Qt3DExtras::QForwardRenderer *defaultFramegraph() const;
+
+ Qt3DRender::QCamera *camera() const;
+
+public Q_SLOTS:
+
+Q_SIGNALS:
+
+protected:
+ void showEvent(QShowEvent *e) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<Qt3DCore::QAspectEngine> m_aspectEngine;
+
+ // Aspects
+ Qt3DRender::QRenderAspect *m_renderAspect;
+ Qt3DInput::QInputAspect *m_inputAspect;
+ Qt3DLogic::QLogicAspect *m_logicAspect;
+
+ // Renderer configuration
+ Qt3DRender::QRenderSettings *m_renderSettings;
+ Qt3DExtras::QForwardRenderer *m_forwardRenderer;
+ Qt3DRender::QCamera *m_defaultCamera;
+
+ // Input configuration
+ Qt3DInput::QInputSettings *m_inputSettings;
+
+ // Logic configuration
+
+ // Scene
+ Qt3DCore::QEntity *m_root;
+ Qt3DCore::QEntity *m_userRoot;
+
+ bool m_initialized;
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DWINDOW_H
diff --git a/src/extras/extras.pro b/src/extras/extras.pro
index 3b7758007..57ba35652 100644
--- a/src/extras/extras.pro
+++ b/src/extras/extras.pro
@@ -1,6 +1,6 @@
TARGET = Qt3DExtras
MODULE = 3dextras
-QT += core-private 3dcore 3dcore-private 3drender 3drender-private
+QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dinput 3dlogic
DEFINES += QT3DEXTRAS_LIBRARY