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_QRAYCASTINGSERVICE_P_H |
5 | #define QT3DRENDER_QRAYCASTINGSERVICE_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 <Qt3DCore/qt3dcore_global.h> |
19 | #include <Qt3DRender/private/qabstractcollisionqueryservice_p.h> |
20 | #include <Qt3DRender/private/qray3d_p.h> |
21 | |
22 | #include <QHash> |
23 | #include <QtConcurrent> |
24 | #include <QAtomicInt> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | namespace Qt3DRender { |
29 | namespace RayCasting { |
30 | |
31 | class QBoundingVolumeProvider; |
32 | class QRayCastingServicePrivate; |
33 | |
34 | typedef QFuture<QCollisionQueryResult> FutureQueryResult; |
35 | |
36 | class Q_3DRENDERSHARED_EXPORT QRayCastingService : public QAbstractCollisionQueryService |
37 | { |
38 | public: |
39 | QRayCastingService(); |
40 | |
41 | QQueryHandle query(const QRay3D &ray, QueryMode mode, QBoundingVolumeProvider *provider) override; |
42 | QCollisionQueryResult::Hit query(const QRay3D &ray, const QBoundingVolume *volume) override; |
43 | |
44 | QCollisionQueryResult fetchResult(const QQueryHandle &handle) override; |
45 | QList<QCollisionQueryResult> fetchAllResults() const override; |
46 | |
47 | protected: |
48 | QRayCastingService(QRayCastingServicePrivate &dd); |
49 | |
50 | private: |
51 | Q_DISABLE_COPY(QRayCastingService) |
52 | Q_DECLARE_PRIVATE(QRayCastingService) |
53 | }; |
54 | |
55 | class QRayCastingServicePrivate : public QAbstractCollisionQueryServicePrivate |
56 | { |
57 | public: |
58 | QRayCastingServicePrivate(const QString &description); |
59 | |
60 | QCollisionQueryResult collides(const QRay3D &ray, |
61 | QBoundingVolumeProvider *provider, |
62 | QAbstractCollisionQueryService::QueryMode mode, |
63 | const QQueryHandle &handle); |
64 | QCollisionQueryResult::Hit collides(const QRay3D &ray, |
65 | const QBoundingVolume *volume); |
66 | |
67 | Q_DECLARE_PUBLIC(QRayCastingService) |
68 | |
69 | struct Query |
70 | { |
71 | QQueryHandle handle; |
72 | QRay3D ray; |
73 | QRayCastingService::QueryMode mode; |
74 | }; |
75 | |
76 | #if QT_CONFIG(concurrent) |
77 | QHash<QQueryHandle, FutureQueryResult> m_results; |
78 | #else |
79 | QHash<QQueryHandle, QCollisionQueryResult> m_results; |
80 | #endif |
81 | QAtomicInt m_handlesCount; |
82 | }; |
83 | |
84 | } // namespace RayCasting |
85 | } // namespace Qt3DRender |
86 | |
87 | QT_END_NAMESPACE |
88 | |
89 | #endif // QT3DRENDER_QRAYCASTINGSERVICE_P_H |
90 | |