| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QPHYSICSUTILS_P_H |
| 5 | #define QPHYSICSUTILS_P_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 <QVector3D> |
| 19 | #include <QQuaternion> |
| 20 | #include <foundation/PxTransform.h> |
| 21 | #include <foundation/PxMat33.h> |
| 22 | #include <foundation/PxQuat.h> |
| 23 | #include <foundation/PxVec3.h> |
| 24 | |
| 25 | namespace physx { |
| 26 | class PxRigidBody; |
| 27 | } |
| 28 | |
| 29 | namespace QPhysicsUtils { |
| 30 | |
| 31 | Q_ALWAYS_INLINE physx::PxVec3 toPhysXType(const QVector3D &qvec) |
| 32 | { |
| 33 | return physx::PxVec3(qvec.x(), qvec.y(), qvec.z()); |
| 34 | } |
| 35 | |
| 36 | Q_ALWAYS_INLINE physx::PxQuat toPhysXType(const QQuaternion &qquat) |
| 37 | { |
| 38 | return physx::PxQuat(qquat.x(), qquat.y(), qquat.z(), qquat.scalar()); |
| 39 | } |
| 40 | |
| 41 | Q_ALWAYS_INLINE physx::PxMat33 toPhysXType(const QMatrix3x3 &m) |
| 42 | { |
| 43 | return physx::PxMat33(const_cast<float *>(m.constData())); |
| 44 | } |
| 45 | |
| 46 | Q_ALWAYS_INLINE QVector3D toQtType(const physx::PxVec3 &vec) |
| 47 | { |
| 48 | return QVector3D(vec.x, vec.y, vec.z); |
| 49 | } |
| 50 | |
| 51 | Q_ALWAYS_INLINE QQuaternion toQtType(const physx::PxQuat &quat) |
| 52 | { |
| 53 | return QQuaternion(quat.w, quat.x, quat.y, quat.z); |
| 54 | } |
| 55 | |
| 56 | Q_ALWAYS_INLINE physx::PxTransform toPhysXTransform(const QVector3D &position, |
| 57 | const QQuaternion &rotation) |
| 58 | { |
| 59 | return physx::PxTransform(QPhysicsUtils::toPhysXType(qvec: position), |
| 60 | QPhysicsUtils::toPhysXType(qquat: rotation)); |
| 61 | } |
| 62 | |
| 63 | Q_ALWAYS_INLINE bool fuzzyEquals(const physx::PxTransform &a, const physx::PxTransform &b) |
| 64 | { |
| 65 | return qFuzzyCompare(p1: a.p.x, p2: b.p.x) && qFuzzyCompare(p1: a.p.y, p2: b.p.y) && qFuzzyCompare(p1: a.p.z, p2: b.p.z) |
| 66 | && qFuzzyCompare(p1: a.q.x, p2: b.q.x) && qFuzzyCompare(p1: a.q.y, p2: b.q.y) |
| 67 | && qFuzzyCompare(p1: a.q.z, p2: b.q.z) && qFuzzyCompare(p1: a.q.w, p2: b.q.w); |
| 68 | } |
| 69 | |
| 70 | inline const QQuaternion kMinus90YawRotation = QQuaternion::fromEulerAngles(pitch: 0, yaw: -90, roll: 0); |
| 71 | } |
| 72 | |
| 73 | #endif // QPHYSICSUTILS_P_H |
| 74 | |