| 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 | #include "qssgbounds3_p.h" |
| 6 | #include <private/qssgutils_p.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | void QSSGBounds3::include(const QVector3D &v) |
| 11 | { |
| 12 | minimum = QSSGUtils::vec3::minimum(v1: minimum, v2: v); |
| 13 | maximum = QSSGUtils::vec3::maximum(v1: maximum, v2: v); |
| 14 | } |
| 15 | |
| 16 | void QSSGBounds3::include(const QSSGBounds3 &b) |
| 17 | { |
| 18 | minimum = QSSGUtils::vec3::minimum(v1: minimum, v2: b.minimum); |
| 19 | maximum = QSSGUtils::vec3::maximum(v1: maximum, v2: b.maximum); |
| 20 | } |
| 21 | |
| 22 | bool QSSGBounds3::isFinite() const |
| 23 | { |
| 24 | return QSSGUtils::vec3::isFinite(v: minimum) && QSSGUtils::vec3::isFinite(v: maximum); |
| 25 | } |
| 26 | |
| 27 | QSSGBounds3 QSSGBounds3::boundsOfPoints(const QVector3D &v0, const QVector3D &v1) |
| 28 | { |
| 29 | return QSSGBounds3(QSSGUtils::vec3::minimum(v1: v0, v2: v1), QSSGUtils::vec3::maximum(v1: v0, v2: v1)); |
| 30 | } |
| 31 | |
| 32 | QSSGBounds3 QSSGBounds3::basisExtent(const QVector3D ¢er, const QMatrix3x3 &basis, const QVector3D &extent) |
| 33 | { |
| 34 | // extended basis vectors |
| 35 | QVector3D c0 = QVector3D(basis(0, 0), basis(1, 0), basis(2, 0)) * extent.x(); |
| 36 | QVector3D c1 = QVector3D(basis(0, 1), basis(1, 1), basis(2, 1)) * extent.y(); |
| 37 | QVector3D c2 = QVector3D(basis(0, 2), basis(1, 2), basis(2, 2)) * extent.z(); |
| 38 | |
| 39 | QVector3D w; |
| 40 | // find combination of base vectors that produces max. distance for each component = sum of |
| 41 | // abs() |
| 42 | w.setX(qAbs(t: c0.x()) + qAbs(t: c1.x()) + qAbs(t: c2.x())); |
| 43 | w.setY(qAbs(t: c0.y()) + qAbs(t: c1.y()) + qAbs(t: c2.y())); |
| 44 | w.setZ(qAbs(t: c0.z()) + qAbs(t: c1.z()) + qAbs(t: c2.z())); |
| 45 | |
| 46 | return QSSGBounds3(center - w, center + w); |
| 47 | } |
| 48 | |
| 49 | QSSGBounds3 QSSGBounds3::transform(const QMatrix3x3 &matrix, const QSSGBounds3 &bounds) |
| 50 | { |
| 51 | return bounds.isEmpty() |
| 52 | ? bounds |
| 53 | : QSSGBounds3::basisExtent(center: QSSGUtils::mat33::transform(m: matrix, v: bounds.center()), basis: matrix, extent: bounds.extents()); |
| 54 | } |
| 55 | |
| 56 | void QSSGBounds3::transform(const QMatrix4x4 &inMatrix) |
| 57 | { |
| 58 | if (!isEmpty()) { |
| 59 | const auto pointsPrevious = toQSSGBoxPointsNoEmptyCheck(); |
| 60 | setEmpty(); |
| 61 | for (const QVector3D& point : pointsPrevious) |
| 62 | include(v: inMatrix.map(point)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | QVector3D QSSGBounds3::getSupport(const QVector3D &direction) const |
| 67 | { |
| 68 | const QVector3D halfExtents = extents(); |
| 69 | return QVector3D(direction.x() > 0 ? halfExtents.x() : -halfExtents.x(), |
| 70 | direction.y() > 0 ? halfExtents.y() : -halfExtents.y(), |
| 71 | direction.z() > 0 ? halfExtents.z() : -halfExtents.z()) + center(); |
| 72 | } |
| 73 | |
| 74 | QT_END_NAMESPACE |
| 75 | |