Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dfrustumcamera.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
7
8#include <QtQuick3DRuntimeRender/private/qssgrendercamera_p.h>
9
10#include <QtMath>
11#include <QtQuick3DUtils/private/qssgutils_p.h>
12
14
16
18
19/*!
20 \qmltype FrustumCamera
21 \inherits PerspectiveCamera
22 \inqmlmodule QtQuick3D
23 \brief Defines a PerspectiveCamera with a custom frustum.
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 FrustumCamera type provides a PerspectiveCamera where the frustum bounds can be
36 customized. This can be useful for creating asymmetrical frustums.
37
38 The following example creates a FrustumCamera at [0, 0, 100] in the scene.
39 The \l {PerspectiveCamera::clipNear}{near plane} is placed 100 units in front of the camera at the origin.
40 The intersection of the frustum and the near plane is then given by the rectangle that has a bottom left corner at [-5, -5],
41 and a top right corner at [5, 5], and continues until it intersect the
42 \l {PerspectiveCamera::clipFar}{far plane}, which is located 1000 units from the camera at [0, 0, -900].
43
44 \note The \l{PerspectiveCamera::fieldOfViewOrientation}{vertical field of view} angle is
45 a product of the distance between the camera, the \l {PerspectiveCamera::clipNear}{near plane}
46 and the length between the \c top and \c bottom of the near plane.
47
48 \note If the top and bottom, or left right, values are asymmetric,
49 the apex of the frustum will be shifted, effectively offsetting the camera from its location.
50
51 \code
52 FrustumCamera {
53 position: Qt.vector3d(0, 0, 100)
54 clipNear: 100
55 clipFar: 1000
56 top: 5
57 bottom: -5
58 left: -5
59 right: 5
60 }
61 \endcode
62
63 \sa PerspectiveCamera, OrthographicCamera, CustomCamera
64*/
65
66/*!
67 * \internal
68 */
69QQuick3DFrustumCamera::QQuick3DFrustumCamera(QQuick3DNode *parent)
70 : QQuick3DPerspectiveCamera(*(new QQuick3DNodePrivate(QQuick3DNodePrivate::Type::CustomFrustumCamera)), parent)
71{}
72
73/*!
74 \qmlproperty real FrustumCamera::top
75
76 The \c top value specifies the top of the \l{PerspectiveCamera::clipNear}{near clip plane},
77 relative to the camera's position in local coordinates.
78*/
79float QQuick3DFrustumCamera::top() const
80{
81 return m_top;
82}
83
84/*!
85 \qmlproperty real FrustumCamera::bottom
86
87 The \c bottom value specifies the bottom of the \l{PerspectiveCamera::clipNear}{near clip plane},
88 relative to the camera's position in local coordinates.
89*/
90float QQuick3DFrustumCamera::bottom() const
91{
92 return m_bottom;
93}
94
95/*!
96 \qmlproperty real FrustumCamera::right
97
98 The \c right value specifies the right of the \l{PerspectiveCamera::clipNear}{near clip plane},
99 relative to the camera's position in local coordinates.
100*/
101float QQuick3DFrustumCamera::right() const
102{
103 return m_right;
104}
105
106/*!
107 \qmlproperty real FrustumCamera::left
108
109 The \c left value specifies the left of the \l{PerspectiveCamera::clipNear}{near clip plane},
110 relative to the camera's position in local coordinates.
111*/
112float QQuick3DFrustumCamera::left() const
113{
114 return m_left;
115}
116
117void QQuick3DFrustumCamera::setTop(float top)
118{
119 if (qFuzzyCompare(m_top, top))
120 return;
121
122 m_top = top;
123 emit topChanged();
124 update();
125}
126
127void QQuick3DFrustumCamera::setBottom(float bottom)
128{
129 if (qFuzzyCompare(m_bottom, bottom))
130 return;
131
132 m_bottom = bottom;
133 emit bottomChanged();
134 update();
135}
136
137void QQuick3DFrustumCamera::setRight(float right)
138{
139 if (qFuzzyCompare(m_right, right))
140 return;
141
142 m_right = right;
143 emit rightChanged();
144 update();
145}
146
147void QQuick3DFrustumCamera::setLeft(float left)
148{
149 if (qFuzzyCompare(m_left, left))
150 return;
151
152 m_left = left;
153 emit leftChanged();
154 update();
155}
156
157QSSGRenderGraphObject *QQuick3DFrustumCamera::updateSpatialNode(QSSGRenderGraphObject *node)
158{
159 // NOTE: The frustum camera extends the perspective camera!
160 QSSGRenderCamera *camera = static_cast<QSSGRenderCamera *>(QQuick3DPerspectiveCamera::updateSpatialNode(node));
161 if (camera) {
162 const bool changed = ((int(qUpdateIfNeeded(camera->customFrustum, { m_top, m_bottom, m_left, m_right }))) != 0);
163 if (changed)
164 camera->markDirty(QSSGRenderCamera::DirtyFlag::CameraDirty);
165 }
166
167 return camera;
168}
169
170QT_END_NAMESPACE
Combined button and popup list for selecting options.