1/****************************************************************************
2**
3** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the Qt3D module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QT3DRENDER_QRAY3D_H
42#define QT3DRENDER_QRAY3D_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists for the convenience
49// of other Qt classes. This header file may change from version to
50// version without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <Qt3DRender/qt3drender_global.h>
56#include <Qt3DCore/private/matrix4x4_p.h>
57#include <Qt3DCore/private/vector3d_p.h>
58
59QT_BEGIN_NAMESPACE
60
61namespace Qt3DRender {
62namespace RayCasting {
63
64class Q_3DRENDERSHARED_EXPORT QRay3D
65{
66public:
67 QRay3D();
68 explicit QRay3D(const Vector3D &origin, const Vector3D &direction = Vector3D(0.0f, 0.0f, 1.0f), float distance = 1.0f);
69 ~QRay3D();
70
71 Vector3D origin() const;
72 void setOrigin(const Vector3D &value);
73
74 Vector3D direction() const;
75 void setDirection(const Vector3D &value);
76
77 float distance() const;
78 void setDistance(float distance);
79
80 bool contains(const Vector3D &point) const;
81 bool contains(const QRay3D &ray) const;
82
83 Vector3D point(float t) const;
84 float projectedDistance(const Vector3D &point) const;
85
86 Vector3D project(const Vector3D &vector) const;
87
88 float distance(const Vector3D &point) const;
89
90 QRay3D &transform(const Matrix4x4 &matrix);
91 QRay3D transformed(const Matrix4x4 &matrix) const;
92
93 bool operator==(const QRay3D &other) const;
94 bool operator!=(const QRay3D &other) const;
95
96 bool isValid() const { return !m_direction.isNull() && !qFuzzyIsNull(f: m_distance); }
97
98private:
99 Vector3D m_origin;
100 Vector3D m_direction;
101 float m_distance;
102};
103QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QRay3D, Q_MOVABLE_TYPE)
104
105
106#ifndef QT_NO_DEBUG_STREAM
107Q_3DRENDERSHARED_EXPORT QDebug operator<<(QDebug dbg, const QRay3D &ray);
108#endif
109
110#ifndef QT_NO_DATASTREAM
111Q_3DRENDERSHARED_EXPORT QDataStream &operator<<(QDataStream &stream, const QRay3D &ray);
112Q_3DRENDERSHARED_EXPORT QDataStream &operator>>(QDataStream &stream, QRay3D &ray);
113#endif
114
115} // namespace RayCasting
116} // namespace Qt3DRender
117QT_END_NAMESPACE
118
119inline bool qFuzzyCompare(const Qt3DRender::RayCasting::QRay3D &ray1, const Qt3DRender::RayCasting::QRay3D &ray2)
120{
121 return qFuzzyCompare(v1: ray1.origin(), v2: ray2.origin()) &&
122 qFuzzyCompare(v1: ray1.direction(), v2: ray2.direction());
123}
124
125Q_DECLARE_METATYPE(Qt3DRender::RayCasting::QRay3D) // LCOV_EXCL_LINE
126
127#endif // QT3DRENDER_QRAY3D_H
128

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