Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
29
namespace
physx
{
30
class
PxRigidBody;
31
}
32
33
namespace
QPhysicsUtils
{
34
35
Q_ALWAYS_INLINE
physx
::PxVec3
toPhysXType
(
const
QVector3D
&
qvec
)
36
{
37
return
physx
::
PxVec3
(
qvec
.
x
(),
qvec
.
y
(),
qvec
.
z
());
38
}
39
40
Q_ALWAYS_INLINE
physx
::PxQuat
toPhysXType
(
const
QQuaternion
&
qquat
)
41
{
42
return
physx
::
PxQuat
(
qquat
.
x
(),
qquat
.
y
(),
qquat
.
z
(),
qquat
.
scalar
());
43
}
44
45
Q_ALWAYS_INLINE
physx
::PxMat33
toPhysXType
(
const
QMatrix3x3
&
m
)
46
{
47
return
physx
::
PxMat33
(
const_cast
<
float
*>(
m
.
constData
()));
48
}
49
50
Q_ALWAYS_INLINE QVector3D
toQtType
(
const
physx
::
PxVec3
&
vec
)
51
{
52
return
QVector3D
(
vec
.
x
,
vec
.
y
,
vec
.
z
);
53
}
54
55
Q_ALWAYS_INLINE QQuaternion
toQtType
(
const
physx
::
PxQuat
&
quat
)
56
{
57
return
QQuaternion
(
quat
.
w
,
quat
.
x
,
quat
.
y
,
quat
.
z
);
58
}
59
60
Q_ALWAYS_INLINE
physx
::PxTransform
toPhysXTransform
(
const
QVector3D
&
position
,
61
const
QQuaternion
&
rotation
)
62
{
63
return
physx
::
PxTransform
(
QPhysicsUtils
::
toPhysXType
(
position
),
64
QPhysicsUtils
::
toPhysXType
(
rotation
));
65
}
66
67
Q_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
74
Q_ALWAYS_INLINE QFilterData
toQtType
(
const
physx
::
PxFilterData
&
data
)
75
{
76
QFilterData
qtData
;
77
qtData
.
group
=
data
.
word0
;
78
qtData
.
ignoreGroups
=
data
.
word1
;
79
return
qtData
;
80
}
81
82
Q_ALWAYS_INLINE
physx
::PxFilterData
toPhysXType
(
const
QFilterData
&
data
)
83
{
84
physx
::
PxFilterData
pxData
;
85
pxData
.
word0
=
data
.
group
;
86
pxData
.
word1
=
data
.
ignoreGroups
;
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.
97
Q_ALWAYS_INLINE
bool
isFilteredOut
(
const
QFilterData
&a,
const
QFilterData
&b)
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
108
Q_ALWAYS_INLINE
bool
isFinite
(
const
QVector3D &v)
109
{
110
return
qIsFinite(v.x()) && qIsFinite(v.y()) && qIsFinite(v.z());
111
}
112
113
Q_ALWAYS_INLINE
bool
isFinite
(
const
QQuaternion &q)
114
{
115
return
qIsFinite(q.x()) && qIsFinite(q.y()) && qIsFinite(q.z()) && qIsFinite(q.scalar());
116
}
117
118
Q_ALWAYS_INLINE
bool
isFinite
(
const
physx::PxVec3 &v)
119
{
120
return
qIsFinite(v.x) && qIsFinite(v.y) && qIsFinite(v.z);
121
}
122
123
inline
const
QQuaternion
kMinus90YawRotation
=
QQuaternion
::
fromEulerAngles
(0, -90, 0);
124
}
125
126
#
endif
// QPHYSICSUTILS_P_H
QPhysicsUtils
Definition
qphysicsutils_p.h:33
QPhysicsUtils::fuzzyEquals
Q_ALWAYS_INLINE bool fuzzyEquals(const physx::PxTransform &a, const physx::PxTransform &b)
Definition
qphysicsutils_p.h:67
QPhysicsUtils::kMinus90YawRotation
const QQuaternion kMinus90YawRotation
Definition
qphysicsutils_p.h:123
QPhysicsUtils::isFinite
Q_ALWAYS_INLINE bool isFinite(const QVector3D &v)
Definition
qphysicsutils_p.h:108
QPhysicsUtils::isFilteredOut
Q_ALWAYS_INLINE bool isFilteredOut(const QFilterData &a, const QFilterData &b)
Definition
qphysicsutils_p.h:97
physx
Definition
qphysxactorbody_p.h:22
QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
Definition
qtconfigmacros.h:161
QT_END_NAMESPACE
#define QT_END_NAMESPACE
Definition
qtconfigmacros.h:162
emit
#define emit
Definition
qtmetamacros.h:53
QFilterData
Definition
qfilterdata_p.h:30
qtquick3dphysics
src
quick3dphysics
qphysicsutils_p.h
Generated on
for Qt by
1.18.0