| 1 |
// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import QtQuick 2.4 as QQ2 |
| 5 |
import Qt3D.Core 2.0 |
| 6 |
import Qt3D.Render 2.0 |
| 7 |
import Qt3D.Extras 2.0 |
| 8 |
|
| 9 |
Entity { |
| 10 |
id: root |
| 11 |
|
| 12 |
components: RenderSettings { |
| 13 |
StereoFrameGraph { |
| 14 |
id: stereoFrameGraph |
| 15 |
leftCamera: stereoCamera.leftCamera |
| 16 |
rightCamera: stereoCamera.rightCamera |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
// Camera |
| 21 |
StereoCamera { |
| 22 |
id: stereoCamera |
| 23 |
property real circleRotation: 0 |
| 24 |
readonly property real cameraRadius: obstaclesRepeater.radius - 50 |
| 25 |
readonly property vector3d circlePosition: Qt.vector3d(cameraRadius * Math.cos(circleRotation), 0.0, cameraRadius * Math.sin(circleRotation)) |
| 26 |
readonly property vector3d tan: circlePosition.crossProduct(Qt.vector3d(0, 1, 0).normalized()) |
| 27 |
viewCenter: planeTransform.translation |
| 28 |
position: circlePosition.plus(Qt.vector3d(0, 45 * Math.sin(circleRotation * 2), 0)).plus(tan.times(-2)) |
| 29 |
|
| 30 |
QQ2.NumberAnimation { |
| 31 |
target: stereoCamera |
| 32 |
property: "circleRotation" |
| 33 |
from: 0; to: Math.PI * 2 |
| 34 |
duration: 10000 |
| 35 |
loops: QQ2.Animation.Infinite |
| 36 |
running: true |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
// Skybox |
| 41 |
SkyboxEntity { |
| 42 |
baseName: "qrc:/assets/cubemaps/miramar/miramar" |
| 43 |
extension: ".webp" |
| 44 |
} |
| 45 |
|
| 46 |
// Cylinder |
| 47 |
Entity { |
| 48 |
property CylinderMesh cylinder: CylinderMesh { |
| 49 |
radius: 1 |
| 50 |
length: 3 |
| 51 |
rings: 100 |
| 52 |
slices: 20 |
| 53 |
} |
| 54 |
property Transform transform: Transform { |
| 55 |
id: cylinderTransform |
| 56 |
property real theta: 0.0 |
| 57 |
property real phi: 0.0 |
| 58 |
rotation: fromEulerAngles(theta, phi, 0) |
| 59 |
} |
| 60 |
property Material phong: PhongMaterial {} |
| 61 |
|
| 62 |
QQ2.ParallelAnimation { |
| 63 |
loops: QQ2.Animation.Infinite |
| 64 |
running: true |
| 65 |
QQ2.SequentialAnimation { |
| 66 |
QQ2.NumberAnimation { |
| 67 |
target: cylinderTransform |
| 68 |
property: "scale" |
| 69 |
from: 5; to: 45 |
| 70 |
duration: 2000 |
| 71 |
easing.type: QQ2.Easing.OutInQuad |
| 72 |
} |
| 73 |
QQ2.NumberAnimation { |
| 74 |
target: cylinderTransform |
| 75 |
property: "scale" |
| 76 |
from: 45; to: 5 |
| 77 |
duration: 2000 |
| 78 |
easing.type: QQ2.Easing.InOutQuart |
| 79 |
} |
| 80 |
} |
| 81 |
QQ2.NumberAnimation { |
| 82 |
target: cylinderTransform |
| 83 |
property: "phi" |
| 84 |
from: 0; to: 360 |
| 85 |
duration: 4000 |
| 86 |
} |
| 87 |
QQ2.NumberAnimation { |
| 88 |
target: cylinderTransform |
| 89 |
property: "theta" |
| 90 |
from: 0; to: 720 |
| 91 |
duration: 4000 |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
components: [cylinder, transform, phong] |
| 96 |
} |
| 97 |
|
| 98 |
// AirPlane |
| 99 |
Entity { |
| 100 |
components: [ |
| 101 |
Mesh { |
| 102 |
source: "assets/obj/toyplane.obj" |
| 103 |
}, |
| 104 |
Transform { |
| 105 |
id: planeTransform |
| 106 |
property real rollAngle: 0.0 |
| 107 |
translation: Qt.vector3d(Math.sin(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius, |
| 108 |
0.0, |
| 109 |
Math.cos(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius) |
| 110 |
rotation: fromAxesAndAngles(Qt.vector3d(1.0, 0.0, 0.0), planeTransform.rollAngle, |
| 111 |
Qt.vector3d(0.0, 1.0, 0.0), stereoCamera.circleRotation * -2 * 180 / Math.PI + 180) |
| 112 |
}, |
| 113 |
PhongMaterial { |
| 114 |
shininess: 20.0 |
| 115 |
diffuse: "#ba1a02" // Inferno Orange |
| 116 |
} |
| 117 |
] |
| 118 |
|
| 119 |
QQ2.SequentialAnimation { |
| 120 |
running: true |
| 121 |
loops: QQ2.Animation.Infinite |
| 122 |
|
| 123 |
QQ2.NumberAnimation { |
| 124 |
target: planeTransform |
| 125 |
property: "rollAngle" |
| 126 |
from: 30; to: 45 |
| 127 |
duration: 750 |
| 128 |
} |
| 129 |
QQ2.NumberAnimation { |
| 130 |
target: planeTransform |
| 131 |
property: "rollAngle" |
| 132 |
from: 45; to: 25 |
| 133 |
duration: 500 |
| 134 |
} |
| 135 |
QQ2.NumberAnimation { |
| 136 |
target: planeTransform |
| 137 |
property: "rollAngle" |
| 138 |
from: 25; to: 390 |
| 139 |
duration: 800 |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
// Torus obsctacles |
| 145 |
NodeInstantiator { |
| 146 |
id: obstaclesRepeater |
| 147 |
model: 4 |
| 148 |
readonly property real radius: 130.0; |
| 149 |
readonly property real det: 1.0 / model |
| 150 |
delegate: Entity { |
| 151 |
components: [ |
| 152 |
TorusMesh { |
| 153 |
radius: 35 |
| 154 |
minorRadius: 5 |
| 155 |
rings: 100 |
| 156 |
slices: 20 |
| 157 |
}, |
| 158 |
Transform { |
| 159 |
id: transform |
| 160 |
readonly property real angle: Math.PI * 2.0 * index * obstaclesRepeater.det |
| 161 |
translation: Qt.vector3d(obstaclesRepeater.radius * Math.cos(transform.angle), |
| 162 |
0.0, |
| 163 |
obstaclesRepeater.radius * Math.sin(transform.angle)) |
| 164 |
rotation: fromAxisAndAngle(Qt.vector3d(0.0, 1.0, 0.0), transform.angle * 180 / Math.PI) |
| 165 |
}, |
| 166 |
PhongMaterial { |
| 167 |
diffuse: Qt.rgba(Math.abs(Math.cos(transform.angle)), 204 / 255, 75 / 255, 1) |
| 168 |
specular: "white" |
| 169 |
shininess: 20.0 |
| 170 |
} |
| 171 |
] |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|