Debian Codegraph @

tests/manual/anaglyph-rendering/StereoCamera.qml

raw
1 // Copyright (C) 2015 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
7 Entity {
8 id: root
9 property real convergence: 2000.0
10 property real eyeSeparation: 35.0
11 property real aspectRatio: _window.width / _window.height
12 property real fieldOfView: 60.0
13 property real nearPlane: 10.0
14 property real farPlane: 10000.0
15
16 property vector3d viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
17 property vector3d position: Qt.vector3d(0.0, 0.0, 1.0)
18 property vector3d upVector: Qt.vector3d(0.0, 1.0, 0.0)
19
20 readonly property real _fov2: Math.tan(fieldOfView * Math.PI / 180 * 0.5)
21 readonly property real top: nearPlane * _fov2
22 readonly property real a: aspectRatio * _fov2 * convergence
23
24 CameraLens {
25 id: leftEyeLens
26 projectionType: CameraLens.FrustumProjection
27 nearPlane : root.nearPlane
28 farPlane : root.farPlane
29 left: -(a - eyeSeparation * 0.5) * nearPlane / convergence
30 right: (a + eyeSeparation * 0.5) * nearPlane / convergence
31 top: root.top
32 bottom: -root.top
33 }
34
35 CameraLens {
36 id: rightEyeLens
37 projectionType: CameraLens.FrustumProjection
38 nearPlane : root.nearPlane
39 farPlane : root.farPlane
40 left: -(a + eyeSeparation * 0.5) * nearPlane / convergence
41 right: (a - eyeSeparation * 0.5) * nearPlane / convergence
42 top: root.top
43 bottom: -root.top
44 }
45
46 Transform {
47 id: eyeTransform
48
49 matrix: {
50 var m = Qt.matrix4x4();
51 m.translate(root.position)
52 var zAxis = root.position.minus(root.viewCenter).normalized()
53 var xAxis = root.upVector.crossProduct(zAxis).normalized();
54 var yAxis = zAxis.crossProduct(xAxis);
55 var r = Qt.matrix4x4(xAxis.x, yAxis.x, zAxis.x, 0,
56 xAxis.y, yAxis.y, zAxis.y, 0,
57 xAxis.z, yAxis.z, zAxis.z, 0,
58 0, 0, 0, 1)
59 return m.times(r);
60 }
61 }
62
63 components: [ eyeTransform ]
64
65 property Entity leftCamera: Entity {
66 components: [ leftEyeLens ]
67 }
68
69 property Entity rightCamera: Entity {
70 id: rightCameraEntity
71 components: [ rightEyeLens ]
72 }
73 }