Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dxrcamera.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
6#include <QtQuick3DRuntimeRender/private/qssgrendercamera_p.h>
7#include <QtQuick3D/private/qquick3dutils_p.h>
8#include <QtQuick3D/private/qquick3dnode_p_p.h>
9
10#include <cmath>
11
25
27{
28 return m_leftTangent;
29}
30
32{
33 return m_rightTangent;
34}
35
37{
38 return m_upTangent;
39}
40
42{
43 return m_downTangent;
44}
45
47{
48 return m_clipNear;
49}
50
52{
53 return m_clipFar;
54}
55
57{
58 if (qFuzzyCompare(m_leftTangent, leftTangent))
59 return;
60
61 m_leftTangent = leftTangent;
62 emit leftTangentChanged(m_leftTangent);
63 markProjectionDirty();
64}
65
67{
68 if (qFuzzyCompare(m_rightTangent, rightTangent))
69 return;
70
71 m_rightTangent = rightTangent;
72 emit rightTangentChanged(m_rightTangent);
73 markProjectionDirty();
74}
75
77{
78 if (qFuzzyCompare(m_upTangent, upTangent))
79 return;
80
81 m_upTangent = upTangent;
82 emit upTangentChanged(m_upTangent);
83 markProjectionDirty();
84}
85
87{
88 if (qFuzzyCompare(m_downTangent, downTangent))
89 return;
90
91 m_downTangent = downTangent;
92 emit downTangentChanged(m_downTangent);
93 markProjectionDirty();
94}
95
97{
98 if (qFuzzyCompare(m_clipNear, clipNear))
99 return;
100
101 m_clipNear = clipNear;
102 emit clipNearChanged(m_clipNear);
103 markProjectionDirty();
104}
105
107{
108 if (qFuzzyCompare(m_clipFar, clipFar))
109 return;
110
111 m_clipFar = clipFar;
112 emit clipFarChanged(m_clipFar);
113 markProjectionDirty();
114}
115
117{
119 if (camera) {
120 maybeUpdateProjection();
121 bool changed = false;
122 changed |= qUpdateIfNeeded(camera->projection, m_projection);
123 // Still need to report near and far (used for shadows)
124 changed |= qUpdateIfNeeded(camera->clipNear, m_clipNear);
125 changed |= qUpdateIfNeeded(camera->clipFar, m_clipFar);
126 if (changed)
128 }
129 return camera;
130}
131
132void QQuick3DXrEyeCamera::markProjectionDirty()
133{
134 if (!m_projectionDirty) {
135 m_projectionDirty = true;
136 update();
137 }
138}
139
140void QQuick3DXrEyeCamera::maybeUpdateProjection()
141{
142 if (!m_projectionDirty)
143 return;
144
145 const float right = m_rightTangent * m_clipNear;
146 const float top = m_upTangent * m_clipNear;
147#if defined(Q_OS_VISIONOS)
148 // cp_view_get_tangents always returns positive values
149 // so we need to negate the left and down tangents
150 const float left = -m_leftTangent * m_clipNear;
151 const float bottom = -m_downTangent * m_clipNear;
152#else
153 const float left = m_leftTangent * m_clipNear;
154 const float bottom = m_downTangent * m_clipNear;
155#endif
156
157 float *m = m_projection.data();
158
159 m[0] = 2 * m_clipNear / (right - left);
160 m[4] = 0;
161 m[8] = (right + left) / (right - left);
162 m[12] = 0;
163
164 m[1] = 0;
165 m[5] = 2 * m_clipNear / (top - bottom);
166 m[9] = (top + bottom) / (top - bottom);
167 m[13] = 0;
168
169 m[2] = 0;
170 m[6] = 0;
171 m[10] = m_clipFar / (m_clipNear - m_clipFar);
172 m[14] = m_clipFar * m_clipNear / (m_clipNear - m_clipFar);
173
174
175 m[3] = 0;
176 m[7] = 0;
177 m[11] = -1;
178 m[15] = 0;
179
180 const bool isReverseZ = false; // placeholder
181 if (isReverseZ) {
182 if (std::isinf(m_clipFar)) {
183 m[10] = 0;
184 m[14] = m_clipNear;
185 } else {
186 m[10] = -m[10] - 1;
187 m[14] = -m[14];
188 }
189 } else if (std::isinf(m_clipFar)) {
190 m[10] = -1;
191 m[14] = -m_clipNear;
192 }
193}
194
199
204
211{
212 return m_clipNear;
213}
214
221{
222 return m_clipFar;
223}
224
225
227{
228 if (qFuzzyCompare(m_clipNear, clipNear))
229 return;
230 m_clipNear = clipNear;
231 emit clipNearChanged(m_clipNear);
232}
233
235{
236 if (qFuzzyCompare(m_clipFar, clipFar))
237 return;
238 m_clipFar = clipFar;
239 emit clipFarChanged(m_clipFar);
240}
241
float * data()
Returns a pointer to the raw data of this matrix.
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *node) override
void setClipNear(float clipNear)
void clipFarChanged(float clipFar)
void setClipFar(float clipFar)
QQuick3DXrCamera(QQuick3DNode *parent=nullptr)
void clipNearChanged(float clipNear)
void leftTangentChanged(float leftTangent)
void clipFarChanged(float clipFar)
void clipNearChanged(float clipNear)
void downTangentChanged(float downTangent)
void setDownTangent(float downTangent)
void setUpTangent(float upTangent)
void setClipNear(float clipNear)
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *node) override
void setRightTangent(float rightTangent)
void setClipFar(float clipFar)
void upTangentChanged(float upTangent)
void rightTangentChanged(float rightTangent)
void setLeftTangent(float leftTangent)
QQuick3DXrEyeCamera(QQuick3DNode *parent=nullptr)
\qmltype XrCamera \inherits Node \inqmlmodule QtQuick3D.Xr
QCamera * camera
Definition camera.cpp:19
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
const GLfloat * m
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint left
GLint GLint bottom
QT_BEGIN_NAMESPACE bool qUpdateIfNeeded(T &orig, T updated)
#define emit
Definition moc.h:23