1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
5#define QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DRender/qt3drender_global.h>
19#include <Qt3DCore/qnodeid.h>
20#include <Qt3DCore/private/vector3d_p.h>
21#include <QSharedData>
22
23QT_BEGIN_NAMESPACE
24
25namespace Qt3DRender {
26namespace RayCasting {
27
28typedef int QQueryHandle;
29class QCollisionQueryResultPrivate;
30
31class Q_3DRENDERSHARED_EXPORT QCollisionQueryResult
32{
33public:
34 struct Hit {
35 enum HitType {
36 Entity,
37 Point,
38 Edge,
39 Triangle
40 };
41
42 Hit()
43 : m_type(Entity)
44 , m_distance(-1.f)
45 , m_primitiveIndex(0)
46 {
47 m_vertexIndex[0] = m_vertexIndex[1] = m_vertexIndex[2] = 0;
48 }
49
50 Hit(Qt3DCore::QNodeId entity, const Vector3D &intersection, float distance, const Vector3D &uvw)
51 : m_entityId(entity)
52 , m_type(Entity)
53 , m_intersection(intersection)
54 , m_distance(distance)
55 , m_primitiveIndex(0U)
56 , m_uvw(uvw)
57 {
58 }
59
60 Qt3DCore::QNodeId m_entityId;
61 HitType m_type;
62 Vector3D m_intersection;
63 float m_distance;
64 uint m_primitiveIndex;
65 uint m_vertexIndex[3];
66 Vector3D m_uvw;
67 };
68
69 QCollisionQueryResult();
70 QCollisionQueryResult(const QCollisionQueryResult &);
71 ~QCollisionQueryResult();
72
73 QCollisionQueryResult &operator=(const QCollisionQueryResult &);
74#ifdef Q_COMPILER_RVALUE_REFS
75 QCollisionQueryResult &operator=(QCollisionQueryResult &&other) noexcept
76 {
77 swap(other);
78 return *this;
79 }
80#endif
81
82 void swap(QCollisionQueryResult &other) noexcept
83 {
84 qSwap(value1&: d_ptr, value2&: other.d_ptr);
85 }
86
87 QQueryHandle handle() const;
88 const std::vector<Hit> &hits() const;
89 std::vector<Qt3DCore::QNodeId> entitiesHit() const;
90
91private:
92 friend class QAbstractCollisionQueryService;
93
94 explicit QCollisionQueryResult(QCollisionQueryResultPrivate &p);
95
96 QSharedDataPointer<QCollisionQueryResultPrivate> d_ptr;
97 // Q_DECLARE_PRIVATE equivalent for shared data pointers
98 QCollisionQueryResultPrivate *d_func();
99 inline const QCollisionQueryResultPrivate *d_func() const
100 {
101 return d_ptr.constData();
102 }
103};
104QT3D_DECLARE_TYPEINFO_2(Qt3DRender, RayCasting, QCollisionQueryResult::Hit, Q_PRIMITIVE_TYPE)
105QT3D_DECLARE_SHARED_2(Qt3DRender, RayCasting, QCollisionQueryResult)
106
107class QCollisionQueryResultPrivate : public QSharedData
108{
109public:
110 explicit QCollisionQueryResultPrivate();
111 explicit QCollisionQueryResultPrivate(const QCollisionQueryResultPrivate &copy);
112
113 void setHandle(const QQueryHandle &handle);
114 void addEntityHit(Qt3DCore::QNodeId entity, const Vector3D& intersection, float distance,
115 const Vector3D& uvw);
116
117 QQueryHandle m_handle;
118 std::vector<QCollisionQueryResult::Hit> m_hits;
119};
120
121inline bool operator==(const QCollisionQueryResult::Hit& left, const QCollisionQueryResult::Hit& right)
122{
123 return left.m_entityId == right.m_entityId;
124}
125
126} // RayCasting
127} // Qt3DRender
128
129QT_END_NAMESPACE
130
131#endif // QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
132

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