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
qssgplane_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// Qt-Security score:significant reason:default
5
6
7#ifndef QSSGPLANE_H
8#define QSSGPLANE_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
22#include <QtGui/QVector3D>
23#include <QtCore/qmath.h>
24
26
27/**
28\brief Representation of a plane.
29
30 Plane equation used: n.dot(v) + d = 0
31*/
33{
34public:
35 QSSGPlane() = default;
36
37 /**
38 \brief Constructor from a normal and a distance
39 */
40 Q_ALWAYS_INLINE QSSGPlane(float nx, float ny, float nz, float distance) : n(nx, ny, nz), d(distance) {}
41
42 /**
43 \brief Constructor from a normal and a distance
44 */
45 Q_ALWAYS_INLINE QSSGPlane(const QVector3D &normal, float distance) : n(normal), d(distance) {}
46
47 /**
48 \brief Constructor from a point on the plane and a normal
49 */
50 Q_ALWAYS_INLINE QSSGPlane(const QVector3D &point, const QVector3D &normal)
51 : n(normal), d(-QVector3D::dotProduct(point, n)) // p satisfies normal.dot(p) + d = 0
52 {
53 }
54
55 /**
56 \brief Constructor from three points
57 */
58 Q_ALWAYS_INLINE QSSGPlane(const QVector3D &p0, const QVector3D &p1, const QVector3D &p2)
59 {
60 n = QVector3D::crossProduct(p1 - p0, p2 - p0).normalized();
61 d = QVector3D::dotProduct(-p0, n);
62 }
63
64 Q_ALWAYS_INLINE float distance(const QVector3D &p) const { return QVector3D::dotProduct(p, n) + d; }
65
66 Q_ALWAYS_INLINE bool contains(const QVector3D &p) const { return qAbs(distance(p)) < (1.0e-7f); }
67
68 /**
69 \brief projects p into the plane
70 */
71 Q_ALWAYS_INLINE QVector3D project(const QVector3D &p) const { return p - n * distance(p); }
72
73 /**
74 \brief find an arbitrary point in the plane
75 */
76 Q_ALWAYS_INLINE QVector3D pointInPlane() const { return -n * d; }
77
78 /**
79 \brief equivalent plane with unit normal
80 */
81
82 void normalize();
83
84 QVector3D n; //!< The normal to the plane
85 float d = 0.0f; //!< The distance from the origin
86};
87
88QT_END_NAMESPACE
89
90#endif // QSSGPLANE_H
Representation of a plane.
Definition qssgplane_p.h:33
Combined button and popup list for selecting options.
float magnitude(const QVector3D &vector)
Definition qssgplane.cpp:12