1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef ABSTRACTPHYSICSNODE_H |
5 | #define ABSTRACTPHYSICSNODE_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 purely as an |
12 | // implementation detail. 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 <QtQuick3DPhysics/qtquick3dphysicsglobal.h> |
19 | #include <QtQuick3D/private/qquick3dnode_p.h> |
20 | #include <QtQml/QQmlEngine> |
21 | #include <QtQml/QQmlListProperty> |
22 | #include <QtQuick3DPhysics/private/qabstractcollisionshape_p.h> |
23 | |
24 | namespace physx { |
25 | class PxTransform; |
26 | class PxShape; |
27 | } |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QAbstractPhysXNode; |
32 | |
33 | class Q_QUICK3DPHYSICS_EXPORT QAbstractPhysicsNode : public QQuick3DNode |
34 | { |
35 | Q_OBJECT |
36 | Q_PROPERTY( |
37 | QQmlListProperty<QAbstractCollisionShape> collisionShapes READ collisionShapes CONSTANT) |
38 | Q_PROPERTY(bool sendContactReports READ sendContactReports WRITE setSendContactReports NOTIFY |
39 | sendContactReportsChanged) |
40 | Q_PROPERTY(bool receiveContactReports READ receiveContactReports WRITE setReceiveContactReports |
41 | NOTIFY receiveContactReportsChanged) |
42 | Q_PROPERTY(bool sendTriggerReports READ sendTriggerReports WRITE setSendTriggerReports NOTIFY |
43 | sendTriggerReportsChanged REVISION(6, 5)) |
44 | Q_PROPERTY(bool receiveTriggerReports READ receiveTriggerReports WRITE setReceiveTriggerReports |
45 | NOTIFY receiveTriggerReportsChanged REVISION(6, 5)) |
46 | Q_PROPERTY(int filterGroup READ filterGroup WRITE setfilterGroup NOTIFY filterGroupChanged |
47 | REVISION(6, 7)) |
48 | Q_PROPERTY(int filterIgnoreGroups READ filterIgnoreGroups WRITE setFilterIgnoreGroups NOTIFY |
49 | filterIgnoreGroupsChanged REVISION(6, 7)); |
50 | |
51 | QML_NAMED_ELEMENT(PhysicsNode) |
52 | QML_UNCREATABLE("abstract interface" ) |
53 | public: |
54 | QAbstractPhysicsNode(); |
55 | ~QAbstractPhysicsNode() override; |
56 | |
57 | QQmlListProperty<QAbstractCollisionShape> collisionShapes(); |
58 | const QVector<QAbstractCollisionShape *> &getCollisionShapesList() const; |
59 | |
60 | void updateFromPhysicsTransform(const physx::PxTransform &transform); |
61 | |
62 | void registerContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions, |
63 | const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals); |
64 | |
65 | bool sendContactReports() const; |
66 | void setSendContactReports(bool sendContactReports); |
67 | |
68 | bool receiveContactReports() const; |
69 | void setReceiveContactReports(bool receiveContactReports); |
70 | |
71 | Q_REVISION(6, 5) bool sendTriggerReports() const; |
72 | Q_REVISION(6, 5) void setSendTriggerReports(bool sendTriggerReports); |
73 | |
74 | Q_REVISION(6, 5) bool receiveTriggerReports() const; |
75 | Q_REVISION(6, 5) void setReceiveTriggerReports(bool receiveTriggerReports); |
76 | |
77 | bool hasStaticShapes() const { return m_hasStaticShapes; } |
78 | |
79 | virtual QAbstractPhysXNode *createPhysXBackend() = 0; |
80 | |
81 | Q_REVISION(6, 7) int filterGroup() const; |
82 | Q_REVISION(6, 7) void setfilterGroup(int newfilterGroup); |
83 | |
84 | Q_REVISION(6, 7) int filterIgnoreGroups() const; |
85 | Q_REVISION(6, 7) void setFilterIgnoreGroups(int newFilterIgnoreGroups); |
86 | |
87 | private Q_SLOTS: |
88 | void onShapeDestroyed(QObject *object); |
89 | void onShapeNeedsRebuild(QObject *object); |
90 | |
91 | Q_SIGNALS: |
92 | void bodyContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions, |
93 | const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals); |
94 | void sendContactReportsChanged(float sendContactReports); |
95 | void receiveContactReportsChanged(float receiveContactReports); |
96 | Q_REVISION(6, 5) void sendTriggerReportsChanged(float sendTriggerReports); |
97 | Q_REVISION(6, 5) void receiveTriggerReportsChanged(float receiveTriggerReports); |
98 | Q_REVISION(6, 5) void enteredTriggerBody(QAbstractPhysicsNode *body); |
99 | Q_REVISION(6, 5) void exitedTriggerBody(QAbstractPhysicsNode *body); |
100 | Q_REVISION(6, 7) void filterGroupChanged(); |
101 | Q_REVISION(6, 7) void filterIgnoreGroupsChanged(); |
102 | |
103 | private: |
104 | static void qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list, |
105 | QAbstractCollisionShape *shape); |
106 | static QAbstractCollisionShape *qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list, |
107 | qsizetype index); |
108 | static qsizetype qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list); |
109 | static void qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list); |
110 | |
111 | QVector<QAbstractCollisionShape *> m_collisionShapes; |
112 | bool m_shapesDirty = false; |
113 | bool m_sendContactReports = false; |
114 | bool m_receiveContactReports = false; |
115 | bool m_sendTriggerReports = false; |
116 | bool m_receiveTriggerReports = false; |
117 | bool m_hasStaticShapes = false; |
118 | int m_filterGroup = 0; |
119 | int m_filterIgnoreGroups = 0; |
120 | bool m_filtersDirty = false; |
121 | |
122 | friend class QAbstractPhysXNode; |
123 | friend class QPhysicsWorld; // for register/deregister TODO: cleaner mechanism |
124 | friend class SimulationEventCallback; |
125 | QAbstractPhysXNode *m_backendObject = nullptr; |
126 | }; |
127 | |
128 | QT_END_NAMESPACE |
129 | |
130 | #endif // ABSTRACTPHYSICSNODE_H |
131 | |