| 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 <QtGui/qgenericmatrix.h> |
| 23 | |
| 24 | namespace physx { |
| 25 | class PxRigidBody; |
| 26 | } |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QDynamicRigidBody; |
| 31 | |
| 32 | class QPhysicsCommand |
| 33 | { |
| 34 | Q_DISABLE_COPY_MOVE(QPhysicsCommand) |
| 35 | public: |
| 36 | QPhysicsCommand() = default; |
| 37 | virtual ~QPhysicsCommand(); |
| 38 | virtual void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) = 0; |
| 39 | }; |
| 40 | |
| 41 | class QPhysicsCommandApplyCentralForce : public QPhysicsCommand |
| 42 | { |
| 43 | public: |
| 44 | explicit QPhysicsCommandApplyCentralForce(const QVector3D &inForce); |
| 45 | ~QPhysicsCommandApplyCentralForce() override; |
| 46 | |
| 47 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 48 | |
| 49 | private: |
| 50 | QVector3D force; |
| 51 | }; |
| 52 | |
| 53 | class QPhysicsCommandApplyForce : public QPhysicsCommand |
| 54 | { |
| 55 | public: |
| 56 | explicit QPhysicsCommandApplyForce(const QVector3D &inForce, const QVector3D &inPosition); |
| 57 | ~QPhysicsCommandApplyForce() override; |
| 58 | |
| 59 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 60 | |
| 61 | private: |
| 62 | QVector3D force; |
| 63 | QVector3D position; |
| 64 | }; |
| 65 | |
| 66 | class QPhysicsCommandApplyTorque : public QPhysicsCommand |
| 67 | { |
| 68 | public: |
| 69 | explicit QPhysicsCommandApplyTorque(const QVector3D &inTorque); |
| 70 | ~QPhysicsCommandApplyTorque() override; |
| 71 | |
| 72 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 73 | |
| 74 | private: |
| 75 | QVector3D torque; |
| 76 | }; |
| 77 | |
| 78 | class QPhysicsCommandApplyCentralImpulse : public QPhysicsCommand |
| 79 | { |
| 80 | public: |
| 81 | explicit QPhysicsCommandApplyCentralImpulse(const QVector3D &inImpulse); |
| 82 | ~QPhysicsCommandApplyCentralImpulse() override; |
| 83 | |
| 84 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 85 | |
| 86 | private: |
| 87 | QVector3D impulse; |
| 88 | }; |
| 89 | |
| 90 | class QPhysicsCommandApplyImpulse : public QPhysicsCommand |
| 91 | { |
| 92 | public: |
| 93 | explicit QPhysicsCommandApplyImpulse(const QVector3D &inImpulse, const QVector3D &inPosition); |
| 94 | ~QPhysicsCommandApplyImpulse() override; |
| 95 | |
| 96 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 97 | |
| 98 | private: |
| 99 | QVector3D impulse; |
| 100 | QVector3D position; |
| 101 | }; |
| 102 | |
| 103 | class QPhysicsCommandApplyTorqueImpulse : public QPhysicsCommand |
| 104 | { |
| 105 | public: |
| 106 | explicit QPhysicsCommandApplyTorqueImpulse(const QVector3D &inImpulse); |
| 107 | ~QPhysicsCommandApplyTorqueImpulse() override; |
| 108 | |
| 109 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 110 | |
| 111 | private: |
| 112 | QVector3D impulse; |
| 113 | }; |
| 114 | |
| 115 | class QPhysicsCommandSetAngularVelocity : public QPhysicsCommand |
| 116 | { |
| 117 | public: |
| 118 | explicit QPhysicsCommandSetAngularVelocity(const QVector3D &inAngularVelocity); |
| 119 | ~QPhysicsCommandSetAngularVelocity() override; |
| 120 | |
| 121 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 122 | |
| 123 | private: |
| 124 | QVector3D angularVelocity; |
| 125 | }; |
| 126 | |
| 127 | class QPhysicsCommandSetLinearVelocity : public QPhysicsCommand |
| 128 | { |
| 129 | public: |
| 130 | explicit QPhysicsCommandSetLinearVelocity(const QVector3D &inLinearVelocity); |
| 131 | ~QPhysicsCommandSetLinearVelocity() override; |
| 132 | |
| 133 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 134 | |
| 135 | private: |
| 136 | QVector3D linearVelocity; |
| 137 | }; |
| 138 | |
| 139 | class QPhysicsCommandSetMass : public QPhysicsCommand |
| 140 | { |
| 141 | public: |
| 142 | explicit QPhysicsCommandSetMass(float inMass); |
| 143 | ~QPhysicsCommandSetMass() override; |
| 144 | |
| 145 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 146 | |
| 147 | private: |
| 148 | float mass; |
| 149 | }; |
| 150 | |
| 151 | class QPhysicsCommandSetMassAndInertiaTensor : public QPhysicsCommand |
| 152 | { |
| 153 | public: |
| 154 | explicit QPhysicsCommandSetMassAndInertiaTensor(float inMass, const QVector3D &inInertia); |
| 155 | ~QPhysicsCommandSetMassAndInertiaTensor() override; |
| 156 | |
| 157 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 158 | |
| 159 | private: |
| 160 | float mass; |
| 161 | QVector3D inertia; |
| 162 | }; |
| 163 | |
| 164 | class QPhysicsCommandSetMassAndInertiaMatrix : public QPhysicsCommand |
| 165 | { |
| 166 | public: |
| 167 | explicit QPhysicsCommandSetMassAndInertiaMatrix(float inMass, const QMatrix3x3 &inInertia); |
| 168 | ~QPhysicsCommandSetMassAndInertiaMatrix() override; |
| 169 | |
| 170 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 171 | |
| 172 | private: |
| 173 | float mass; |
| 174 | QMatrix3x3 inertia; |
| 175 | }; |
| 176 | |
| 177 | class QPhysicsCommandSetDensity : public QPhysicsCommand |
| 178 | { |
| 179 | public: |
| 180 | explicit QPhysicsCommandSetDensity(float inDensity); |
| 181 | ~QPhysicsCommandSetDensity() override; |
| 182 | |
| 183 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 184 | |
| 185 | private: |
| 186 | float density; |
| 187 | }; |
| 188 | |
| 189 | class QPhysicsCommandSetIsKinematic : public QPhysicsCommand |
| 190 | { |
| 191 | public: |
| 192 | explicit QPhysicsCommandSetIsKinematic(bool inIsKinematic); |
| 193 | ~QPhysicsCommandSetIsKinematic() override; |
| 194 | |
| 195 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 196 | |
| 197 | private: |
| 198 | bool isKinematic; |
| 199 | }; |
| 200 | |
| 201 | class QPhysicsCommandSetGravityEnabled : public QPhysicsCommand |
| 202 | { |
| 203 | public: |
| 204 | explicit QPhysicsCommandSetGravityEnabled(bool inGravityEnabled); |
| 205 | ~QPhysicsCommandSetGravityEnabled() override; |
| 206 | |
| 207 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 208 | |
| 209 | private: |
| 210 | bool gravityEnabled; |
| 211 | }; |
| 212 | |
| 213 | class QPhysicsCommandReset : public QPhysicsCommand |
| 214 | { |
| 215 | public: |
| 216 | explicit QPhysicsCommandReset(QVector3D inPosition, QVector3D inEulerRotation); |
| 217 | ~QPhysicsCommandReset() override; |
| 218 | |
| 219 | void execute(const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body) override; |
| 220 | |
| 221 | private: |
| 222 | QVector3D position; |
| 223 | QVector3D eulerRotation; |
| 224 | }; |
| 225 | |
| 226 | QT_END_NAMESPACE |
| 227 | |
| 228 | #endif // QPHYSICSCOMMANDS_H |
| 229 | |