diff options
Diffstat (limited to 'examples/qt3d/examples-common')
-rw-r--r-- | examples/qt3d/examples-common/FirstPersonCameraController.qml | 176 | ||||
-rw-r--r-- | examples/qt3d/examples-common/OrbitController.qml | 235 | ||||
-rw-r--r-- | examples/qt3d/examples-common/examples-common.pri | 20 | ||||
-rw-r--r-- | examples/qt3d/examples-common/examples-common.pro | 48 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qfirstpersoncameracontroller.cpp | 253 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qfirstpersoncameracontroller.h | 99 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qfirstpersoncameracontroller_p.h | 129 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qorbitcontrol.cpp | 320 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qorbitcontrol.h | 90 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qorbitcontrol_p.h | 131 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qt3dquickwindow.cpp | 246 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qt3dquickwindow.h | 131 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qt3dwindow.cpp | 175 | ||||
-rw-r--r-- | examples/qt3d/examples-common/qt3dwindow.h | 137 |
14 files changed, 0 insertions, 2190 deletions
diff --git a/examples/qt3d/examples-common/FirstPersonCameraController.qml b/examples/qt3d/examples-common/FirstPersonCameraController.qml deleted file mode 100644 index e6950140d..000000000 --- a/examples/qt3d/examples-common/FirstPersonCameraController.qml +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Paul Lemire <paul.lemire350@gmail.com> -** 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$ -** -****************************************************************************/ - -import Qt3D.Core 2.0 -import Qt3D.Render 2.0 -import Qt3D.Input 2.0 -import Qt3D.Logic 2.0 -import QtQml 2.2 - -Entity { - id: root - property Camera camera - property real linearSpeed: 10.0 - property real lookSpeed: 180.0 - - QtObject { - id: d - readonly property vector3d firstPersonUp: Qt.vector3d(0, 1, 0) - readonly property bool leftMouseButtonPressed: leftMouseButtonAction.active - readonly property real vx: txAxis.value * linearSpeed; - readonly property real vy: tyAxis.value * linearSpeed; - readonly property real vz: tzAxis.value * linearSpeed; - readonly property real dx: rxAxis.value * lookSpeed - readonly property real dy: ryAxis.value * lookSpeed - readonly property bool fineMotion: fineMotionAction.active - } - - KeyboardDevice { - id: keyboardSourceDevice - } - - MouseDevice { - id: mouseSourceDevice - sensitivity: d.fineMotion ? 0.01 : 0.1 - } - - components: [ - - LogicalDevice { - actions: [ - Action { - id: leftMouseButtonAction - ActionInput { - sourceDevice: mouseSourceDevice - buttons: [MouseEvent.LeftButton] - } - }, - Action { - id: fineMotionAction - ActionInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Shift] - } - } - ] // actions - - axes: [ - // Rotation - Axis { - id: rxAxis - AxisInput { - sourceDevice: mouseSourceDevice - axis: MouseDevice.X - } - }, - Axis { - id: ryAxis - AxisInput { - sourceDevice: mouseSourceDevice - axis: MouseDevice.Y - } - }, - // Translation - Axis { - id: txAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Left] - scale: -1.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Right] - scale: 1.0 - } - }, - Axis { - id: tzAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Up] - scale: 1.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Down] - scale: -1.0 - } - }, - Axis { - id: tyAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_PageUp] - scale: 1.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_PageDown] - scale: -1.0 - } - } - ] // axes - }, - - FrameAction { - onTriggered: { - // The time difference since the last frame is passed in as the - // argument dt. It is a floating point value in units of seconds. - root.camera.translate(Qt.vector3d(d.vx, d.vy, d.vz).times(dt)) - - if (d.leftMouseButtonPressed) { - root.camera.pan(d.dx * dt, d.firstPersonUp) - root.camera.tilt(d.dy * dt) - } - } - } - ] // components -} diff --git a/examples/qt3d/examples-common/OrbitController.qml b/examples/qt3d/examples-common/OrbitController.qml deleted file mode 100644 index bba114730..000000000 --- a/examples/qt3d/examples-common/OrbitController.qml +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Paul Lemire <paul.lemire350@gmail.com> -** 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$ -** -****************************************************************************/ - -import Qt3D.Core 2.0 -import Qt3D.Render 2.0 -import Qt3D.Input 2.0 -import Qt3D.Logic 2.0 -import QtQml 2.2 - -Entity { - id: root - property Camera camera - property real linearSpeed: 10.0 - property real lookSpeed: 180.0 - property real zoomLimit: 2.0 - - QtObject { - id: d - readonly property vector3d firstPersonUp: Qt.vector3d(0, 1, 0) - readonly property bool leftMouseButtonPressed: leftMouseButtonAction.active - readonly property bool rightMouseButtonPressed: rightMouseButtonAction.active - readonly property bool shiftPressed: shiftAction.active - readonly property bool altPressed: altAction.active - property real translationX: clampInputs(leftMouseButtonPressed ? mouseXAxis.value : 0, keyboardXAxis.value) * linearSpeed; - property real translationY: clampInputs(leftMouseButtonPressed ? mouseYAxis.value : 0, keyboardYAxis.value) * linearSpeed; - property real translationZ: keyboardZAxis.value * linearSpeed; - property real orbitX: clampInputs(rightMouseButtonPressed ? mouseXAxis.value : 0, keyboardXAxis.value) * lookSpeed; - property real orbitY: clampInputs(rightMouseButtonPressed ? mouseYAxis.value : 0, keyboardYAxis.value) * lookSpeed; - } - - function clampInputs(input1, input2) { - var axisValue = input1 + input2; - return (axisValue < -1) ? -1 : (axisValue > 1) ? 1 : axisValue; - } - - function zoomDistance(firstPoint, secondPoint) { - var u = secondPoint.minus(firstPoint); u = u.times(u); - return u.x + u.y + u.z; - } - - KeyboardDevice { - id: keyboardSourceDevice - } - - MouseDevice { - id: mouseSourceDevice - sensitivity: 0.1 - } - - components: [ - - LogicalDevice { - actions: [ - Action { - id: leftMouseButtonAction - ActionInput { - sourceDevice: mouseSourceDevice - buttons: [MouseEvent.LeftButton] - } - }, - Action { - id: rightMouseButtonAction - ActionInput { - sourceDevice: mouseSourceDevice - buttons: [MouseEvent.RightButton] - } - }, - Action { - id: shiftAction - ActionInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Shift] - } - }, - Action { - id: altAction - ActionInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Alt] - } - } - ] // actions - - axes: [ - // Mouse - Axis { - id: mouseXAxis - AxisInput { - sourceDevice: mouseSourceDevice - axis: MouseDevice.X - } - }, - Axis { - id: mouseYAxis - AxisInput { - sourceDevice: mouseSourceDevice - axis: MouseDevice.Y - } - }, - // Keyboard - Axis { - id: keyboardXAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Left] - scale: -1.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Right] - scale: 1.0 - } - }, - Axis { - id: keyboardZAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Up] - scale: d.shiftPressed ? 1.0 : 0.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Down] - scale: d.shiftPressed ? -1.0 : 0.0 - } - }, - Axis { - id: keyboardYAxis - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Up] - scale: d.shiftPressed ? 0.0 : 1.0 - } - AxisInput { - sourceDevice: keyboardSourceDevice - buttons: [Qt.Key_Down] - scale: d.shiftPressed ? 0.0 : -1.0 - } - } - ] // axes - }, - - FrameAction { - onTriggered: { - // The time difference since the last frame is passed in as the - // argument dt. It is a floating point value in units of seconds. - - // Mouse input - if (d.leftMouseButtonPressed) { - if (d.rightMouseButtonPressed) { - if (zoomDistance(root.camera.position, root.camera.viewCenter) > root.zoomLimit * root.zoomLimit) { - // Dolly up to limit - root.camera.translate(Qt.vector3d(0, 0, d.translationY).times(dt), Camera.DontTranslateViewCenter); - } else { - // Too close, Dolly backwards - root.camera.translate(Qt.vector3d(0, 0, -1).times(dt), Camera.DontTranslateViewCenter); - } - } else { - // Translate - root.camera.translate(Qt.vector3d(d.translationX, d.translationY, 0).times(dt)); - return - } - } else if (d.rightMouseButtonPressed) { - // Orbit - root.camera.panAboutViewCenter(d.orbitX * dt, d.firstPersonUp); - root.camera.tiltAboutViewCenter(d.orbitY * dt); - } - // Keyboard input - if (d.altPressed) { - // Orbit - root.camera.panAboutViewCenter(d.orbitX * dt, d.firstPersonUp); - root.camera.tiltAboutViewCenter(d.orbitY * dt); - } else if (d.shiftPressed) { - if (zoomDistance(root.camera.position, root.camera.viewCenter) > root.zoomLimit * root.zoomLimit) { - // Dolly up to limit - root.camera.translate(Qt.vector3d(0, 0, d.translationZ).times(dt), Camera.DontTranslateViewCenter); - } else { - // Too close, Dolly backwards - root.camera.translate(Qt.vector3d(0, 0, -1).times(dt), Camera.DontTranslateViewCenter); - } - } else { - // Translate - root.camera.translate(Qt.vector3d(d.translationX, d.translationY, 0).times(dt)); - } - } - } - ] // components -} diff --git a/examples/qt3d/examples-common/examples-common.pri b/examples/qt3d/examples-common/examples-common.pri deleted file mode 100644 index ddfea6765..000000000 --- a/examples/qt3d/examples-common/examples-common.pri +++ /dev/null @@ -1,20 +0,0 @@ -QT += 3dcore 3drender 3dinput 3dlogic qml 3dextras - -INCLUDEPATH += $$PWD - -win32 { - build_pass { - CONFIG(debug, debug|release) { - common_static_lib = $$OUT_PWD/../examples-common/debug/$${QMAKE_PREFIX_STATICLIB}examples-common.$${QMAKE_EXTENSION_STATICLIB} - } else { - common_static_lib = $$OUT_PWD/../examples-common/release/$${QMAKE_PREFIX_STATICLIB}examples-common.$${QMAKE_EXTENSION_STATICLIB} - } - } - LIBS += $$common_static_lib - PRE_TARGETDEPS += $$common_static_lib -} else { - LIBS += -L$$OUT_PWD/../examples-common -l$$qtLibraryTarget(examples-common) - PRE_TARGETDEPS += $$OUT_PWD/../examples-common/lib$$qtLibraryTarget(examples-common).a -} - -RESOURCES += $$OUT_PWD/../examples-common/examples-common.qrc diff --git a/examples/qt3d/examples-common/examples-common.pro b/examples/qt3d/examples-common/examples-common.pro deleted file mode 100644 index a11a77ee5..000000000 --- a/examples/qt3d/examples-common/examples-common.pro +++ /dev/null @@ -1,48 +0,0 @@ -TEMPLATE = lib -CONFIG += staticlib -TARGET = $$qtLibraryTarget(examples-common) -QT += core-private 3dcore 3dcore-private 3drender 3dinput 3dlogic qml quick 3dextras - -SOURCES += \ - qfirstpersoncameracontroller.cpp \ - qorbitcontrol.cpp \ - qt3dwindow.cpp \ - qt3dquickwindow.cpp - - -HEADERS += \ - qfirstpersoncameracontroller.h \ - qfirstpersoncameracontroller_p.h \ - qorbitcontrol_p.h \ - qorbitcontrol.h \ - qt3dwindow.h \ - qt3dquickwindow.h - -QML_FILES = \ - $$PWD/OrbitController.qml \ - $$PWD/FirstPersonCameraController.qml - -OTHER_FILES += \ - $$QML_FILES - -# Create a resource file for qml files that need to be registered by the plugin -GENERATED_RESOURCE_FILE = $$OUT_PWD/examples-common.qrc -INCLUDED_RESOURCE_FILES = $$QML_FILES -RESOURCE_CONTENT = \ - "<RCC>" \ - "<qresource prefix=\"/\">" - -for(resourcefile, INCLUDED_RESOURCE_FILES) { - resourcefileabsolutepath = $$absolute_path($$resourcefile) - relativepath_in = $$relative_path($$resourcefileabsolutepath, $$_PRO_FILE_PWD_) - relativepath_out = $$relative_path($$resourcefileabsolutepath, $$OUT_PWD) - RESOURCE_CONTENT += "<file alias=\"$$relativepath_in\">$$relativepath_out</file>" -} - -RESOURCE_CONTENT += \ - "</qresource>" \ - "</RCC>" - -write_file($$GENERATED_RESOURCE_FILE, RESOURCE_CONTENT)|error("Aborting.") - -RESOURCES += $$GENERATED_RESOURCE_FILE diff --git a/examples/qt3d/examples-common/qfirstpersoncameracontroller.cpp b/examples/qt3d/examples-common/qfirstpersoncameracontroller.cpp deleted file mode 100644 index 3e0bd2c68..000000000 --- a/examples/qt3d/examples-common/qfirstpersoncameracontroller.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/**************************************************************************** -** -** 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 Qt3DInput { - - -QFirstPersonCameraControllerPrivate::QFirstPersonCameraControllerPrivate() - : Qt3DCore::QEntityPrivate() - , m_camera(Q_NULLPTR) - , m_leftMouseButtonAction(new QAction()) - , m_fineMotionAction(new QAction()) - , m_rxAxis(new QAxis()) - , m_ryAxis(new QAxis()) - , m_txAxis(new QAxis()) - , m_tyAxis(new QAxis()) - , m_tzAxis(new QAxis()) - , m_leftMouseButtonInput(new QActionInput()) - , m_fineMotionKeyInput(new QActionInput()) - , m_mouseRxInput(new QAxisInput()) - , m_mouseRyInput(new QAxisInput()) - , m_keyboardTxPosInput(new QAxisInput()) - , m_keyboardTyPosInput(new QAxisInput()) - , m_keyboardTzPosInput(new QAxisInput()) - , m_keyboardTxNegInput(new QAxisInput()) - , m_keyboardTyNegInput(new QAxisInput()) - , m_keyboardTzNegInput(new QAxisInput()) - , m_keyboardDevice(new QKeyboardDevice()) - , m_mouseDevice(new QMouseDevice()) - , m_logicalDevice(new 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() << QMouseEvent::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(QMouseDevice::X); - m_mouseRxInput->setSourceDevice(m_mouseDevice); - m_rxAxis->addInput(m_mouseRxInput); - - // Mouse Y - m_mouseRyInput->setAxis(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(); - } -} - -} // Qt3DInput - -QT_END_NAMESPACE - -#include "moc_qfirstpersoncameracontroller.cpp" diff --git a/examples/qt3d/examples-common/qfirstpersoncameracontroller.h b/examples/qt3d/examples-common/qfirstpersoncameracontroller.h deleted file mode 100644 index 5b9019586..000000000 --- a/examples/qt3d/examples-common/qfirstpersoncameracontroller.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** 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 QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_H -#define QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_H - -#include <Qt3DCore/QEntity> - -QT_BEGIN_NAMESPACE - -namespace Qt3DRender { -class QCamera; -} - -namespace Qt3DInput { - -class QFirstPersonCameraControllerPrivate; - -class 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)) -}; - -} // Qt3DInput - -QT_END_NAMESPACE - -#endif // QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_H diff --git a/examples/qt3d/examples-common/qfirstpersoncameracontroller_p.h b/examples/qt3d/examples-common/qfirstpersoncameracontroller_p.h deleted file mode 100644 index 4df7278d1..000000000 --- a/examples/qt3d/examples-common/qfirstpersoncameracontroller_p.h +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_P_H -#define QT3DINPUT_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; - -class QFirstPersonCameraControllerPrivate : public Qt3DCore::QEntityPrivate -{ -public: - QFirstPersonCameraControllerPrivate(); - - void init(); - - Qt3DRender::QCamera *m_camera; - - QAction *m_leftMouseButtonAction; - QAction *m_fineMotionAction; - - QAxis *m_rxAxis; - QAxis *m_ryAxis; - QAxis *m_txAxis; - QAxis *m_tyAxis; - QAxis *m_tzAxis; - - QActionInput *m_leftMouseButtonInput; - QActionInput *m_fineMotionKeyInput; - - QAxisInput *m_mouseRxInput; - QAxisInput *m_mouseRyInput; - QAxisInput *m_keyboardTxPosInput; - QAxisInput *m_keyboardTyPosInput; - QAxisInput *m_keyboardTzPosInput; - QAxisInput *m_keyboardTxNegInput; - QAxisInput *m_keyboardTyNegInput; - QAxisInput *m_keyboardTzNegInput; - - QKeyboardDevice *m_keyboardDevice; - QMouseDevice *m_mouseDevice; - - 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/examples/qt3d/examples-common/qorbitcontrol.cpp b/examples/qt3d/examples-common/qorbitcontrol.cpp deleted file mode 100644 index 4f35158f6..000000000 --- a/examples/qt3d/examples-common/qorbitcontrol.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/**************************************************************************** -** -** 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 Qt3DInput { - -/*! - * \class QOrbitControl::QOrbitControl - * \internal - */ - -QOrbitControlPrivate::QOrbitControlPrivate() - : Qt3DCore::QEntityPrivate() - , m_camera(Q_NULLPTR) - , m_leftMouseButtonAction(new QAction()) - , m_rightMouseButtonAction(new QAction()) - , m_altButtonAction(new QAction()) - , m_shiftButtonAction(new QAction()) - , m_rxAxis(new QAxis()) - , m_ryAxis(new QAxis()) - , m_txAxis(new QAxis()) - , m_tyAxis(new QAxis()) - , m_tzAxis(new QAxis()) - , m_leftMouseButtonInput(new QActionInput()) - , m_rightMouseButtonInput(new QActionInput()) - , m_altButtonInput(new QActionInput()) - , m_shiftButtonInput(new QActionInput()) - , m_mouseRxInput(new QAxisInput()) - , m_mouseRyInput(new QAxisInput()) - , m_keyboardTxPosInput(new QAxisInput()) - , m_keyboardTyPosInput(new QAxisInput()) - , m_keyboardTzPosInput(new QAxisInput()) - , m_keyboardTxNegInput(new QAxisInput()) - , m_keyboardTyNegInput(new QAxisInput()) - , m_keyboardTzNegInput(new QAxisInput()) - , m_keyboardDevice(new QKeyboardDevice()) - , m_mouseDevice(new QMouseDevice()) - , m_logicalDevice(new 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() << QMouseEvent::LeftButton); - m_leftMouseButtonInput->setSourceDevice(m_mouseDevice); - m_leftMouseButtonAction->addInput(m_leftMouseButtonInput); - - // Right Mouse Button Action - m_rightMouseButtonInput->setButtons(QVariantList() << QMouseEvent::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(QMouseDevice::X); - m_mouseRxInput->setSourceDevice(m_mouseDevice); - m_rxAxis->addInput(m_mouseRxInput); - - // Mouse Y - m_mouseRyInput->setAxis(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(); - } -} - -} // Qt3DInput - -QT_END_NAMESPACE - -#include "moc_qorbitcontrol.cpp" diff --git a/examples/qt3d/examples-common/qorbitcontrol.h b/examples/qt3d/examples-common/qorbitcontrol.h deleted file mode 100644 index dbfc6e08d..000000000 --- a/examples/qt3d/examples-common/qorbitcontrol.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 QT3DINPUT_QORBITCONTROL_H -#define QT3DINPUT_QORBITCONTROL_H - -#include <Qt3DCore/QEntity> - -QT_BEGIN_NAMESPACE - -namespace Qt3DRender { -class QCamera; -} - -namespace Qt3DInput { - -class QOrbitControlPrivate; - -class 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)) -}; - -} // Qt3DInput - -QT_END_NAMESPACE - -#endif // QT3DINPUT_QORBITCONTROL_H diff --git a/examples/qt3d/examples-common/qorbitcontrol_p.h b/examples/qt3d/examples-common/qorbitcontrol_p.h deleted file mode 100644 index 34f853685..000000000 --- a/examples/qt3d/examples-common/qorbitcontrol_p.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** 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; - -class QOrbitControlPrivate : public Qt3DCore::QEntityPrivate -{ -public: - QOrbitControlPrivate(); - - void init(); - - Qt3DRender::QCamera *m_camera; - - QAction *m_leftMouseButtonAction; - QAction *m_rightMouseButtonAction; - QAction *m_altButtonAction; - QAction *m_shiftButtonAction; - - QAxis *m_rxAxis; - QAxis *m_ryAxis; - QAxis *m_txAxis; - QAxis *m_tyAxis; - QAxis *m_tzAxis; - - QActionInput *m_leftMouseButtonInput; - QActionInput *m_rightMouseButtonInput; - QActionInput *m_altButtonInput; - QActionInput *m_shiftButtonInput; - - QAxisInput *m_mouseRxInput; - QAxisInput *m_mouseRyInput; - QAxisInput *m_keyboardTxPosInput; - QAxisInput *m_keyboardTyPosInput; - QAxisInput *m_keyboardTzPosInput; - QAxisInput *m_keyboardTxNegInput; - QAxisInput *m_keyboardTyNegInput; - QAxisInput *m_keyboardTzNegInput; - - QKeyboardDevice *m_keyboardDevice; - QMouseDevice *m_mouseDevice; - - 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 Qt3DInput - -QT_END_NAMESPACE - -#endif // QTINPUT_QORBITCONTROL_P_H diff --git a/examples/qt3d/examples-common/qt3dquickwindow.cpp b/examples/qt3d/examples-common/qt3dquickwindow.cpp deleted file mode 100644 index 1537b4e71..000000000 --- a/examples/qt3d/examples-common/qt3dquickwindow.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** 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 "qt3dquickwindow.h" -#include <Qt3DQuick/QQmlAspectEngine> -#include <Qt3DRender/qcamera.h> -#include <Qt3DRender/qrenderaspect.h> -#include <Qt3DRender/qrendersettings.h> -#include <Qt3DRender/qrendersurfaceselector.h> -#include <Qt3DInput/qinputaspect.h> -#include <Qt3DInput/qinputsettings.h> -#include <Qt3DLogic/qlogicaspect.h> - -#include <QQmlContext> - -#include <QtGui/qopenglcontext.h> - -QT_BEGIN_NAMESPACE - -Qt3DQuickWindow::Qt3DQuickWindow(QWindow *parent) - : QQuickWindow(parent) - , m_engine(Q_NULLPTR) - , m_renderAspect(Q_NULLPTR) - , m_inputAspect(Q_NULLPTR) - , m_logicAspect(Q_NULLPTR) - , m_initialized(false) - , m_cameraAspectRatioMode(AutomaticAspectRatio) -{ - 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); - QSurfaceFormat::setDefaultFormat(format); - create(); - - m_engine.reset(new Qt3DCore::Quick::QQmlAspectEngine); - m_renderAspect = new Qt3DRender::QRenderAspect; - m_inputAspect = new Qt3DInput::QInputAspect; - m_logicAspect = new Qt3DLogic::QLogicAspect; - - m_engine->aspectEngine()->registerAspect(m_renderAspect); - m_engine->aspectEngine()->registerAspect(m_inputAspect); - m_engine->aspectEngine()->registerAspect(m_logicAspect); -} - -Qt3DQuickWindow::~Qt3DQuickWindow() -{ -} - -void Qt3DQuickWindow::registerAspect(Qt3DCore::QAbstractAspect *aspect) -{ - Q_ASSERT(!isVisible()); - m_engine->aspectEngine()->registerAspect(aspect); -} - -void Qt3DQuickWindow::registerAspect(const QString &name) -{ - Q_ASSERT(!isVisible()); - m_engine->aspectEngine()->registerAspect(name); -} - -void Qt3DQuickWindow::setSource(const QUrl &source) -{ - m_source = source; -} - -Qt3DCore::Quick::QQmlAspectEngine *Qt3DQuickWindow::engine() const -{ - return m_engine.data(); -} - -void Qt3DQuickWindow::setCameraAspectRatioMode(CameraAspectRatioMode mode) -{ - if (m_cameraAspectRatioMode == mode) - return; - - m_cameraAspectRatioMode = mode; - setCameraAspectModeHelper(); - emit cameraAspectRatioModeChanged(mode); -} - -Qt3DQuickWindow::CameraAspectRatioMode Qt3DQuickWindow::cameraAspectRatioMode() const -{ - return m_cameraAspectRatioMode; -} - -void Qt3DQuickWindow::showEvent(QShowEvent *e) -{ - if (!m_initialized) { - - // Connect to the QQmlAspectEngine's statusChanged signal so that when the QML is loaded - // and th eobjects hav ebeen instantiated, but before we set them on the QAspectEngine we - // can swoop in and set the window surface and camera on the framegraph and ensure the camera - // respects the window's aspect ratio - connect(m_engine.data(), &Qt3DCore::Quick::QQmlAspectEngine::sceneCreated, - this, &Qt3DQuickWindow::onSceneCreated); - - m_engine->setSource(m_source); - - // Set the QQmlIncubationController on the window - // to benefit from asynchronous incubation - m_engine->qmlEngine()->setIncubationController(QQuickWindow::incubationController()); - - m_initialized = true; - } - QQuickWindow::showEvent(e); -} - -void Qt3DQuickWindow::onSceneCreated(QObject *rootObject) -{ - Q_ASSERT(rootObject); - - setWindowSurface(rootObject); - - if (m_cameraAspectRatioMode == AutomaticAspectRatio) { - // Set aspect ratio of first camera to match the window - QList<Qt3DRender::QCamera *> cameras - = rootObject->findChildren<Qt3DRender::QCamera *>(); - if (cameras.isEmpty()) { - qWarning() << "No camera found"; - } else { - m_camera = cameras.first(); - setCameraAspectModeHelper(); - } - } - - // Set ourselves up as a source of input events for the input aspect - Qt3DInput::QInputSettings *inputSettings = rootObject->findChild<Qt3DInput::QInputSettings *>(); - if (inputSettings) { - inputSettings->setEventSource(this); - } else { - qWarning() << "No Input Settings found, keyboard and mouse events won't be handled"; - } -} - -void Qt3DQuickWindow::setWindowSurface(QObject *rootObject) -{ - // Find surface selector in framegraph and set ourselves up as the - // render surface there - Qt3DRender::QRenderSettings *rendererSettings - = rootObject->findChild<Qt3DRender::QRenderSettings *>(); - if (!rendererSettings) { - qWarning() << "No renderer settings component found"; - return; - } - - Qt3DCore::QNode *frameGraphRoot = rendererSettings->activeFrameGraph(); - if (!frameGraphRoot) { - qWarning() << "No active frame graph found"; - return; - } - - Qt3DRender::QRenderSurfaceSelector *surfaceSelector = qobject_cast<Qt3DRender::QRenderSurfaceSelector *>(frameGraphRoot); - if (!surfaceSelector) - surfaceSelector = frameGraphRoot->findChild<Qt3DRender::QRenderSurfaceSelector *>(); - if (!surfaceSelector) { - qWarning() << "No render surface selector found in frame graph"; - return; - } - - surfaceSelector->setSurface(this); -} - -void Qt3DQuickWindow::setCameraAspectModeHelper() -{ - switch (m_cameraAspectRatioMode) { - case AutomaticAspectRatio: - connect(this, &QWindow::widthChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio); - connect(this, &QWindow::heightChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio); - break; - case UserAspectRatio: - disconnect(this, &QWindow::widthChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio); - disconnect(this, &QWindow::heightChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio); - break; - } -} - -void Qt3DQuickWindow::updateCameraAspectRatio() -{ - if (m_camera) { - m_camera->setAspectRatio(static_cast<float>(width()) / - static_cast<float>(height())); - } -} - -QT_END_NAMESPACE diff --git a/examples/qt3d/examples-common/qt3dquickwindow.h b/examples/qt3d/examples-common/qt3dquickwindow.h deleted file mode 100644 index 5a01be779..000000000 --- a/examples/qt3d/examples-common/qt3dquickwindow.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** 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 QT3DQUICKWINDOW_H -#define QT3DQUICKWINDOW_H - -#include <QQuickWindow> -#include <QtCore/qpointer.h> -#include <QUrl> - -QT_BEGIN_NAMESPACE - -namespace Qt3DCore { -class QAbstractAspect; -namespace Quick { -class QQmlAspectEngine; -} -} - -namespace Qt3DRender { -class QRenderAspect; -class QCamera; -} - -namespace Qt3DInput { -class QInputAspect; -} - -namespace Qt3DLogic { -class QLogicAspect; -} - -class Qt3DQuickWindow : public QQuickWindow -{ - Q_OBJECT - Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged) - -public: - Qt3DQuickWindow(QWindow *parent = Q_NULLPTR); - ~Qt3DQuickWindow(); - - void registerAspect(Qt3DCore::QAbstractAspect *aspect); - void registerAspect(const QString &name); - - void setSource(const QUrl &source); - Qt3DCore::Quick::QQmlAspectEngine *engine() const; - - enum CameraAspectRatioMode { - AutomaticAspectRatio, - UserAspectRatio - }; - Q_ENUM(CameraAspectRatioMode); - - void setCameraAspectRatioMode(CameraAspectRatioMode mode); - CameraAspectRatioMode cameraAspectRatioMode() const; - -Q_SIGNALS: - void cameraAspectRatioModeChanged(CameraAspectRatioMode mode); - -protected: - void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; - -private: - void onSceneCreated(QObject *rootObject); - void setWindowSurface(QObject *rootObject); - void setCameraAspectModeHelper(); - void updateCameraAspectRatio(); - - QScopedPointer<Qt3DCore::Quick::QQmlAspectEngine> m_engine; - - // Aspects - Qt3DRender::QRenderAspect *m_renderAspect; - Qt3DInput::QInputAspect *m_inputAspect; - Qt3DLogic::QLogicAspect *m_logicAspect; - - QUrl m_source; - bool m_initialized; - QPointer<Qt3DRender::QCamera> m_camera; - CameraAspectRatioMode m_cameraAspectRatioMode; -}; - -QT_END_NAMESPACE - -#endif // QT3DQUICKWINDOW_H diff --git a/examples/qt3d/examples-common/qt3dwindow.cpp b/examples/qt3d/examples-common/qt3dwindow.cpp deleted file mode 100644 index 4c0bfc21a..000000000 --- a/examples/qt3d/examples-common/qt3dwindow.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** 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 - -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())); -} - -QT_END_NAMESPACE diff --git a/examples/qt3d/examples-common/qt3dwindow.h b/examples/qt3d/examples-common/qt3dwindow.h deleted file mode 100644 index 5cb71d1d9..000000000 --- a/examples/qt3d/examples-common/qt3dwindow.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** 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> - -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; -} - -class 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; -}; - -QT_END_NAMESPACE - -#endif // QT3DWINDOW_H |