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
qphysicsutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QPHYSICSUTILS_P_H
6#define QPHYSICSUTILS_P_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 <QVector3D>
20#include <QQuaternion>
21#include <foundation/PxTransform.h>
22#include <foundation/PxMat33.h>
23#include <foundation/PxQuat.h>
24#include <foundation/PxVec3.h>
25#include <PxFiltering.h>
26
27#include "qfilterdata_p.h"
28
29namespace physx {
30class PxRigidBody;
31}
32
33namespace QPhysicsUtils {
34
35Q_ALWAYS_INLINE physx::PxVec3 toPhysXType(const QVector3D &qvec)
36{
37 return physx::PxVec3(qvec.x(), qvec.y(), qvec.z());
38}
39
40Q_ALWAYS_INLINE physx::PxQuat toPhysXType(const QQuaternion &qquat)
41{
42 return physx::PxQuat(qquat.x(), qquat.y(), qquat.z(), qquat.scalar());
43}
44
45Q_ALWAYS_INLINE physx::PxMat33 toPhysXType(const QMatrix3x3 &m)
46{
47 return physx::PxMat33(const_cast<float *>(m.constData()));
48}
49
50Q_ALWAYS_INLINE QVector3D toQtType(const physx::PxVec3 &vec)
51{
52 return QVector3D(vec.x, vec.y, vec.z);
53}
54
55Q_ALWAYS_INLINE QQuaternion toQtType(const physx::PxQuat &quat)
56{
57 return QQuaternion(quat.w, quat.x, quat.y, quat.z);
58}
59
66
67Q_ALWAYS_INLINE bool fuzzyEquals(const physx::PxTransform &a, const physx::PxTransform &b)
68{
69 return qFuzzyCompare(a.p.x, b.p.x) && qFuzzyCompare(a.p.y, b.p.y) && qFuzzyCompare(a.p.z, b.p.z)
70 && qFuzzyCompare(a.q.x, b.q.x) && qFuzzyCompare(a.q.y, b.q.y)
71 && qFuzzyCompare(a.q.z, b.q.z) && qFuzzyCompare(a.q.w, b.q.w);
72}
73
74Q_ALWAYS_INLINE QFilterData toQtType(const physx::PxFilterData &data)
75{
79 return qtData;
80}
81
82Q_ALWAYS_INLINE physx::PxFilterData toPhysXType(const QFilterData &data)
83{
87 return pxData;
88}
89
90// Whether two nodes are filtered out from each other: either side naming the
91// other's group among the ones it ignores is enough. PhysX asks this in
92// contactReportFilterShader() as it decides what to pair. A CharacterController,
93// which moves through scene queries rather than pairs, asks it of what it
94// sweeps against, and a GravityField without shapes, which acts on bodies it
95// never pairs with, asks it of the nodes, so that the answer is the same
96// either way.
98{
99 const auto isBitSet = [](quint32 value, quint32 position) {
100 Q_ASSERT(position < 32);
101 return (value & (1u << position)) != 0u;
102 };
103
104 return a.group < 32 && b.group < 32
105 && (isBitSet(a.ignoreGroups, b.group) || isBitSet(b.ignoreGroups, a.group));
106}
107
108Q_ALWAYS_INLINE bool isFinite(const QVector3D &v)
109{
110 return qIsFinite(v.x()) && qIsFinite(v.y()) && qIsFinite(v.z());
111}
112
113Q_ALWAYS_INLINE bool isFinite(const QQuaternion &q)
114{
115 return qIsFinite(q.x()) && qIsFinite(q.y()) && qIsFinite(q.z()) && qIsFinite(q.scalar());
116}
117
118Q_ALWAYS_INLINE bool isFinite(const physx::PxVec3 &v)
119{
120 return qIsFinite(v.x) && qIsFinite(v.y) && qIsFinite(v.z);
121}
122
124}
125
126#endif // QPHYSICSUTILS_P_H
Q_ALWAYS_INLINE bool fuzzyEquals(const physx::PxTransform &a, const physx::PxTransform &b)
const QQuaternion kMinus90YawRotation
Q_ALWAYS_INLINE bool isFinite(const QVector3D &v)
Q_ALWAYS_INLINE bool isFilteredOut(const QFilterData &a, const QFilterData &b)
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
#define emit