1// Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
2// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QT3DRENDER_QRAY3D_H
6#define QT3DRENDER_QRAY3D_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 for the convenience
13// of other Qt classes. 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 <Qt3DRender/qt3drender_global.h>
20#include <Qt3DCore/private/matrix4x4_p.h>
21#include <Qt3DCore/private/vector3d_p.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace Qt3DRender {
26namespace RayCasting {
27
28class Q_3DRENDERSHARED_EXPORT QRay3D
29{
30public:
31 QRay3D();
32 explicit QRay3D(const Vector3D &origin, const Vector3D &direction = Vector3D(0.0f, 0.0f, 1.0f), float distance = 1.0f);
33 ~QRay3D();
34
35 Vector3D origin() const;
36 void setOrigin(const Vector3D &value);
37
38 Vector3D direction() const;
39 void setDirection(const Vector3D &value);
40
41 float distance() const;
42 void setDistance(float distance);
43
44 bool contains(const Vector3D &point) const;
45 bool contains(const QRay3D &ray) const;
46
47 Vector3D point(float t) const;
48 float projectedDistance(const Vector3D &point) const;
49
50 Vector3D project(const Vector3D &vector) const;
51
52 float distance(const Vector3D &point) const;
53
54 QRay3D &transform(const Matrix4x4 &matrix);
55 QRay3D transformed(const Matrix4x4 &matrix) const;
56
57 bool operator==(const QRay3D &other) const;
58 bool operator!=(const QRay3D &other) const;
59
60 bool isValid() const { return !m_direction.isNull() && !qFuzzyIsNull(f: m_distance); }
61
62private:
63 Vector3D m_origin;
64 Vector3D m_direction;
65 float m_distance;
66};
67QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QRay3D, Q_RELOCATABLE_TYPE)
68
69
70#ifndef QT_NO_DEBUG_STREAM
71Q_3DRENDERSHARED_EXPORT QDebug operator<<(QDebug dbg, const QRay3D &ray);
72#endif
73
74#ifndef QT_NO_DATASTREAM
75Q_3DRENDERSHARED_EXPORT QDataStream &operator<<(QDataStream &stream, const QRay3D &ray);
76Q_3DRENDERSHARED_EXPORT QDataStream &operator>>(QDataStream &stream, QRay3D &ray);
77#endif
78
79} // namespace RayCasting
80} // namespace Qt3DRender
81QT_END_NAMESPACE
82
83inline bool qFuzzyCompare(const Qt3DRender::RayCasting::QRay3D &ray1, const Qt3DRender::RayCasting::QRay3D &ray2)
84{
85 return qFuzzyCompare(v1: ray1.origin(), v2: ray2.origin()) &&
86 qFuzzyCompare(v1: ray1.direction(), v2: ray2.direction());
87}
88
89Q_DECLARE_METATYPE(Qt3DRender::RayCasting::QRay3D) // LCOV_EXCL_LINE
90
91#endif // QT3DRENDER_QRAY3D_H
92

source code of qt3d/src/render/raycasting/qray3d_p.h