1/****************************************************************************
2**
3** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
41#define QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of other Qt classes. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <Qt3DRender/qt3drender_global.h>
55#include <Qt3DCore/qnodeid.h>
56#include <Qt3DCore/private/vector3d_p.h>
57#include <QVector>
58#include <QSharedData>
59
60QT_BEGIN_NAMESPACE
61
62namespace Qt3DRender {
63namespace RayCasting {
64
65typedef int QQueryHandle;
66class QCollisionQueryResultPrivate;
67
68class Q_3DRENDERSHARED_EXPORT QCollisionQueryResult
69{
70public:
71 struct Hit {
72 enum HitType {
73 Entity,
74 Point,
75 Edge,
76 Triangle
77 };
78
79 Hit()
80 : m_type(Entity)
81 , m_distance(-1.f)
82 , m_primitiveIndex(0)
83 {
84 m_vertexIndex[0] = m_vertexIndex[1] = m_vertexIndex[2] = 0;
85 }
86
87 Hit(Qt3DCore::QNodeId entity, const Vector3D &intersection, float distance, const Vector3D &uvw)
88 : m_entityId(entity)
89 , m_type(Entity)
90 , m_intersection(intersection)
91 , m_distance(distance)
92 , m_primitiveIndex(0U)
93 , m_uvw(uvw)
94 {
95 }
96
97 Qt3DCore::QNodeId m_entityId;
98 HitType m_type;
99 Vector3D m_intersection;
100 float m_distance;
101 uint m_primitiveIndex;
102 uint m_vertexIndex[3];
103 Vector3D m_uvw;
104 };
105
106 QCollisionQueryResult();
107 QCollisionQueryResult(const QCollisionQueryResult &);
108 ~QCollisionQueryResult();
109
110 QCollisionQueryResult &operator=(const QCollisionQueryResult &);
111#ifdef Q_COMPILER_RVALUE_REFS
112 QCollisionQueryResult &operator=(QCollisionQueryResult &&other) Q_DECL_NOTHROW
113 {
114 swap(other);
115 return *this;
116 }
117#endif
118
119 void swap(QCollisionQueryResult &other) Q_DECL_NOTHROW
120 {
121 qSwap(value1&: d_ptr, value2&: other.d_ptr);
122 }
123
124 QQueryHandle handle() const;
125 QVector<Hit> hits() const;
126 QVector<Qt3DCore::QNodeId> entitiesHit() const;
127
128private:
129 friend class QAbstractCollisionQueryService;
130
131 explicit QCollisionQueryResult(QCollisionQueryResultPrivate &p);
132
133 QSharedDataPointer<QCollisionQueryResultPrivate> d_ptr;
134 // Q_DECLARE_PRIVATE equivalent for shared data pointers
135 QCollisionQueryResultPrivate *d_func();
136 inline const QCollisionQueryResultPrivate *d_func() const
137 {
138 return d_ptr.constData();
139 }
140};
141QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QCollisionQueryResult::Hit, Q_PRIMITIVE_TYPE)
142QT3D_DECLARE_SHARED_2(Qt3DRender, RayCasting, QCollisionQueryResult)
143
144class QCollisionQueryResultPrivate : public QSharedData
145{
146public:
147 explicit QCollisionQueryResultPrivate();
148 explicit QCollisionQueryResultPrivate(const QCollisionQueryResultPrivate &copy);
149
150 void setHandle(const QQueryHandle &handle);
151 void addEntityHit(Qt3DCore::QNodeId entity, const Vector3D& intersection, float distance,
152 const Vector3D& uvw);
153
154 QQueryHandle m_handle;
155 QVector<QCollisionQueryResult::Hit> m_hits;
156};
157
158inline bool operator==(const QCollisionQueryResult::Hit& left, const QCollisionQueryResult::Hit& right)
159{
160 return left.m_entityId == right.m_entityId;
161}
162
163} // RayCasting
164} // Qt3DRender
165
166QT_END_NAMESPACE
167
168#endif // QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
169

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