Debian Codegraph @

tests/manual/scene3d-in-sync/main.qml

raw
1 // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.0
5 import Qt3D.Core 2.9
6 import Qt3D.Render 2.9
7 import Qt3D.Input 2.0
8 import Qt3D.Extras 2.9
9 import QtQuick.Scene3D 2.0
10
11 Item {
12 id: root
13 property int _trackingPosition : 0
14 readonly property int squareSize: 100
15
16 Timer {
17 running: true
18 interval: 16
19 repeat: true
20 onTriggered: {
21 _trackingPosition += 1
22 if ((_trackingPosition + squareSize) >= root.width)
23 _trackingPosition = 0
24 }
25 }
26
27 // Scene3D + Qt3D content
28 Scene3D {
29 id: sceneThreeD
30 readonly property double halfWidth: width * 0.5
31
32 focus: true
33 anchors.fill: parent
34 // anchors.margins: -15
35 // Make sure to define the input aspect if we want to handle inputs
36 aspects: ["render", "input"]
37 multisample: false
38
39 Entity { // Root
40 id: sceneRoot
41 components: [
42 RenderSettings {
43 activeFrameGraph: ForwardRenderer {
44 id: forwardRenderer
45 camera: planeCamera
46 clearColor: "yellow"
47 }
48 },
49 // Event Source is the Scene3D in that case
50 InputSettings { }
51 ]
52
53 Camera {
54 id: planeCamera
55 left: -sceneThreeD.halfWidth
56 right: sceneThreeD.halfWidth
57 bottom: -(sceneThreeD.height * 0.5)
58 top: (sceneThreeD.height * 0.5)
59 nearPlane: -100
60 farPlane: 100
61 projectionType: CameraLens.OrthographicProjection
62 position: Qt.vector3d(0, 0, 10)
63 viewCenter: Qt.vector3d(0, 0, 0)
64 }
65
66 Entity {
67 id: trackingCube
68 components: [
69 CuboidMesh {
70 xExtent: 100
71 yExtent: 100
72 zExtent: 2
73 },
74
75 PhongMaterial {
76 diffuse: "orange"
77 ambient: "orange"
78 },
79
80 Transform {
81 translation: Qt.vector3d(-sceneThreeD.halfWidth + squareSize * 0.5 + _trackingPosition, -50, 0)
82 }
83 ]
84 }
85 }
86 }
87
88 // QtQuick Content
89 Rectangle {
90 id: qtQuickTracer
91 x: _trackingPosition
92 onXChanged: {
93 console.info("Tracking position is now:" + _trackingPosition);
94 }
95
96 y: root.height * 0.5 - height
97 width: squareSize; height: squareSize
98 color: "red"
99 //transformOrigin: Item.Center
100 Text {
101 color: "white"
102 text: "Rendered with QtQuick"
103 anchors.fill: parent
104 horizontalAlignment: Text.AlignHCenter
105 verticalAlignment: Text.AlignVCenter
106 wrapMode: Text.WrapAnywhere
107 }
108
109 Text {
110 color: "white"
111 text: "Rendered with Qt3D"
112 width: parent.width
113 height: parent.height
114 anchors.top: parent.bottom
115 horizontalAlignment: Text.AlignHCenter
116 verticalAlignment: Text.AlignVCenter
117 wrapMode: Text.WrapAnywhere
118 }
119
120 Rectangle {
121 width: 1
122 height: 200
123 x: 100
124 color: "black"
125 }
126 }
127 }