summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/qardboard
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qt3d/qardboard')
-rw-r--r--examples/qt3d/qardboard/Info.plist35
-rw-r--r--examples/qt3d/qardboard/PlacedEntity.qml82
-rw-r--r--examples/qt3d/qardboard/QardboardCamera.qml124
-rw-r--r--examples/qt3d/qardboard/QardboardFrameGraph.qml90
-rw-r--r--examples/qt3d/qardboard/QardboardRootEntity.qml105
-rw-r--r--examples/qt3d/qardboard/QardboardScene3D.qml68
-rw-r--r--examples/qt3d/qardboard/abstractdeviceorientation.cpp112
-rw-r--r--examples/qt3d/qardboard/abstractdeviceorientation.h96
-rw-r--r--examples/qt3d/qardboard/dummydeviceorientation.cpp73
-rw-r--r--examples/qt3d/qardboard/dummydeviceorientation.h68
-rw-r--r--examples/qt3d/qardboard/iosdeviceorientation.h68
-rw-r--r--examples/qt3d/qardboard/iosdeviceorientation.mm77
-rw-r--r--examples/qt3d/qardboard/iosdeviceorientation_p.h63
-rw-r--r--examples/qt3d/qardboard/iosdeviceorientation_p.mm154
-rw-r--r--examples/qt3d/qardboard/main.cpp85
-rw-r--r--examples/qt3d/qardboard/main.qml205
-rw-r--r--examples/qt3d/qardboard/qardboard.pro35
-rw-r--r--examples/qt3d/qardboard/resources.qrc10
18 files changed, 1550 insertions, 0 deletions
diff --git a/examples/qt3d/qardboard/Info.plist b/examples/qt3d/qardboard/Info.plist
new file mode 100644
index 000000000..26c5fe5e2
--- /dev/null
+++ b/examples/qt3d/qardboard/Info.plist
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleGetInfoString</key>
+ <string>Created by Qt/QMake</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleExecutable</key>
+ <string>qardboard</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.kdab.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
diff --git a/examples/qt3d/qardboard/PlacedEntity.qml b/examples/qt3d/qardboard/PlacedEntity.qml
new file mode 100644
index 000000000..b0d73634b
--- /dev/null
+++ b/examples/qt3d/qardboard/PlacedEntity.qml
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Extras 2.0
+
+Entity {
+ id: root
+ property double angle: 0
+ property double radius: 10
+ property var mesh
+ property alias color: material.diffuse
+ property vector3d center: Qt.vector3d(0, 0, 0)
+
+ components: [
+ Transform {
+ id: tr
+ matrix: {
+ var ra = 0// (root.angle) * Math.PI / 180
+ var m = Qt.matrix4x4()
+ m.rotate(root.angle, Qt.vector3d(0, 1, 0))
+ m.translate(Qt.vector3d(root.center.x + root.radius * Math.sin(ra), root.center.y, root.center.z - root.radius * Math.cos(ra)))
+ return m
+ }
+ }
+ ]
+
+ Entity {
+ PhongMaterial {
+ id: material
+ }
+ components: [ material, mesh ]
+ }
+}
diff --git a/examples/qt3d/qardboard/QardboardCamera.qml b/examples/qt3d/qardboard/QardboardCamera.qml
new file mode 100644
index 000000000..1912b8a22
--- /dev/null
+++ b/examples/qt3d/qardboard/QardboardCamera.qml
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+
+Entity {
+ id: root
+ property real convergence: 2000.0
+ property real eyeSeparation: 35.0
+ property real aspectRatio: _window.width / _window.height
+ property real fieldOfView: 60.0
+ property real nearPlane: 1.
+ property real farPlane: 1000.0
+
+ property vector3d position: Qt.vector3d(0.0, 0.0, 0.0)
+ property vector3d viewDirection: Qt.vector3d(0.0, 0.0, 1.0)
+ property vector3d viewUp: Qt.vector3d(0.0, 1.0, 0.0)
+ property alias viewMatrix: leftEyeTransform.matrix
+
+ readonly property real _fov2: Math.tan(fieldOfView * Math.PI / 180 * 0.5)
+ readonly property real top: nearPlane * _fov2
+ readonly property real a: aspectRatio * _fov2 * convergence
+
+ CameraLens {
+ id: leftEyeLens
+ projectionType: CameraLens.FrustumProjection
+ nearPlane : root.nearPlane
+ farPlane : root.farPlane
+ left: -(a - eyeSeparation * 0.5) * nearPlane / convergence
+ right: (a + eyeSeparation * 0.5) * nearPlane / convergence
+ top: root.top
+ bottom: -root.top
+ }
+
+ CameraLens {
+ id: rightEyeLens
+ projectionType: CameraLens.FrustumProjection
+ nearPlane : root.nearPlane
+ farPlane : root.farPlane
+ left: -(a + eyeSeparation * 0.5) * nearPlane / convergence
+ right: (a - eyeSeparation * 0.5) * nearPlane / convergence
+ top: root.top
+ bottom: -root.top
+ }
+
+ Transform {
+ id: leftEyeTransform
+
+ matrix: {
+ var m = Qt.matrix4x4();
+ m.lookAt(root.position, root.position + root.viewDirection, root.viewUp);
+ return m;
+ }
+ }
+
+ Transform {
+ id: rightEyeTransform
+
+ matrix: leftEyeTransform.matrix
+ }
+
+ property Entity leftCamera: Entity {
+ components: [
+ leftEyeLens,
+ leftEyeTransform
+ ]
+ }
+
+ property Entity rightCamera: Entity {
+ id: rightCameraEntity
+ components: [
+ rightEyeLens,
+ rightEyeTransform
+ ]
+ }
+}
diff --git a/examples/qt3d/qardboard/QardboardFrameGraph.qml b/examples/qt3d/qardboard/QardboardFrameGraph.qml
new file mode 100644
index 000000000..195076c70
--- /dev/null
+++ b/examples/qt3d/qardboard/QardboardFrameGraph.qml
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+
+Viewport {
+ property alias leftCamera: leftCameraSelector.camera
+ property alias rightCamera: rightCameraSelector.camera
+ property alias window: surfaceSelector.surface
+
+ RenderSurfaceSelector {
+ id: surfaceSelector
+
+ // ColorMask is reset by default
+ // By default reset to the default if not specified
+ ClearBuffers {
+ clearColor: "white"
+ buffers: ClearBuffers.ColorDepthBuffer
+ NoDraw {} // We just want to clear the buffers
+ }
+
+ // Draw with left eye
+ Viewport {
+ id: leftViewport
+ normalizedRect: Qt.rect(0, 0, .5, 1)
+
+ CameraSelector {
+ id: leftCameraSelector
+ }
+ }
+
+ // Draw with right eye
+ Viewport {
+ id: rightViewport
+ normalizedRect: Qt.rect(.5, 0, .5, 1)
+
+ CameraSelector {
+ id: rightCameraSelector
+ }
+ }
+ }
+}
diff --git a/examples/qt3d/qardboard/QardboardRootEntity.qml b/examples/qt3d/qardboard/QardboardRootEntity.qml
new file mode 100644
index 000000000..85e4fbc7e
--- /dev/null
+++ b/examples/qt3d/qardboard/QardboardRootEntity.qml
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Input 2.0
+import Qardboard 1.0
+
+Entity {
+ id: root
+ property alias fieldOfView: stereoCamera.fieldOfView
+ property alias cameraPosition: stereoCamera.position
+ property alias cameraDirection: stereoCamera.viewDirection
+ property alias headlightDirection: headLight.worldDirection
+
+ components: [
+ RenderSettings {
+ activeFrameGraph: QardboardFrameGraph {
+ id: stereoFrameGraph
+ leftCamera: stereoCamera.leftCamera
+ rightCamera: stereoCamera.rightCamera
+ }
+ },
+ InputSettings { },
+ DirectionalLight {
+ id: headLight
+ worldDirection: stereoCamera.viewDirection.times(-1)
+ }
+ ]
+
+ DeviceOrientation {
+ id: orientation
+ enabled: true
+ }
+
+ QardboardCamera {
+ id: stereoCamera
+ viewMatrix: computeMatrix(orientation.roll, orientation.pitch, orientation.yaw)
+
+ property vector3d vc
+ property vector3d vd
+ property vector3d vu
+
+ function computeMatrix(roll, pitch, yaw) {
+ var m = Qt.matrix4x4()
+ m.rotate(-roll, Qt.vector3d(1, 0, 0))
+ m.rotate(yaw, Qt.vector3d(0, 1, 0))
+ vd = m.times(stereoCamera.viewDirection)
+ vu = m.times(stereoCamera.viewUp)
+ var r = Qt.matrix4x4()
+ vc = stereoCamera.position.minus(vd)
+ r.lookAt(stereoCamera.position, vc, vu)
+// console.log(roll.toFixed(2), pitch.toFixed(2), yaw.toFixed(2), stereoCamera.position, vd, vc, vu)
+// console.log(r)
+ return r
+ }
+ }
+}
diff --git a/examples/qt3d/qardboard/QardboardScene3D.qml b/examples/qt3d/qardboard/QardboardScene3D.qml
new file mode 100644
index 000000000..01c7ba771
--- /dev/null
+++ b/examples/qt3d/qardboard/QardboardScene3D.qml
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Scene3D 2.0
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Input 2.0
+import Qt3D.Extras 2.0
+
+Scene3D {
+ id: scene3d
+ focus: true
+ aspects: ["input", "logic"]
+ cameraAspectRatioMode: Scene3D.UserAspectRatio
+ multisample: true
+
+ QardboardRootEntity {
+ }
+}
diff --git a/examples/qt3d/qardboard/abstractdeviceorientation.cpp b/examples/qt3d/qardboard/abstractdeviceorientation.cpp
new file mode 100644
index 000000000..d8e869439
--- /dev/null
+++ b/examples/qt3d/qardboard/abstractdeviceorientation.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "abstractdeviceorientation.h"
+
+#include <QDateTime>
+#include <QDebug>
+#include <QtMath>
+#include <QScreen>
+
+
+AbstractDeviceOrientation::AbstractDeviceOrientation(QObject *parent)
+ : QObject(parent)
+ , m_roll(0)
+ , m_pitch(0)
+ , m_yaw(0)
+ , m_enabled(false)
+{
+}
+
+bool AbstractDeviceOrientation::enabled() const
+{
+ return m_enabled;
+}
+
+void AbstractDeviceOrientation::stop()
+{
+ if (m_enabled) {
+ m_enabled = false;
+ emit enabledChanged(m_enabled);
+ }
+}
+
+void AbstractDeviceOrientation::setRoll(qreal v)
+{
+ if (v != m_roll) {
+ m_roll = v;
+ emit rollChanged(v);
+ }
+}
+
+void AbstractDeviceOrientation::setPitch(qreal v)
+{
+ if (v != m_pitch) {
+ m_pitch = v;
+ emit pitchChanged(v);
+ }
+}
+
+void AbstractDeviceOrientation::setYaw(qreal v)
+{
+ if (v != m_yaw) {
+ m_yaw = v;
+ emit yawChanged(v);
+ }
+}
+
+void AbstractDeviceOrientation::setEnabled(bool v)
+{
+ if (v && !m_enabled) {
+ start();
+ } else if (!v && m_enabled) {
+ stop();
+ }
+}
diff --git a/examples/qt3d/qardboard/abstractdeviceorientation.h b/examples/qt3d/qardboard/abstractdeviceorientation.h
new file mode 100644
index 000000000..ea06c6cab
--- /dev/null
+++ b/examples/qt3d/qardboard/abstractdeviceorientation.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 ABSTRACT_DEVICEORIENTATION_H
+#define ABSTRACT_DEVICEORIENTATION_H
+
+#include <QObject>
+
+class AbstractDeviceOrientation : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal roll READ roll WRITE setRoll NOTIFY rollChanged)
+ Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
+ Q_PROPERTY(qreal yaw READ yaw WRITE setYaw NOTIFY yawChanged)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
+
+public:
+ AbstractDeviceOrientation(QObject* parent = 0);
+
+ qreal roll() const { return m_roll; }
+ qreal pitch() const { return m_pitch; }
+ qreal yaw() const { return m_yaw; }
+
+ bool enabled() const;
+
+signals:
+ void rollChanged(qreal roll);
+ void pitchChanged(qreal pitch);
+ void yawChanged(qreal yaw);
+ void enabledChanged(bool);
+
+public slots:
+ virtual void setRoll(qreal v);
+ virtual void setPitch(qreal v);
+ virtual void setYaw(qreal v);
+ virtual void setEnabled(bool v);
+
+ virtual bool start() = 0; //!< Called to start the sensor services.
+ virtual void stop(); //!< Called to stop updates from the #CompassClino.
+
+protected:
+ qreal m_roll;
+ qreal m_pitch;
+ qreal m_yaw;
+ bool m_enabled;
+};
+
+
+#endif // ABSTRACT_DEVICEORIENTATION_H
diff --git a/examples/qt3d/qardboard/dummydeviceorientation.cpp b/examples/qt3d/qardboard/dummydeviceorientation.cpp
new file mode 100644
index 000000000..ddf9580e6
--- /dev/null
+++ b/examples/qt3d/qardboard/dummydeviceorientation.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "dummydeviceorientation.h"
+
+DummyDeviceOrientation::DummyDeviceOrientation(QObject *parent)
+ : AbstractDeviceOrientation(parent)
+{
+}
+
+bool DummyDeviceOrientation::start()
+{
+ if (!m_enabled) {
+ m_enabled = true;
+ emit enabledChanged(m_enabled);
+ }
+ return true;
+}
+
+void DummyDeviceOrientation::stop()
+{
+ if (m_enabled) {
+ m_enabled = false;
+ emit enabledChanged(m_enabled);
+ }
+}
diff --git a/examples/qt3d/qardboard/dummydeviceorientation.h b/examples/qt3d/qardboard/dummydeviceorientation.h
new file mode 100644
index 000000000..4f18ea4ad
--- /dev/null
+++ b/examples/qt3d/qardboard/dummydeviceorientation.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 DUMMY_DEVICEORIENTATION_H
+#define DUMMY_DEVICEORIENTATION_H
+
+#include <abstractdeviceorientation.h>
+
+class DummyDeviceOrientation : public AbstractDeviceOrientation
+{
+ Q_OBJECT
+public:
+ DummyDeviceOrientation(QObject* parent = 0);
+
+public slots:
+ bool start() override;
+ void stop() override;
+};
+
+
+#endif // DUMMY_DEVICEORIENTATION_H
diff --git a/examples/qt3d/qardboard/iosdeviceorientation.h b/examples/qt3d/qardboard/iosdeviceorientation.h
new file mode 100644
index 000000000..8f18595dc
--- /dev/null
+++ b/examples/qt3d/qardboard/iosdeviceorientation.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 IOS_DEVICEORIENTATION_H
+#define IOS_DEVICEORIENTATION_H
+
+#include <abstractdeviceorientation.h>
+
+class iOSDeviceOrientation : public AbstractDeviceOrientation
+{
+ Q_OBJECT
+public:
+ iOSDeviceOrientation(QObject* parent = 0);
+
+public slots:
+ bool start() override;
+ void stop() override;
+};
+
+
+#endif // IOS_DEVICEORIENTATION_H
diff --git a/examples/qt3d/qardboard/iosdeviceorientation.mm b/examples/qt3d/qardboard/iosdeviceorientation.mm
new file mode 100644
index 000000000..c66208136
--- /dev/null
+++ b/examples/qt3d/qardboard/iosdeviceorientation.mm
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "iosdeviceorientation.h"
+#include "iosdeviceorientation_p.h"
+
+iOSDeviceOrientation::iOSDeviceOrientation(QObject *parent)
+ : AbstractDeviceOrientation(parent)
+{
+ [[iOSDeviceOrientationP instance] setHandler:this];
+}
+
+bool iOSDeviceOrientation::start()
+{
+ if (!m_enabled) {
+ [[iOSDeviceOrientationP instance] start];
+ m_enabled = true;
+ emit enabledChanged(m_enabled);
+ }
+ return true;
+}
+
+void iOSDeviceOrientation::stop()
+{
+ if (m_enabled) {
+ [[iOSDeviceOrientationP instance] stop];
+ m_enabled = false;
+ emit enabledChanged(m_enabled);
+ }
+}
diff --git a/examples/qt3d/qardboard/iosdeviceorientation_p.h b/examples/qt3d/qardboard/iosdeviceorientation_p.h
new file mode 100644
index 000000000..ec32a5a91
--- /dev/null
+++ b/examples/qt3d/qardboard/iosdeviceorientation_p.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+#import <Foundation/Foundation.h>
+#import <CoreLocation/CoreLocation.h>
+#import <CoreMotion/CoreMotion.h>
+
+
+@interface iOSDeviceOrientationP : NSObject <CLLocationManagerDelegate>
+@property (readonly) BOOL isActive;
+
++ (iOSDeviceOrientationP*)instance;
+- (void)setHandler:(iOSDeviceOrientation*) handler;
+- (void)start;
+- (void)stop;
+@end
diff --git a/examples/qt3d/qardboard/iosdeviceorientation_p.mm b/examples/qt3d/qardboard/iosdeviceorientation_p.mm
new file mode 100644
index 000000000..4e7db4820
--- /dev/null
+++ b/examples/qt3d/qardboard/iosdeviceorientation_p.mm
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+#include "iosdeviceorientation.h"
+#import "iosdeviceorientation_p.h"
+
+#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
+#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
+
+
+@interface QIOSMotionManager : NSObject {
+}
+
++ (CMMotionManager *)sharedManager;
+@end
+
+@interface iOSDeviceOrientationP()
+{
+ BOOL active;
+ iOSDeviceOrientation* handler;
+}
+
+@property (strong) CMMotionManager *motionManager;
+@end
+
+
+
+@implementation iOSDeviceOrientationP
+
+#define kUpdateFrequency 20.0
+
+
++ (iOSDeviceOrientationP*)instance
+{
+ static iOSDeviceOrientationP* _myInstance = 0;
+ if (0 == _myInstance)
+ _myInstance = [[iOSDeviceOrientationP alloc] init];
+ return _myInstance;
+}
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ self.motionManager = [QIOSMotionManager sharedManager]; // [[CMMotionManager alloc] init];
+ self.motionManager.deviceMotionUpdateInterval = 1. / kUpdateFrequency;
+
+ active = FALSE;
+ }
+ return self;
+}
+
+- (void)setHandler:(iOSDeviceOrientation*)h
+{
+ handler = h;
+}
+
+- (BOOL)isActive
+{
+ return active;
+}
+
+- (void)start
+{
+ // Motion updates
+ [self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical
+ toQueue:[NSOperationQueue currentQueue]
+ withHandler: ^(CMDeviceMotion *motion, NSError *error) {
+ //CMAttitude *attitude = motion.attitude;
+ //NSLog(@"rotation rate = [%f, %f, %f]", attitude.pitch, attitude.roll, attitude.yaw);
+ if (error)
+ NSLog(@"%@", [error description]);
+ else
+ [self performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES];
+ }];
+ active = TRUE;
+}
+
+- (void)stop
+{
+ [_motionManager stopDeviceMotionUpdates];
+ active = FALSE;
+}
+
+- (void)handleDeviceMotion:(CMDeviceMotion*)motion
+{
+ if (!active)
+ return;
+
+ if (motion.magneticField.accuracy == CMMagneticFieldCalibrationAccuracyUncalibrated)
+ return;
+
+ // X: A pitch is a rotation around a lateral axis that passes through the device from side to side.
+ // Y: A roll is a rotation around a longitudinal axis that passes through the device from its top to bottom.
+ // Z: A yaw is a rotation around an axis that runs vertically through the device. It is perpendicular to the
+ // body of the device, with its origin at the center of gravity and directed toward the bottom of the device.
+
+ CMAttitude *attitude = motion.attitude;
+ handler->setRoll(90 - RADIANS_TO_DEGREES(attitude.roll));
+ handler->setPitch(RADIANS_TO_DEGREES(attitude.pitch));
+ handler->setYaw(RADIANS_TO_DEGREES(attitude.yaw));
+}
+
+@end
diff --git a/examples/qt3d/qardboard/main.cpp b/examples/qt3d/qardboard/main.cpp
new file mode 100644
index 000000000..412f0fc88
--- /dev/null
+++ b/examples/qt3d/qardboard/main.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 <Qt3DQuickExtras/qt3dquickwindow.h>
+#include <Qt3DQuick/QQmlAspectEngine>
+#include <QGuiApplication>
+#include <QQmlEngine>
+#include <QQmlContext>
+
+#ifdef Q_OS_IOS
+#include "iosdeviceorientation.h"
+#else
+#include "dummydeviceorientation.h"
+#endif
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Qt3DExtras::Quick::Qt3DQuickWindow view;
+
+#ifdef Q_OS_IOS
+ qmlRegisterType<iOSDeviceOrientation>("Qardboard", 1, 0, "DeviceOrientation");
+#else
+ qmlRegisterType<DummyDeviceOrientation>("Qardboard", 1, 0, "DeviceOrientation");
+#endif
+
+ view.engine()->qmlEngine()->rootContext()->setContextProperty(QStringLiteral("_window"), &view);
+ view.setSource(QUrl("qrc:/main.qml"));
+#ifdef Q_OS_IOS
+ view.showFullScreen();
+#else
+ view.resize(800, 400);
+ view.show();
+#endif
+
+ return app.exec();
+}
diff --git a/examples/qt3d/qardboard/main.qml b/examples/qt3d/qardboard/main.qml
new file mode 100644
index 000000000..b273c0f57
--- /dev/null
+++ b/examples/qt3d/qardboard/main.qml
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Extras 2.0
+import QtQuick 2.4 as QQ2
+
+QardboardRootEntity {
+ id: root
+ cameraPosition: cameraController.position
+
+ Entity {
+ id: cameraController
+
+ function posAtAngle(a) {
+ return Qt.vector3d(cameraRadius * Math.cos(a), 0.0, cameraRadius * Math.sin(a))
+ }
+ function rotAtAngle(a) {
+ return a * 180 / Math.PI + 90
+ }
+
+ property real circleRotation: 0
+ readonly property real cameraRadius: obstaclesRepeater.radius
+ readonly property vector3d circlePosition: cameraController.posAtAngle(cameraController.circleRotation)
+ property vector3d position: planeTransform.translation.plus(Qt.vector3d(0, 0, 35))
+
+ QQ2.NumberAnimation {
+ target: cameraController
+ property: "circleRotation"
+ from: 0; to: Math.PI * 2
+ duration: 10000
+ loops: QQ2.Animation.Infinite
+ running: true
+ }
+ }
+
+ // AirPlane
+ Entity {
+ components: [
+ Mesh {
+ source: "assets/obj/toyplane.obj"
+ },
+ Transform {
+ id: planeTransform
+ property real rollAngle: 0.0
+ translation: cameraController.posAtAngle(cameraController.circleRotation)
+ rotation: fromAxesAndAngles(Qt.vector3d(1.0, 0.0, 0.0), planeTransform.rollAngle,
+ Qt.vector3d(0.0, -1.0, 0.0), cameraController.rotAtAngle(cameraController.circleRotation))
+ },
+ PhongMaterial {
+ shininess: 20.0
+ diffuse: "#ba1a02" // Inferno Orange
+ }
+ ]
+
+ QQ2.SequentialAnimation {
+ running: true
+ loops: QQ2.Animation.Infinite
+
+ QQ2.NumberAnimation {
+ target: planeTransform
+ property: "rollAngle"
+ from: -30; to: 45
+ duration: 1500
+ }
+ QQ2.NumberAnimation {
+ target: planeTransform
+ property: "rollAngle"
+ from: 45; to: -30
+ duration: 3500
+ }
+ }
+ }
+
+ // Cylinder
+ Entity {
+ property CylinderMesh cylinder: CylinderMesh {
+ radius: 1
+ length: 3
+ rings: 100
+ slices: 20
+ }
+ property Transform transform: Transform {
+ id: cylinderTransform
+ property real theta: 0.0
+ property real phi: 0.0
+ rotation: fromEulerAngles(theta, phi, 0)
+ }
+ property Material phong: PhongMaterial {}
+
+ QQ2.ParallelAnimation {
+ loops: QQ2.Animation.Infinite
+ running: true
+ QQ2.SequentialAnimation {
+ QQ2.NumberAnimation {
+ target: cylinderTransform
+ property: "scale"
+ from: 5; to: 45
+ duration: 2000
+ easing.type: QQ2.Easing.OutInQuad
+ }
+ QQ2.NumberAnimation {
+ target: cylinderTransform
+ property: "scale"
+ from: 45; to: 5
+ duration: 2000
+ easing.type: QQ2.Easing.InOutQuart
+ }
+ }
+ QQ2.NumberAnimation {
+ target: cylinderTransform
+ property: "phi"
+ from: 0; to: 360
+ duration: 4000
+ }
+ QQ2.NumberAnimation {
+ target: cylinderTransform
+ property: "theta"
+ from: 0; to: 720
+ duration: 4000
+ }
+ }
+
+ components: [cylinder, transform, phong]
+ }
+
+ // Torus obsctacles
+ NodeInstantiator {
+ id: obstaclesRepeater
+ model: 4
+ readonly property real radius: 130.0;
+ readonly property real det: 1.0 / model
+ delegate: Entity {
+ components: [
+ TorusMesh {
+ radius: 35
+ minorRadius: 5
+ rings: 100
+ slices: 20
+ },
+ Transform {
+ id: transform
+ readonly property real angle: Math.PI * 2.0 * index * obstaclesRepeater.det
+ translation: Qt.vector3d(obstaclesRepeater.radius * Math.cos(transform.angle),
+ 0.0,
+ obstaclesRepeater.radius * Math.sin(transform.angle))
+ rotation: fromAxisAndAngle(Qt.vector3d(0.0, 1.0, 0.0), transform.angle * 180 / Math.PI)
+ },
+ PhongMaterial {
+ diffuse: Qt.rgba(Math.abs(Math.cos(transform.angle)), 204 / 255, 75 / 255, 1)
+ specular: "white"
+ shininess: 20.0
+ }
+ ]
+ }
+ }
+}
diff --git a/examples/qt3d/qardboard/qardboard.pro b/examples/qt3d/qardboard/qardboard.pro
new file mode 100644
index 000000000..07db75737
--- /dev/null
+++ b/examples/qt3d/qardboard/qardboard.pro
@@ -0,0 +1,35 @@
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+SOURCE += main.cpp
+
+QT += qml quick 3dcore 3drender 3dinput 3dquick 3dextras 3dquickextras
+
+OTHER_FILES += *.qml
+
+SOURCES += \
+ main.cpp \
+ abstractdeviceorientation.cpp \
+ dummydeviceorientation.cpp
+
+HEADERS += \
+ abstractdeviceorientation.h \
+ dummydeviceorientation.h
+
+RESOURCES += \
+ resources.qrc \
+ ../exampleresources/obj.qrc
+
+ios {
+ QT += sensors sensors-private
+ QMAKE_INFO_PLIST = Info.plist
+
+ OBJECTIVE_SOURCES += \
+ iosdeviceorientation.mm \
+ iosdeviceorientation_p.mm
+
+ HEADERS += \
+ iosdeviceorientation.h \
+ iosdeviceorientation_p.h
+}
diff --git a/examples/qt3d/qardboard/resources.qrc b/examples/qt3d/qardboard/resources.qrc
new file mode 100644
index 000000000..fae6dc122
--- /dev/null
+++ b/examples/qt3d/qardboard/resources.qrc
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>QardboardCamera.qml</file>
+ <file>QardboardFrameGraph.qml</file>
+ <file>QardboardRootEntity.qml</file>
+ <file>QardboardScene3D.qml</file>
+ <file>PlacedEntity.qml</file>
+ </qresource>
+</RCC>