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
qphysicsmaterial.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
#
include
"qphysicsmaterial_p.h"
6
7
#
include
<
foundation
/
PxSimpleTypes
.
h
>
8
9
// This order clamps a NaN value to max instead of leaving it as NaN.
10
static
float
clamp
(
float
value,
float
min,
float
max)
11
{
12
return
std::max(min, std::min(max, value));
13
}
14
15
QT_BEGIN_NAMESPACE
16
17
/*!
18
\qmltype PhysicsMaterial
19
\inqmlmodule QtQuick3D.Physics
20
\since 6.4
21
\brief Defines the physics material of a body.
22
23
The PhysicsMaterial type determines how objects interact when they touch.
24
25
Friction uses the Coulomb friction model, which is based around
26
the concepts of 2 coefficients: the static friction coefficient and the dynamic friction
27
coefficient (sometimes called kinetic friction). Friction resists relative lateral motion of two
28
solid surfaces in contact. These two coefficients define a relationship between the normal force
29
exerted by each surface on the other and the amount of friction force that is applied to resist
30
lateral motion. While most real-world materials have friction coefficients between \c{0} and
31
\c{1}, values above \c{1} are not uncommon. The properties accept any real number greater or
32
equal to \c{0}.
33
34
Restitution determines how objects bounce when they collide.
35
*/
36
37
/*!
38
\qmlproperty real PhysicsMaterial::staticFriction
39
This property defines the amount of friction that is applied between surfaces that are not
40
moving lateral to each-other.
41
42
Default value: \c 0.5
43
44
Range: \c{[0, inf]}
45
*/
46
47
/*!
48
\qmlproperty real PhysicsMaterial::dynamicFriction
49
This property defines the amount of friction applied between surfaces that are moving relative
50
to each-other.
51
52
Default value: \c 0.5
53
54
Range: \c{[0, inf]}
55
*/
56
57
/*!
58
\qmlproperty real PhysicsMaterial::restitution
59
This property defines the coefficient of restitution, or how bouncy the material is.
60
The coefficient of restitution of two
61
colliding objects is a fractional value representing the ratio of speeds after and before an
62
impact, taken along the line of impact. A coefficient of restitution of 1 is said to collide
63
elastically, while a coefficient of restitution < 1 is said to be inelastic.
64
65
Default value: \c 0.5
66
67
Range: \c{[0, 1]}
68
*/
69
70
QPhysicsMaterial::QPhysicsMaterial(QObject *parent) : QObject(parent) { }
71
72
float
QPhysicsMaterial::staticFriction()
const
73
{
74
return
m_staticFriction;
75
}
76
77
void
QPhysicsMaterial::setStaticFriction(
float
staticFriction)
78
{
79
staticFriction = clamp(staticFriction, 0.f, PX_MAX_F32);
80
81
if
(qFuzzyCompare(m_staticFriction, staticFriction))
82
return
;
83
m_staticFriction = staticFriction;
84
emit staticFrictionChanged();
85
}
86
87
float
QPhysicsMaterial::dynamicFriction()
const
88
{
89
return
m_dynamicFriction;
90
}
91
92
void
QPhysicsMaterial::setDynamicFriction(
float
dynamicFriction)
93
{
94
dynamicFriction = clamp(dynamicFriction, 0.f, PX_MAX_F32);
95
96
if
(qFuzzyCompare(m_dynamicFriction, dynamicFriction))
97
return
;
98
m_dynamicFriction = dynamicFriction;
99
emit dynamicFrictionChanged();
100
}
101
102
float
QPhysicsMaterial::restitution()
const
103
{
104
return
m_restitution;
105
}
106
107
void
QPhysicsMaterial::setRestitution(
float
restitution)
108
{
109
restitution = clamp(restitution, 0.f, 1.f);
110
111
if
(qFuzzyCompare(m_restitution, restitution))
112
return
;
113
m_restitution = restitution;
114
emit restitutionChanged();
115
}
116
117
QT_END_NAMESPACE
clamp
static float clamp(float value, float min, float max)
Definition
qphysicsmaterial.cpp:10
qtquick3dphysics
src
quick3dphysics
qphysicsmaterial.cpp
Generated on
for Qt by
1.18.0