13 std::array<int, 2> { 0, 1 }, std::array<int, 2> { 1, 2 }, std::array<int, 2> { 2, 3 }, std::array<int, 2> { 3, 0 },
14 std::array<int, 2> { 4, 5 }, std::array<int, 2> { 5, 6 }, std::array<int, 2> { 6, 7 }, std::array<int, 2> { 7, 4 },
15 std::array<int, 2> { 0, 4 }, std::array<int, 2> { 1, 5 }, std::array<int, 2> { 2, 6 }, std::array<int, 2> { 3, 7 },
50 float shortestAxisSq = (
box[0] -
box[1]).lengthSquared();
51 shortestAxisSq = std::min(shortestAxisSq, (
box[0] -
box[4]).lengthSquared());
52 shortestAxisSq = std::min(shortestAxisSq, (
box[0] -
box[3]).lengthSquared());
53 const float axisLength =
qSqrt(shortestAxisSq) * 0.5f;
58 debugDrawSystem->
drawLine(from, mid, axisColor);
59 debugDrawSystem->
drawLine(mid, to, colorBox);
88 double a1 =
b.y() -
a.y();
89 double b1 =
a.x() -
b.x();
90 double c1 =
a1 * (
a.x()) + b1 * (
a.y());
93 double a2 =
d.y() -
c.y();
94 double b2 =
c.x() -
d.x();
95 double c2 =
a2 * (
c.x()) + b2 * (
c.y());
97 double determinant =
a1 * b2 -
a2 * b1;
104 double x = (b2 * c1 - b1 *
c2) / determinant;
105 double y = (
a1 *
c2 -
a2 * c1) / determinant;
108 return x > min.x() &&
x < max.
x() &&
y > min.y() &&
y < max.
y();
158 QList<Vertex> vertices;
159 vertices.reserve(castingBox.size());
160 for (
const auto &
p : castingBox) {
163 vertices.push_back(point);
167 vertices[
line[0]].addNeighbor(
line[1]);
168 vertices[
line[1]].addNeighbor(
line[0]);
171 QList<QVector2D> planePoints;
172 QList<QPair<quint8, quint8>> lines;
173 QList<bool> intersecting;
174 QList<quint8> newVertexIndices;
175 QList<Vertex> verticesPrev;
177 for (
const auto &plane : planes) {
180 newVertexIndices.clear();
181 verticesPrev = vertices;
182 for (
int vertIndexI = 0, vertEnd = vertices.length(); vertIndexI < vertEnd; ++vertIndexI) {
183 Vertex vertex = vertices[vertIndexI];
194 vertices[vertIndexI].active =
false;
195 for (
int neighborIndex : vertex.
neighbors) {
196 if (neighborIndex == -1)
198 vertices[neighborIndex].removeNeighbor(vertIndexI);
201 for (
int neighborIndex : vertex.
neighbors) {
202 if (neighborIndex == -1)
205 const quint32 idx0 = vertIndexI;
206 const quint32 idx1 = neighborIndex;
214 QVector3D linePoint = vertices[idx0].position;
215 QVector3D lineDirection = vertices[idx0].position - vertices[idx1].position;
216 QSSGPlane plane(planePoint, planeNormal);
220 int addedIdx = vertices.length();
225 vertices[idx1].addNeighbor(addedIdx);
226 vertices.push_back(
p);
227 newVertexIndices.push_back(addedIdx);
232 if (newVertexIndices.isEmpty())
248 planePoints.reserve(newVertexIndices.length());
249 for (
auto &p0 : newVertexIndices) {
257 lines.reserve((planePoints.length() * planePoints.length()) / 4);
260 lines.push_back({
i,
j });
265 intersecting.clear();
266 intersecting.resize(lines.length(),
false);
268 QPair<quint8, quint8> lineI = lines[
i];
272 QPair<quint8, quint8> lineJ = lines[
j];
275 if (lineJ.first == lineI.first || lineJ.first == lineI.second || lineJ.second == lineI.first
276 || lineJ.second == lineI.second)
282 intersecting[
i] =
true;
283 intersecting[
j] =
true;
289 if (intersecting[
i]) {
293 QPair<quint8, quint8> lineI = lines[
i];
294 int a = newVertexIndices[lineI.first];
295 int b = newVertexIndices[lineI.second];
296 vertices[
a].addNeighbor(
b);
297 vertices[
b].addNeighbor(
a);
301 for (
const Vertex &point : vertices) {
302 if (point.active && (point.borked || !point.allNeighbors())) {
303 vertices = verticesPrev;
310 result.reserve(vertices.length());
311 for (
const Vertex &vertex : vertices) {
313 result.push_back(vertex.position);
316 if (debugDrawSystem) {
318 for (
int i = 0;
i < vertices.length();
i++) {
338 static std::array<std::array<int, 4>, 6> faceIndices = {
339 std::array<int, 4> { 0, 1, 2, 3 }, std::array<int, 4> { 0, 3, 7, 4 }, std::array<int, 4> { 3, 2, 6, 7 },
340 std::array<int, 4> { 7, 6, 5, 4 }, std::array<int, 4> { 4, 5, 1, 0 }, std::array<int, 4> { 2, 1, 5, 6 },
343 QList<std::array<QVector3D, 2>> faces;
344 faces.resize(faceIndices.size());
345 for (
int i = 0;
i < int(faceIndices.size()); ++
i) {
346 std::array<int, 4>
face = faceIndices[
i];
359 const float minX = boxBounds.minimum.x();
360 const float minY = boxBounds.minimum.y();
361 const float minZ = boxBounds.minimum.z();
362 const float maxX = boxBounds.maximum.x();
363 const float maxY = boxBounds.maximum.y();
364 const float maxZ = boxBounds.maximum.z();
378 static constexpr std::array<int, 4> LEFT = { 0, 3, 7, 4 };
379 static constexpr std::array<int, 4> TOP = { 3, 2, 6, 7 };
380 static constexpr std::array<int, 4>
BOTTOM = { 4, 5, 1, 0 };
381 static constexpr std::array<int, 4> RIGHT = { 2, 1, 5, 6 };
382 static constexpr std::array<std::array<int, 4>, 4> faceIndices = { LEFT, TOP,
BOTTOM, RIGHT };
384 QList<std::array<QVector3D, 2>> faces;
385 faces.resize(faceIndices.size());
386 for (
int i = 0;
i < int(faceIndices.size()); ++
i) {
387 std::array<int, 4>
face = faceIndices[
i];
392 faces[
i] = { center,
n };
The QColor class provides colors based on RGB, HSV or CMYK values.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Class representing 3D range or axis aligned bounding box.
void drawLine(const QVector3D &startPoint, const QVector3D &endPoint, const QColor &color, bool isPersistent=false)
Representation of a plane.
The QVector2D class represents a vector or vertex in 2D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
The QVector3D class represents a vector or vertex in 3D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
The QVector4D class represents a vector or vertex in 4D space.
Combined button and popup list for selecting options.
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
void addDebugFrustum(const QSSGBoxPoints &frustumPoints, const QColor &color, QSSGDebugDrawSystem *debugDrawSystem)
QList< QVector3D > intersectBoxByFrustum(const QSSGBoxPoints &frustumPoints, const QSSGBoxPoints &box, QSSGDebugDrawSystem *debugDrawSystem, const QColor &color)
void addDebugBox(const QSSGBoxPoints &boxUnsorted, const QColor &color, QSSGDebugDrawSystem *debugDrawSystem)
QList< QVector3D > intersectBoxByBox(const QSSGBounds3 &boxBounds, const QSSGBoxPoints &box)
void addDirectionalLightDebugBox(const QSSGBoxPoints &box, QSSGDebugDrawSystem *debugDrawSystem)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
qfloat16 qSqrt(qfloat16 f)
QT_BEGIN_NAMESPACE constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
GLsizei const GLint * box
GLfloat GLfloat GLfloat GLfloat maxX
GLuint GLenum GLenum transform
GLfixed GLfixed GLint GLint GLfixed points
GLint GLenum GLboolean normalized
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static bool lineLineIntersection(QVector2D a, QVector2D b, QVector2D c, QVector2D d)
static QList< QVector3D > sliceBoxByPlanes(const QList< std::array< QVector3D, 2 > > &planes, const QSSGBoxPoints &castingBox, QSSGDebugDrawSystem *debugDrawSystem, const QColor &color)
static QT_BEGIN_NAMESPACE constexpr std::array< std::array< int, 2 >, 12 > BOX_LINE_INDICES
std::array< QVector3D, 8 > QSSGBoxPoints
static std::optional< QVector3D > intersect(const QSSGPlane &inPlane, const QSSGRenderRay &ray)
\qmltype MapCircle \instantiates QDeclarativeCircleMapItem \inqmlmodule QtLocation
bool allNeighbors() const
void removeNeighbor(int neighbor)
std::array< int, 3 > neighbors
void addNeighbor(int neighbor)