| 1 |
// Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.14 |
| 5 |
import Qt3D.Render 2.14 |
| 6 |
|
| 7 |
Entity { |
| 8 |
id: root |
| 9 |
|
| 10 |
property vector3d position: Qt.vector3d(0.0, 0.0, 10.0) |
| 11 |
property vector3d viewCenter: Qt.vector3d(0.0, 0.0, 0.0) |
| 12 |
property vector3d upVector: Qt.vector3d(0.0, 1.0, 0.0) |
| 13 |
property CameraLens lens: null |
| 14 |
|
| 15 |
components: [lens, transform] |
| 16 |
|
| 17 |
Transform { |
| 18 |
id: transform |
| 19 |
matrix: { |
| 20 |
var m = Qt.matrix4x4(); |
| 21 |
m.translate(root.position) |
| 22 |
var zAxis = root.position.minus(root.viewCenter).normalized() |
| 23 |
var xAxis = root.upVector.crossProduct(zAxis).normalized(); |
| 24 |
var yAxis = zAxis.crossProduct(xAxis); |
| 25 |
var r = Qt.matrix4x4(xAxis.x, yAxis.x, zAxis.x, 0, |
| 26 |
xAxis.y, yAxis.y, zAxis.y, 0, |
| 27 |
xAxis.z, yAxis.z, zAxis.z, 0, |
| 28 |
0, 0, 0, 1) |
| 29 |
return m.times(r); |
| 30 |
} |
| 31 |
} |
| 32 |
} |