1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qphysxstaticbody_p.h" |
5 | |
6 | #include "PxPhysics.h" |
7 | #include "PxRigidActor.h" |
8 | #include "PxRigidStatic.h" |
9 | |
10 | #include "qphysicsutils_p.h" |
11 | #include "qphysicsworld_p.h" |
12 | #include "qstaticrigidbody_p.h" |
13 | #include "qstaticphysxobjects_p.h" |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | QPhysXStaticBody::QPhysXStaticBody(QStaticRigidBody *frontEnd) : QPhysXRigidBody(frontEnd) { } |
18 | |
19 | DebugDrawBodyType QPhysXStaticBody::getDebugDrawBodyType() |
20 | { |
21 | return DebugDrawBodyType::Static; |
22 | } |
23 | |
24 | void QPhysXStaticBody::sync(float deltaTime, QHash<QQuick3DNode *, QMatrix4x4> &transformCache) |
25 | { |
26 | auto *staticBody = static_cast<QStaticRigidBody *>(frontendNode); |
27 | const physx::PxTransform poseNew = QPhysicsUtils::toPhysXTransform(position: staticBody->scenePosition(), |
28 | rotation: staticBody->sceneRotation()); |
29 | const physx::PxTransform poseOld = actor->getGlobalPose(); |
30 | |
31 | // For performance we only update static objects if they have been moved |
32 | if (!QPhysicsUtils::fuzzyEquals(a: poseNew, b: poseOld)) |
33 | actor->setGlobalPose(pose: poseNew); |
34 | |
35 | const bool disabledPrevious = actor->getActorFlags() & physx::PxActorFlag::eDISABLE_SIMULATION; |
36 | const bool disabled = !staticBody->simulationEnabled(); |
37 | if (disabled != disabledPrevious) { |
38 | actor->setActorFlag(flag: physx::PxActorFlag::eDISABLE_SIMULATION, value: disabled); |
39 | } |
40 | |
41 | QPhysXActorBody::sync(deltaTime, transformCache); |
42 | } |
43 | |
44 | void QPhysXStaticBody::createActor(QPhysXWorld * /*physX*/) |
45 | { |
46 | auto &s_physx = StaticPhysXObjects::getReference(); |
47 | const physx::PxTransform trf = QPhysicsUtils::toPhysXTransform(position: frontendNode->scenePosition(), |
48 | rotation: frontendNode->sceneRotation()); |
49 | actor = s_physx.physics->createRigidStatic(pose: trf); |
50 | } |
51 | |
52 | QT_END_NAMESPACE |
53 |