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
25namespace physx {
26template<class Type>
29class PxShape;
30}
31
33
35class QPhysicsJoint;
36
37class Q_QUICK3DPHYSICS_EXPORT QAbstractPhysicsNode : public QQuick3DNode
38{
39 Q_OBJECT
40 Q_PROPERTY(
41 QQmlListProperty<QAbstractCollisionShape> collisionShapes READ collisionShapes CONSTANT)
42 Q_PROPERTY(bool sendContactReports READ sendContactReports WRITE setSendContactReports NOTIFY
43 sendContactReportsChanged)
44 Q_PROPERTY(bool receiveContactReports READ receiveContactReports WRITE setReceiveContactReports
45 NOTIFY receiveContactReportsChanged)
46 Q_PROPERTY(bool sendTriggerReports READ sendTriggerReports WRITE setSendTriggerReports NOTIFY
47 sendTriggerReportsChanged REVISION(6, 5))
48 Q_PROPERTY(bool receiveTriggerReports READ receiveTriggerReports WRITE setReceiveTriggerReports
49 NOTIFY receiveTriggerReportsChanged REVISION(6, 5))
50 Q_PROPERTY(int filterGroup READ filterGroup WRITE setfilterGroup NOTIFY filterGroupChanged
51 REVISION(6, 7))
52 Q_PROPERTY(int filterIgnoreGroups READ filterIgnoreGroups WRITE setFilterIgnoreGroups NOTIFY
53 filterIgnoreGroupsChanged REVISION(6, 7));
54
55 QML_NAMED_ELEMENT(PhysicsNode)
56 QML_UNCREATABLE("abstract interface")
57public:
58 QAbstractPhysicsNode();
59 ~QAbstractPhysicsNode() override;
60
61 QQmlListProperty<QAbstractCollisionShape> collisionShapes();
62 const QVector<QAbstractCollisionShape *> &getCollisionShapesList() const;
63
64 void updateFromPhysicsTransform(const physx::PxTransform &transform);
65
66 void registerContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions,
67 const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals);
68
69 bool sendContactReports() const;
70 void setSendContactReports(bool sendContactReports);
71
72 bool receiveContactReports() const;
73 void setReceiveContactReports(bool receiveContactReports);
74
75 Q_REVISION(6, 5) bool sendTriggerReports() const;
76 Q_REVISION(6, 5) void setSendTriggerReports(bool sendTriggerReports);
78 Q_REVISION(6, 5) bool receiveTriggerReports() const;
79 Q_REVISION(6, 5) void setReceiveTriggerReports(bool receiveTriggerReports);
81 bool hasStaticShapes() const { return m_hasStaticShapes; }
83 virtual QAbstractPhysXNode *createPhysXBackend() = 0;
84
85 Q_REVISION(6, 7) int filterGroup() const;
86 Q_REVISION(6, 7) void setfilterGroup(int newfilterGroup);
87
88 Q_REVISION(6, 7) int filterIgnoreGroups() const;
89 Q_REVISION(6, 7) void setFilterIgnoreGroups(int newFilterIgnoreGroups);
91private Q_SLOTS:
92 void onShapeDestroyed(QObject *object);
93 void onShapeNeedsRebuild(QObject *object);
95Q_SIGNALS:
96 void bodyContact(QAbstractPhysicsNode *body, const QVector<QVector3D> &positions,
97 const QVector<QVector3D> &impulses, const QVector<QVector3D> &normals);
98 void sendContactReportsChanged(float sendContactReports);
99 void receiveContactReportsChanged(float receiveContactReports);
100 Q_REVISION(6, 5) void sendTriggerReportsChanged(float sendTriggerReports);
101 Q_REVISION(6, 5) void receiveTriggerReportsChanged(float receiveTriggerReports);
102 Q_REVISION(6, 5) void enteredTriggerBody(QAbstractPhysicsNode *body);
103 Q_REVISION(6, 5) void exitedTriggerBody(QAbstractPhysicsNode *body);
104 Q_REVISION(6, 7) void filterGroupChanged();
105 Q_REVISION(6, 7) void filterIgnoreGroupsChanged();
106
107private:
108 static void qmlAppendShape(QQmlListProperty<QAbstractCollisionShape> *list,
109 QAbstractCollisionShape *shape);
110 static QAbstractCollisionShape *qmlShapeAt(QQmlListProperty<QAbstractCollisionShape> *list,
111 qsizetype index);
112 static qsizetype qmlShapeCount(QQmlListProperty<QAbstractCollisionShape> *list);
113 static void qmlClearShapes(QQmlListProperty<QAbstractCollisionShape> *list);
114
115 QVector<QAbstractCollisionShape *> m_collisionShapes;
116 bool m_shapesDirty = false;
117 bool m_sendContactReports = false;
118 bool m_receiveContactReports = false;
119 bool m_sendTriggerReports = false;
120 bool m_receiveTriggerReports = false;
121 bool m_hasStaticShapes = false;
122 int m_filterGroup = 0;
123 int m_filterIgnoreGroups = 0;
124 bool m_filtersDirty = false;
125
126 friend class QPhysicsJoint;
127 friend class QAbstractPhysXNode;
128 friend class QPhysicsWorld; // for register/deregister TODO: cleaner mechanism
129 friend class SimulationEventCallback;
130 QAbstractPhysXNode *m_backendObject = nullptr;
131};
132
134
135#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)
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 detachFrontend()
bool cleanupIfRemoved(QPhysXWorld *physX)
virtual bool useTriggerFlag()
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
void updateFilters() override
physx::PxTransform getGlobalPose() override
physx::PxD6Motion::Enum toPxEnum(QD6Joint::Motion val)
Definition qd6joint.cpp:286
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