Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dcustomcamera.cpp
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"qquick3dcustomcamera_p.h"
7
8
#
include
<
QtQuick3DRuntimeRender
/
private
/
qssgrendercamera_p
.
h
>
9
10
#
include
<
QtMath
>
11
#
include
<
QtQuick3DUtils
/
private
/
qssgutils_p
.
h
>
12
13
#
include
"qquick3dnode_p_p.h"
14
15
#
include
"qquick3dutils_p.h"
16
17
QT_BEGIN_NAMESPACE
18
19
/*!
20
\qmltype CustomCamera
21
\inherits Camera
22
\inqmlmodule QtQuick3D
23
\brief Defines a Camera with a custom projection matrix.
24
25
A \l Camera defines how the content of the 3D scene is projected onto a 2D surface,
26
such as a View3D. A scene needs at least one \l Camera in order to visualize its
27
contents.
28
29
It is possible to position and rotate the \l Camera like any other spatial \l{QtQuick3D::Node}{Node} in
30
the scene. The \l{QtQuick3D::Node}{Node}'s location and orientation determines where the \l Camera is in
31
the scene, and what direction it is facing. The default orientation of the \l Camera
32
has its forward vector pointing along the negative Z axis and its up vector along
33
the positive Y axis.
34
35
The CustomCamera type provides a \l Camera where the projection matrix can be customized
36
freely.
37
38
The following example creates a CustomCamera at position [0, 200, 300] in the scene, with
39
a 30 degree downward pitch, and a custom projection matrix based on custom near and far plane
40
distances, and a custom field of view.
41
\code
42
CustomCamera {
43
position: Qt.vector3d(0, 200, 300)
44
eulerRotation.x: -30
45
46
property real near: 10.0
47
property real far: 10000.0
48
property real fov: 60.0 * Math.PI / 180.0
49
projection: Qt.matrix4x4(Math.cos(fov / 2) / Math.sin(fov / 2) * (window.height / window.width), 0, 0, 0,
50
0, Math.cos(fov / 2) / Math.sin(fov / 2), 0, 0,
51
0, 0, -(near + far) / (far - near), -(2.0 * near * far) / (far - near),
52
0, 0, -1, 0);
53
}
54
\endcode
55
56
\note When using CustomCamera, some anti-aliasing modes(Temporal AA and Progressive AA) cannot be applied correctly.
57
58
\sa PerspectiveCamera, OrthographicCamera, FrustumCamera
59
*/
60
61
/*!
62
* \internal
63
*/
64
QQuick3DCustomCamera::QQuick3DCustomCamera(QQuick3DNode *parent)
65
: QQuick3DCamera(*(
new
QQuick3DNodePrivate(QQuick3DNodePrivate::Type::CustomCamera, QQuick3DContentLayer::LayerAll)), parent){}
66
67
/*!
68
\qmlproperty matrix4x4 CustomCamera::projection
69
70
This property defines the CustomCamera's projection matrix.
71
*/
72
QMatrix4x4 QQuick3DCustomCamera::projection()
const
73
{
74
return
m_projection;
75
}
76
77
void
QQuick3DCustomCamera::setProjection(
const
QMatrix4x4 &projection)
78
{
79
if
(m_projection == projection)
80
return
;
81
82
m_projection = projection;
83
emit projectionChanged();
84
update();
85
}
86
87
/*!
88
* \internal
89
*/
90
QSSGRenderGraphObject *QQuick3DCustomCamera::updateSpatialNode(QSSGRenderGraphObject *node)
91
{
92
QSSGRenderCamera *camera =
static_cast
<QSSGRenderCamera *>(QQuick3DCamera::updateSpatialNode(node));
93
if
(camera) {
94
if
(qUpdateIfNeeded(camera->projection, m_projection))
95
camera->markDirty(QSSGRenderCamera::DirtyFlag::CameraDirty);
96
}
97
98
return
camera;
99
}
100
101
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
quick3d
qquick3dcustomcamera.cpp
Generated on
for Qt by
1.18.0