Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstractphysicsnode_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef ABSTRACTPHYSICSNODE_H
6#define ABSTRACTPHYSICSNODE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DPhysics/qtquick3dphysicsglobal.h>
20#include <QtQuick3D/private/qquick3dnode_p.h>
21#include <QtQml/QQmlEngine>
22#include <QtQml/QQmlListProperty>
23#include <QtQuick3DPhysics/private/qabstractcollisionshape_p.h>
24#include <QtQuick3DPhysics/private/qfilterdata_p.h>
25
26namespace physx {
27template<class Type>
30class PxShape;
31}
32
34
36class QPhysicsJoint;
37
38class Q_QUICK3DPHYSICS_EXPORT QAbstractPhysicsNode : public QQuick3DNode
39{
40 Q_OBJECT
41 Q_PROPERTY(
42 QQmlListProperty<QAbstractCollisionShape> collisionShapes READ collisionShapes CONSTANT)
43 Q_PROPERTY(bool sendContactReports READ sendContactReports WRITE setSendContactReports NOTIFY
44 sendContactReportsChanged)
45 Q_PROPERTY(bool receiveContactReports READ receiveContactReports WRITE setReceiveContactReports
46 NOTIFY receiveContactReportsChanged)
47 Q_PROPERTY(bool sendTriggerReports READ sendTriggerReports WRITE setSendTriggerReports NOTIFY
48 sendTriggerReportsChanged REVISION(6, 5))
49 Q_PROPERTY(bool receiveTriggerReports READ receiveTriggerReports WRITE setReceiveTriggerReports
50 NOTIFY receiveTriggerReportsChanged REVISION(6, 5))
51 Q_PROPERTY(int filterGroup READ filterGroup WRITE setfilterGroup NOTIFY filterGroupChanged
52 REVISION(6, 7))
53 Q_PROPERTY(int filterIgnoreGroups READ filterIgnoreGroups WRITE setFilterIgnoreGroups NOTIFY
54 filterIgnoreGroupsChanged REVISION(6, 7));
55
56 QML_NAMED_ELEMENT(PhysicsNode)
57 QML_UNCREATABLE("abstract interface")
58public:
59 QAbstractPhysicsNode();
60 ~QAbstractPhysicsNode() override;
61
62 QQmlListProperty<QAbstractCollisionShape> collisionShapes();
63 const QVector<QAbstractCollisionShape *> &getCollisionShapesList() const;
64
65 void updateFromPhysicsTransform(const physx::PxTransform &transform);
66
67 void registerContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions,
68 const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals);
69
70 bool sendContactReports() const;
71 void setSendContactReports(bool sendContactReports);
72
73 bool receiveContactReports() const;
74 void setReceiveContactReports(bool receiveContactReports);
75
76 Q_REVISION(6, 5) bool sendTriggerReports() const;
77 Q_REVISION(6, 5) void setSendTriggerReports(bool sendTriggerReports);
79 Q_REVISION(6, 5) bool receiveTriggerReports() const;
80 Q_REVISION(6, 5) void setReceiveTriggerReports(bool receiveTriggerReports);
82 bool hasStaticShapes() const { return m_hasStaticShapes; }
84 virtual QAbstractPhysXNode *createPhysXBackend() = 0;
85
86 Q_REVISION(6, 7) int filterGroup() const;
87 Q_REVISION(6, 7) void setfilterGroup(int newfilterGroup);
88
89 Q_REVISION(6, 7) int filterIgnoreGroups() const;
90 Q_REVISION(6, 7) void setFilterIgnoreGroups(int newFilterIgnoreGroups);
91
92 // Both of the above as PhysX is told them.
93 QFilterData filterData() const;
95private Q_SLOTS:
96 void onShapeDestroyed(QObject *object);
97 void onShapeNeedsRebuild(QObject *object);
99Q_SIGNALS:
100 void bodyContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions,
101 const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals);
102 void sendContactReportsChanged(float sendContactReports);
103 void receiveContactReportsChanged(float receiveContactReports);
104 Q_REVISION(6, 5) void sendTriggerReportsChanged(float sendTriggerReports);
105 Q_REVISION(6, 5) void receiveTriggerReportsChanged(float receiveTriggerReports);
106 Q_REVISION(6, 5) void enteredTriggerBody(QAbstractPhysicsNode *body);
107 Q_REVISION(6, 5) void exitedTriggerBody(QAbstractPhysicsNode *body);
108 Q_REVISION(6, 7) void filterGroupChanged();
109 Q_REVISION(6, 7) void filterIgnoreGroupsChanged();
110
111private:
112 static void qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list,
113 QAbstractCollisionShape *shape);
114 static QAbstractCollisionShape *qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list,
115 qsizetype index);
116 static qsizetype qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list);
117 static void qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list);
118
119 QVector<QAbstractCollisionShape *> m_collisionShapes;
120 bool m_shapesDirty = false;
121 bool m_sendContactReports = false;
122 bool m_receiveContactReports = false;
123 bool m_sendTriggerReports = false;
124 bool m_receiveTriggerReports = false;
125 bool m_hasStaticShapes = false;
126 int m_filterGroup = 0;
127 int m_filterIgnoreGroups = 0;
128 bool m_filtersDirty = false;
129
130 friend class QPhysicsJoint;
131 friend class QAbstractPhysXNode;
132 friend class QPhysicsWorld; // for register/deregister TODO: cleaner mechanism
133 friend class SimulationEventCallback;
134 QAbstractPhysXNode *m_backendObject = nullptr;
135};
136
138
139#endif // ABSTRACTPHYSICSNODE_H
virtual void updateDefaultDensity(float density)
virtual void sync(float deltaTime, QHash< QQuick3DNode *, QMatrix4x4 > &transformCache)=0
QAbstractPhysicsNode * frontendNode
QVector< physx::PxShape * > shapes
virtual void cleanup(QPhysXWorld *)
physx::PxMaterial * material
virtual void rebuildDirtyShapes(QPhysicsWorld *, QPhysXWorld *)
PhysicsMaterialProperties materialProperties
void setShapesDirty(bool dirty)
static QAbstractPhysXNode * backendOf(const QAbstractPhysicsNode *node)
virtual bool debugGeometryCapability()
virtual physx::PxTransform getGlobalPose()
virtual void init(QPhysicsWorld *world, QPhysXWorld *physX)=0
virtual void markDirtyShapes()
virtual DebugDrawBodyType getDebugDrawBodyType()
virtual QPhysicsMaterial * qtMaterial() const
void setFiltersDirty(bool dirty)
virtual void updateFilters(QPhysXWorld *physX)
virtual void detachFrontend()
bool cleanupIfRemoved(QPhysXWorld *physX)
virtual bool useTriggerFlag()
void updateFilters(QPhysXWorld *physX) override
void markDirtyShapes() override
void buildShapes(QPhysXWorld *physX)
void rebuildDirtyShapes(QPhysicsWorld *world, QPhysXWorld *physX) override
void init(QPhysicsWorld *world, QPhysXWorld *physX) override
void detachFrontend() override
bool debugGeometryCapability() override
void cleanup(QPhysXWorld *physX) override
physx::PxRigidActor * actor
virtual void createActor(QPhysXWorld *physX)
void sync(float deltaTime, QHash< QQuick3DNode *, QMatrix4x4 > &transformCache) override
physx::PxTransform getGlobalPose() override
physx::PxD6Motion::Enum toPxEnum(QD6Joint::Motion val)
Definition qd6joint.cpp:278
PxTransformT< float > PxTransform
DebugDrawBodyType
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
friend bool operator==(const PhysicsMaterialProperties &lhs, const PhysicsMaterialProperties &rhs) noexcept
friend size_t qHash(const PhysicsMaterialProperties &properties, size_t seed=0) noexcept
static constexpr PhysicsMaterialProperties none()
physx::PxMaterial * material
physx::PxDefaultErrorCallback defaultErrorCallback
physx::PxDefaultAllocator defaultAllocatorCallback
static StaticPhysXObjects & getReference()
physx::PxFoundation * foundation
QHash< PhysicsMaterialProperties, SharedPhysicsMaterial > materials
physx::PxDefaultCpuDispatcher * dispatcher
physx::PxPhysics * physics