Debian Codegraph @

tests/manual/qardboard/main.qml

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