1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QPHYSICSCOMMANDS_H |
5 | #define QPHYSICSCOMMANDS_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 | |
20 | #include <QtCore/QList> |
21 | #include <QtGui/QVector3D> |
22 | #include <QQuaternion> |
23 | |
24 | namespace physx { |
25 | class PxRigidBody; |
26 | } |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QDynamicRigidBody; |
31 | |
32 | class QPhysicsCommand |
33 | { |
34 | public: |
35 | virtual ~QPhysicsCommand() = default; |
36 | virtual void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) = 0; |
37 | }; |
38 | |
39 | class QPhysicsCommandApplyCentralForce : public QPhysicsCommand |
40 | { |
41 | public: |
42 | QPhysicsCommandApplyCentralForce(const QVector3D &inForce); |
43 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
44 | |
45 | private: |
46 | QVector3D force; |
47 | }; |
48 | |
49 | class QPhysicsCommandApplyForce : public QPhysicsCommand |
50 | { |
51 | public: |
52 | QPhysicsCommandApplyForce(const QVector3D &inForce, const QVector3D &inPosition); |
53 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
54 | |
55 | private: |
56 | QVector3D force; |
57 | QVector3D position; |
58 | }; |
59 | |
60 | class QPhysicsCommandApplyTorque : public QPhysicsCommand |
61 | { |
62 | public: |
63 | QPhysicsCommandApplyTorque(const QVector3D &inTorque); |
64 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
65 | |
66 | private: |
67 | QVector3D torque; |
68 | }; |
69 | |
70 | class QPhysicsCommandApplyCentralImpulse : public QPhysicsCommand |
71 | { |
72 | public: |
73 | QPhysicsCommandApplyCentralImpulse(const QVector3D &inImpulse); |
74 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
75 | |
76 | private: |
77 | QVector3D impulse; |
78 | }; |
79 | |
80 | class QPhysicsCommandApplyImpulse : public QPhysicsCommand |
81 | { |
82 | public: |
83 | QPhysicsCommandApplyImpulse(const QVector3D &inImpulse, const QVector3D &inPosition); |
84 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
85 | |
86 | private: |
87 | QVector3D impulse; |
88 | QVector3D position; |
89 | }; |
90 | |
91 | class QPhysicsCommandApplyTorqueImpulse : public QPhysicsCommand |
92 | { |
93 | public: |
94 | QPhysicsCommandApplyTorqueImpulse(const QVector3D &inImpulse); |
95 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
96 | |
97 | private: |
98 | QVector3D impulse; |
99 | }; |
100 | |
101 | class QPhysicsCommandSetAngularVelocity : public QPhysicsCommand |
102 | { |
103 | public: |
104 | QPhysicsCommandSetAngularVelocity(const QVector3D &inAngularVelocity); |
105 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
106 | |
107 | private: |
108 | QVector3D angularVelocity; |
109 | }; |
110 | |
111 | class QPhysicsCommandSetLinearVelocity : public QPhysicsCommand |
112 | { |
113 | public: |
114 | QPhysicsCommandSetLinearVelocity(const QVector3D &inLinearVelocity); |
115 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
116 | |
117 | private: |
118 | QVector3D linearVelocity; |
119 | }; |
120 | |
121 | class QPhysicsCommandSetMass : public QPhysicsCommand |
122 | { |
123 | public: |
124 | QPhysicsCommandSetMass(float inMass); |
125 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
126 | |
127 | private: |
128 | float mass; |
129 | }; |
130 | |
131 | class QPhysicsCommandSetMassAndInertiaTensor : public QPhysicsCommand |
132 | { |
133 | public: |
134 | QPhysicsCommandSetMassAndInertiaTensor(float inMass, const QVector3D &inInertia); |
135 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
136 | |
137 | private: |
138 | float mass; |
139 | QVector3D inertia; |
140 | }; |
141 | |
142 | class QPhysicsCommandSetMassAndInertiaMatrix : public QPhysicsCommand |
143 | { |
144 | public: |
145 | QPhysicsCommandSetMassAndInertiaMatrix(float inMass, const QMatrix3x3 &inInertia); |
146 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
147 | |
148 | private: |
149 | float mass; |
150 | QMatrix3x3 inertia; |
151 | }; |
152 | |
153 | class QPhysicsCommandSetDensity : public QPhysicsCommand |
154 | { |
155 | public: |
156 | QPhysicsCommandSetDensity(float inDensity); |
157 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
158 | |
159 | private: |
160 | float density; |
161 | }; |
162 | |
163 | class QPhysicsCommandSetIsKinematic : public QPhysicsCommand |
164 | { |
165 | public: |
166 | QPhysicsCommandSetIsKinematic(bool inIsKinematic); |
167 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
168 | |
169 | private: |
170 | bool isKinematic; |
171 | }; |
172 | |
173 | class QPhysicsCommandSetGravityEnabled : public QPhysicsCommand |
174 | { |
175 | public: |
176 | QPhysicsCommandSetGravityEnabled(bool inGravityEnabled); |
177 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
178 | |
179 | private: |
180 | bool gravityEnabled; |
181 | }; |
182 | |
183 | class QPhysicsCommandReset : public QPhysicsCommand |
184 | { |
185 | public: |
186 | QPhysicsCommandReset(QVector3D inPosition, QVector3D inEulerRotation); |
187 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
188 | |
189 | private: |
190 | QVector3D position; |
191 | QVector3D eulerRotation; |
192 | }; |
193 | |
194 | QT_END_NAMESPACE |
195 | |
196 | #endif // QPHYSICSCOMMANDS_H |
197 | |