summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Brock <robert.brock@kdab.com>2016-01-28 11:22:58 +0000
committerSean Harmer <sean.harmer@kdab.com>2016-03-24 18:43:10 +0000
commita1470b6b380a4612264956b1e09484c6752da20e (patch)
tree88430325ddf1579e50593b75700c200a86030876
parent0832616efeb705d31e26ba88ea47210210f046d9 (diff)
OrbitController Qml and Cpp for Qt3D Camera
Adding an Orbit control that will allow a user to orbit / pan in a 3D QML scene. --- QML - LMB translate - RMB orbit - RMB + LMB dolly - Arrow keys translate - Shift + Up/Down keys dolly - Alt + Arrow keys orbit --- CPP - LMB translate - RMB orbit - RMB + LMB dolly - Arrow keys translate - Shift + Up/Down keys dolly - Alt + Arrow keys orbit Both examples have their speed inputs clamped to -1 and 1 Zoom in can now be limited Change-Id: If24c45c7350767a1682dccfd2e4d49d95433fd5d Task-number: QTBUG-50660 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--examples/qt3d/cylinder-cpp/main.cpp4
-rw-r--r--examples/qt3d/cylinder-qml/main.qml2
-rw-r--r--examples/qt3d/examples-common/OrbitController.qml235
-rw-r--r--examples/qt3d/examples-common/examples-common.pro4
-rw-r--r--examples/qt3d/examples-common/qorbitcontrol.cpp320
-rw-r--r--examples/qt3d/examples-common/qorbitcontrol.h90
-rw-r--r--examples/qt3d/examples-common/qorbitcontrol_p.h131
-rw-r--r--examples/qt3d/examples-common/qt3dwindow.cpp2
-rw-r--r--src/input/frontend/frontend.pri1
-rw-r--r--src/input/input.pro2
-rw-r--r--src/src.pro10
11 files changed, 790 insertions, 11 deletions
diff --git a/examples/qt3d/cylinder-cpp/main.cpp b/examples/qt3d/cylinder-cpp/main.cpp
index 96876fd7d..22442d813 100644
--- a/examples/qt3d/cylinder-cpp/main.cpp
+++ b/examples/qt3d/cylinder-cpp/main.cpp
@@ -69,7 +69,7 @@
#include <Qt3DCore/qaspectengine.h>
#include "qt3dwindow.h"
-#include "qfirstpersoncameracontroller.h"
+#include "qorbitcontrol.h"
int main(int argc, char **argv)
{
@@ -87,7 +87,7 @@ int main(int argc, char **argv)
camera->setViewCenter(QVector3D(0, 0, 0));
// For camera controls
- Qt3DInput::QFirstPersonCameraController *cameraController = new Qt3DInput::QFirstPersonCameraController(rootEntity);
+ Qt3DInput::QOrbitControl *cameraController = new Qt3DInput::QOrbitControl(rootEntity);
cameraController->setCamera(camera);
// Cylinder shape data
diff --git a/examples/qt3d/cylinder-qml/main.qml b/examples/qt3d/cylinder-qml/main.qml
index decdab1c4..3735c8569 100644
--- a/examples/qt3d/cylinder-qml/main.qml
+++ b/examples/qt3d/cylinder-qml/main.qml
@@ -67,7 +67,7 @@ Entity {
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}
- FirstPersonCameraController { camera: camera }
+ OrbitController { camera: camera }
RenderSettings {
id : external_forward_renderer
diff --git a/examples/qt3d/examples-common/OrbitController.qml b/examples/qt3d/examples-common/OrbitController.qml
new file mode 100644
index 000000000..5a88f9d19
--- /dev/null
+++ b/examples/qt3d/examples-common/OrbitController.qml
@@ -0,0 +1,235 @@
+/****************************************************************************
+**
+** 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;
+ }
+
+ KeyboardController {
+ 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.pro b/examples/qt3d/examples-common/examples-common.pro
index 7b56b9b54..b5be67137 100644
--- a/examples/qt3d/examples-common/examples-common.pro
+++ b/examples/qt3d/examples-common/examples-common.pro
@@ -5,17 +5,21 @@ QT += core-private 3dcore 3dcore-private 3drender 3dinput 3dlogic qml quick
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 += \
diff --git a/examples/qt3d/examples-common/qorbitcontrol.cpp b/examples/qt3d/examples-common/qorbitcontrol.cpp
new file mode 100644
index 000000000..4f35158f6
--- /dev/null
+++ b/examples/qt3d/examples-common/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 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
new file mode 100644
index 000000000..a99e38b66
--- /dev/null
+++ b/examples/qt3d/examples-common/qorbitcontrol.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 = Q_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
new file mode 100644
index 000000000..34f853685
--- /dev/null
+++ b/examples/qt3d/examples-common/qorbitcontrol_p.h
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** 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/qt3dwindow.cpp b/examples/qt3d/examples-common/qt3dwindow.cpp
index 5ad068d62..f4556fc66 100644
--- a/examples/qt3d/examples-common/qt3dwindow.cpp
+++ b/examples/qt3d/examples-common/qt3dwindow.cpp
@@ -101,7 +101,6 @@ Qt3DWindow::Qt3DWindow(QScreen *screen)
m_forwardRenderer->setCamera(m_defaultCamera);
m_forwardRenderer->setSurface(this);
m_renderSettings->setActiveFrameGraph(m_forwardRenderer);
-
m_inputSettings->setEventSource(this);
}
@@ -140,7 +139,6 @@ Qt3DWindow::Qt3DWindow(QWindow *parent)
m_forwardRenderer->setCamera(m_defaultCamera);
m_forwardRenderer->setSurface(this);
m_renderSettings->setActiveFrameGraph(m_forwardRenderer);
-
m_inputSettings->setEventSource(this);
}
diff --git a/src/input/frontend/frontend.pri b/src/input/frontend/frontend.pri
index bd45acb2e..9012b1600 100644
--- a/src/input/frontend/frontend.pri
+++ b/src/input/frontend/frontend.pri
@@ -40,6 +40,7 @@ HEADERS += \
$$PWD/qinputsequence_p.h \
$$PWD/qinputchord_p.h
+
SOURCES += \
$$PWD/qinputaspect.cpp \
$$PWD/qkeyboarddevice.cpp \
diff --git a/src/input/input.pro b/src/input/input.pro
index aa559c664..1c1ad8611 100644
--- a/src/input/input.pro
+++ b/src/input/input.pro
@@ -1,6 +1,6 @@
TARGET = Qt3DInput
-QT += core core-private 3dcore 3dcore-private 3drender
+QT += core core-private 3dcore 3dcore-private 3drender 3dlogic
DEFINES += QT3DINPUT_LIBRARY
diff --git a/src/src.pro b/src/src.pro
index 097d2df25..82d53cbf1 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -7,14 +7,14 @@ src_render.subdir = $$PWD/render
src_render.target = sub-render
src_render.depends = src_core
-src_input.subdir = $$PWD/input
-src_input.target = sub-input
-src_input.depends = src_render
-
src_logic.subdir = $$PWD/logic
src_logic.target = sub-logic
src_logic.depends = src_core
+src_input.subdir = $$PWD/input
+src_input.target = sub-input
+src_input.depends = src_render
+
# Quick3D libs
src_quick3d_core.subdir = $$PWD/quick3d/quick3d
src_quick3d_core.target = sub-quick3d-core
@@ -57,8 +57,8 @@ src_plugins_sceneparsers.depends = src_render
SUBDIRS += \
src_core \
src_render \
- src_input \
src_logic \
+ src_input \
src_quick3d_core \
src_quick3d_core_imports \
src_quick3d_render \