Debian Codegraph @

tests/manual/dragging/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.Input 2.0
7 import Qt3D.Extras 2.0
8
9 Entity {
10 id: sceneRoot
11
12 Camera {
13 id: camera
14 projectionType: CameraLens.PerspectiveProjection
15 fieldOfView: 45
16 aspectRatio: 16/9
17 nearPlane : 0.1
18 farPlane : 1000.0
19 position: Qt.vector3d( 0.0, 0.0, 20.0 )
20 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
21 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
22 }
23
24 RenderSettings {
25 id : external_forward_renderer
26 activeFrameGraph : ForwardRenderer {
27 camera: camera
28 clearColor: "white"
29 }
30 }
31
32 // Event Source will be set by the Qt3DQuickWindow
33 InputSettings { id: inputSettings }
34
35 components: [external_forward_renderer, inputSettings]
36
37 Entity {
38 components: [
39 DirectionalLight {
40 worldDirection: Qt.vector3d(0., 0., -1.0).normalized();
41 color: "white"
42 intensity: 1.
43 }
44 ]
45 }
46
47
48 Entity {
49 id: mainEntity
50 objectName: "mainEntity"
51
52 ConeMesh {
53 id: coneMesh
54 length: 4
55 }
56
57 PhongMaterial {
58 id: coneMaterial
59 diffuse: "yellow"
60 }
61
62 Transform {
63 id: coneTransform
64 scale: 1.5
65 translation: Qt.vector3d(0, 2, 0)
66 }
67
68 components: [ coneMesh, coneMaterial, coneTransform ]
69 }
70
71
72
73 Entity {
74 id: draggerEntity
75 objectName: "draggerEntity"
76 property vector3d position: Qt.vector3d(0, 0, 0)
77
78 CylinderMesh {
79 id: mesh
80 radius: .5
81 length: 3
82 rings: 2
83 slices: 20
84 }
85
86 Transform {
87 id: transform
88 rotationZ: 90
89 translation: draggerEntity.position.plus(Qt.vector3d(0, -5, 0))
90 }
91
92 PhongMaterial {
93 id: material
94 diffuse: picker.pressed ? "lightgreen" : "green"
95 }
96
97 ObjectPicker {
98 id: picker
99 property double lastPos: 0
100 dragEnabled: true
101 onPressed: {
102 lastPos = pick.worldIntersection.x
103 }
104 onMoved: {
105 var x = draggerEntity.position.x + (pick.worldIntersection.x - lastPos)
106 if (x > 5) x = 5
107 if (x < -5) x = -5
108 draggerEntity.position.x = x
109 lastPos = pick.worldIntersection.x
110 coneMesh.bottomRadius = 1. + (x / 7.)
111 }
112 }
113
114 components: [ mesh, material, transform, picker ]
115 }
116
117
118 Entity {
119 id: obstructionEntity
120
121 components: [
122 CuboidMesh { },
123 PhongMaterial { diffuse: "blue" },
124 Transform {
125 scale: 2
126 translation: Qt.vector3d(4, -5, 0)
127 },
128 ObjectPicker { }
129 ]
130 }
131 }