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
qssgbounds3_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#ifndef QSSGBOUNDS3_H
6#define QSSGBOUNDS3_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qssgutils_p.h"
20#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
21
22#include <QVector3D>
23#include <QMatrix3x3>
24#include <QMatrix4x4>
25
26#include <limits>
27#include <qnumeric.h>
28
30
31using QSSGBoxPoints = std::array<QVector3D, 8>;
32
40class Q_QUICK3DUTILS_EXPORT QSSGBounds3
41{
42public:
47
52
56 Q_DECL_CONSTEXPR Q_ALWAYS_INLINE QSSGBounds3(const QVector3D &minimum, const QVector3D &maximum);
57
63 static Q_ALWAYS_INLINE QSSGBounds3 boundsOfPoints(const QVector3D &v0, const QVector3D &v1);
64
70 static Q_ALWAYS_INLINE QSSGBounds3 centerExtents(const QVector3D &center, const QVector3D &extent);
71
75 static Q_ALWAYS_INLINE QSSGBounds3 basisExtent(const QVector3D &center, const QMatrix3x3 &basis, const QVector3D &extent);
76
82 static QSSGBounds3 transform(const QMatrix3x3 &matrix, const QSSGBounds3 &bounds);
83
87 Q_ALWAYS_INLINE void setEmpty();
88
92 Q_ALWAYS_INLINE void setInfinite();
93
98 void include(const QVector3D &v);
99
104 void include(const QSSGBounds3 &b);
105
106 Q_ALWAYS_INLINE bool isEmpty() const;
107
112 Q_ALWAYS_INLINE bool intersects(const QSSGBounds3 &b) const;
113
119 Q_ALWAYS_INLINE bool intersects1D(const QSSGBounds3 &a, quint32 axis) const;
120
125 Q_ALWAYS_INLINE bool contains(const QVector3D &v) const;
126
131 Q_ALWAYS_INLINE bool isInside(const QSSGBounds3 &box) const;
132
136 Q_ALWAYS_INLINE QVector3D center() const;
137
141 Q_ALWAYS_INLINE float center(quint32 axis) const;
142
146 Q_ALWAYS_INLINE float extents(quint32 axis) const;
147
151 Q_ALWAYS_INLINE QVector3D dimensions() const;
152
156 Q_ALWAYS_INLINE QVector3D extents() const;
157
162 Q_ALWAYS_INLINE void scale(float scale);
163
167 Q_ALWAYS_INLINE void fatten(double distance);
168
173 bool isFinite() const;
174
178 Q_ALWAYS_INLINE QSSGBoxPoints toQSSGBoxPointsNoEmptyCheck() const;
182 Q_ALWAYS_INLINE QSSGBoxPoints toQSSGBoxPoints() const;
183
184 void transform(const QMatrix4x4 &inMatrix);
185
189 QVector3D getSupport(const QVector3D &direction) const;
190
193};
194
196 : minimum(QVector3D(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max()))
197 , maximum(-std::numeric_limits<float>::max(), -std::numeric_limits<float>::max(), -std::numeric_limits<float>::max())
198{
199}
200
203
205 : minimum(_minimum), maximum(_maximum)
206{
207}
208
210{
211 return QSSGBounds3(center - extent, center + extent);
212}
213
215{
216 constexpr float maxFloat = std::numeric_limits<float>::max();
217 minimum = QVector3D(maxFloat, maxFloat, maxFloat);
218 maximum = QVector3D(-maxFloat, -maxFloat, -maxFloat);
219}
220
222{
223 constexpr float maxFloat = std::numeric_limits<float>::max();
224 minimum = QVector3D(-maxFloat, -maxFloat, -maxFloat);
225 maximum = QVector3D(maxFloat, maxFloat, maxFloat);
226}
227
229{
231 // Consistency condition for (Min, Max) boxes: minimum < maximum
232 return minimum.x() > maximum.x() || minimum.y() > maximum.y() || minimum.z() > maximum.z();
233}
234
236{
237 Q_ASSERT(isFinite() && b.isFinite());
238 return !(b.minimum.x() > maximum.x() || minimum.x() > b.maximum.x() || b.minimum.y() > maximum.y()
239 || minimum.y() > b.maximum.y() || b.minimum.z() > maximum.z() || minimum.z() > b.maximum.z());
240}
241
243{
244 Q_ASSERT(isFinite() && a.isFinite());
245 return maximum[int(axis)] >= a.minimum[axis] && a.maximum[axis] >= minimum[axis];
246}
247
249{
251
252 return !(v.x() < minimum.x() || v.x() > maximum.x() || v.y() < minimum.y() || v.y() > maximum.y()
253 || v.z() < minimum.z() || v.z() > maximum.z());
254}
255
257{
258 Q_ASSERT(isFinite() && box.isFinite());
259 if (box.minimum.x() > minimum.x())
260 return false;
261 if (box.minimum.y() > minimum.y())
262 return false;
263 if (box.minimum.z() > minimum.z())
264 return false;
265 if (box.maximum.x() < maximum.x())
266 return false;
267 if (box.maximum.y() < maximum.y())
268 return false;
269 if (box.maximum.z() < maximum.z())
270 return false;
271 return true;
272}
273
275{
277 return (minimum + maximum) * double(0.5);
278}
279
281{
283 return (minimum[int(axis)] + maximum[int(axis)]) * 0.5f;
284}
285
287{
289 return (maximum[int(axis)] - minimum[int(axis)]) * 0.5f;
290}
291
297
299{
301 return dimensions() * double(0.5);
302}
303
305{
307 *this = centerExtents(center(), extents() * scale);
308}
309
311{
313 minimum -= QVector3D(float(distance), float(distance), float(distance));
314 maximum += QVector3D(float(distance), float(distance), float(distance));
315}
316
318{
319 return { // Min corner of box
320 QVector3D(minimum[0], minimum[1], minimum[2]),
321 QVector3D(maximum[0], minimum[1], minimum[2]),
322 QVector3D(minimum[0], maximum[1], minimum[2]),
323 QVector3D(minimum[0], minimum[1], maximum[2]),
324 // Max corner of box
325 QVector3D(maximum[0], maximum[1], maximum[2]),
326 QVector3D(minimum[0], maximum[1], maximum[2]),
327 QVector3D(maximum[0], minimum[1], maximum[2]),
328 QVector3D(maximum[0], maximum[1], minimum[2])
329 };
330}
331
333{
334 if (isEmpty())
335 return { QVector3D(0, 0, 0), QVector3D(0, 0, 0), QVector3D(0, 0, 0), QVector3D(0, 0, 0),
336 QVector3D(0, 0, 0), QVector3D(0, 0, 0), QVector3D(0, 0, 0), QVector3D(0, 0, 0) };
338}
339
341
342#endif // QSSGBOUNDS3_H
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
Class representing 3D range or axis aligned bounding box.
bool isFinite() const
Q_ALWAYS_INLINE bool contains(const QVector3D &v) const
indicates if these bounds contain v.
Q_ALWAYS_INLINE QVector3D dimensions() const
returns the dimensions (width/height/depth) of this axis aligned box.
Q_ALWAYS_INLINE QSSGBoxPoints toQSSGBoxPoints() const
static Q_ALWAYS_INLINE QSSGBounds3 centerExtents(const QVector3D &center, const QVector3D &extent)
returns the AABB from center and extents vectors.
Q_DECL_CONSTEXPR Q_ALWAYS_INLINE QSSGBounds3()
Default constructor, using empty bounds.
Q_ALWAYS_INLINE QVector3D extents() const
returns the extents, which are half of the width/height/depth.
Q_ALWAYS_INLINE QVector3D center() const
returns the center of this axis aligned box.
Q_ALWAYS_INLINE void setEmpty()
Sets empty to true.
Q_ALWAYS_INLINE QSSGBoxPoints toQSSGBoxPointsNoEmptyCheck() const
Q_ALWAYS_INLINE bool intersects1D(const QSSGBounds3 &a, quint32 axis) const
computes the 1D-intersection between two AABBs, on a given axis.
Q_ALWAYS_INLINE bool intersects(const QSSGBounds3 &b) const
indicates whether the intersection of this and b is empty or not.
Q_ALWAYS_INLINE void fatten(double distance)
QVector3D minimum
Q_ALWAYS_INLINE void setInfinite()
Sets infinite bounds.
Q_ALWAYS_INLINE bool isEmpty() const
QVector3D maximum
Q_ALWAYS_INLINE bool isInside(const QSSGBounds3 &box) const
checks a box is inside another box.
Q_ALWAYS_INLINE void scale(float scale)
scales the AABB.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:671
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:670
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:672
direction
Combined button and popup list for selecting options.
Definition qcompare.h:63
Initialization
#define Q_DECL_CONSTEXPR
#define Q_ALWAYS_INLINE
constexpr int Uninitialized
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLsizei GLsizei GLfloat distance
GLint GLfloat v0
GLint GLfloat GLfloat v1
GLsizei const GLint * box
GLuint GLenum GLenum transform
GLuint GLenum matrix
GLenum GLenum GLenum GLenum GLenum scale
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
std::array< QVector3D, 8 > QSSGBoxPoints
unsigned int quint32
Definition qtypes.h:50