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
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
5#ifndef QSSGPLANE_H
6#define QSSGPLANE_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 <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
20#include <QtGui/QVector3D>
21#include <QtCore/qmath.h>
22
24
30class Q_QUICK3DUTILS_EXPORT QSSGPlane
31{
32public:
33 QSSGPlane() = default;
34
38 Q_ALWAYS_INLINE QSSGPlane(float nx, float ny, float nz, float distance) : n(nx, ny, nz), d(distance) {}
39
43 Q_ALWAYS_INLINE QSSGPlane(const QVector3D &normal, float distance) : n(normal), d(distance) {}
44
48 Q_ALWAYS_INLINE QSSGPlane(const QVector3D &point, const QVector3D &normal)
49 : n(normal), d(-QVector3D::dotProduct(point, n)) // p satisfies normal.dot(p) + d = 0
50 {
51 }
52
57 {
58 n = QVector3D::crossProduct(p1 - p0, p2 - p0).normalized();
60 }
61
62 Q_ALWAYS_INLINE float distance(const QVector3D &p) const { return QVector3D::dotProduct(p, n) + d; }
63
64 Q_ALWAYS_INLINE bool contains(const QVector3D &p) const { return qAbs(distance(p)) < (1.0e-7f); }
65
69 Q_ALWAYS_INLINE QVector3D project(const QVector3D &p) const { return p - n * distance(p); }
70
74 Q_ALWAYS_INLINE QVector3D pointInPlane() const { return -n * d; }
75
80 void normalize();
81
83 float d = 0.0f;
84};
85
87
88#endif // QSSGPLANE_H
Representation of a plane.
Definition qssgplane_p.h:31
Q_ALWAYS_INLINE QVector3D pointInPlane() const
find an arbitrary point in the plane
Definition qssgplane_p.h:74
Q_ALWAYS_INLINE QVector3D project(const QVector3D &p) const
projects p into the plane
Definition qssgplane_p.h:69
Q_ALWAYS_INLINE float distance(const QVector3D &p) const
Definition qssgplane_p.h:62
Q_ALWAYS_INLINE QSSGPlane(const QVector3D &point, const QVector3D &normal)
Constructor from a point on the plane and a normal.
Definition qssgplane_p.h:48
Q_ALWAYS_INLINE QSSGPlane(const QVector3D &p0, const QVector3D &p1, const QVector3D &p2)
Constructor from three points.
Definition qssgplane_p.h:56
QSSGPlane()=default
Q_ALWAYS_INLINE bool contains(const QVector3D &p) const
Definition qssgplane_p.h:64
Q_ALWAYS_INLINE QSSGPlane(const QVector3D &normal, float distance)
Constructor from a normal and a distance.
Definition qssgplane_p.h:43
QVector3D n
The normal to the plane.
Definition qssgplane_p.h:82
Q_ALWAYS_INLINE QSSGPlane(float nx, float ny, float nz, float distance)
Constructor from a normal and a distance.
Definition qssgplane_p.h:38
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
Definition qvectornd.h:770
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.
Definition qvectornd.h:775
QPixmap p2
QPixmap p1
[0]
Combined button and popup list for selecting options.
#define Q_ALWAYS_INLINE
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLsizei GLsizei GLfloat distance
GLfloat n
GLfixed GLfixed nz
GLbyte nx
GLfixed ny
GLfloat GLfloat p
[1]
static void normalize(double &x, double &y)