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
qquick3dparticlerepeller.cpp
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
6
#
include
"qquick3dparticlerepeller_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\qmltype Repeller3D
12
\inherits Affector3D
13
\inqmlmodule QtQuick3D.Particles3D
14
\brief Particle repeller.
15
\since 6.4
16
17
Repeller affector repels particles from the position it is placed.
18
*/
19
20
QQuick3DParticleRepeller::QQuick3DParticleRepeller(QQuick3DNode *parent)
21
: QQuick3DParticleAffector(parent)
22
{
23
24
}
25
26
/*!
27
\qmlproperty real Repeller3D::radius
28
29
This property holds the radius(or inner radius) of the repeller. Particle is repelled
30
at full strength when it gets inside this radius. The default value is zero.
31
*/
32
float
QQuick3DParticleRepeller::radius()
const
33
{
34
return
m_radius;
35
}
36
37
/*!
38
\qmlproperty real Repeller3D::outerRadius
39
40
This property holds the outer radius of the repeller. The particle is not affected
41
until it gets inside this radius and the repel strength grows smoothly until the particle
42
gets to radius distance from the repeller. The default value is 50.0;
43
*/
44
float
QQuick3DParticleRepeller::outerRadius()
const
45
{
46
return
m_outerRadius;
47
}
48
49
/*!
50
\qmlproperty real Repeller3D::strength
51
52
This property holds the strength of the repeller. The default value is 50.0;
53
*/
54
float
QQuick3DParticleRepeller::strength()
const
55
{
56
return
m_strength;
57
}
58
59
void
QQuick3DParticleRepeller::setRadius(
float
radius)
60
{
61
radius = qMax(0.0f, radius);
62
if
(qFuzzyCompare(radius, m_radius))
return
;
63
64
m_radius = radius;
65
Q_EMIT radiusChanged();
66
}
67
68
void
QQuick3DParticleRepeller::setOuterRadius(
float
radius)
69
{
70
radius = qMax(0.0f, radius);
71
if
(qFuzzyCompare(radius, m_outerRadius))
return
;
72
73
m_outerRadius = radius;
74
Q_EMIT outerRadiusChanged();
75
}
76
77
void
QQuick3DParticleRepeller::setStrength(
float
strength)
78
{
79
strength = qMax(0.0f, strength);
80
if
(qFuzzyCompare(strength, m_strength))
return
;
81
82
m_strength = strength;
83
Q_EMIT strengthChanged();
84
}
85
86
void
QQuick3DParticleRepeller::prepareToAffect()
87
{
88
89
}
90
91
static
float
qt_smoothstep
(
float
edge0,
float
edge1,
float
x)
92
{
93
float
t;
94
t = qBound(0.0f, (x - edge0) / (edge1 - edge0), 1.0f);
95
return
t * t * (3.0f - 2.0f * t);
96
}
97
98
void
QQuick3DParticleRepeller::affectParticle(
const
QQuick3DParticleData &, QQuick3DParticleDataCurrent *d,
float
)
99
{
100
QVector3D pos = position();
101
QVector3D dir = d->position - pos;
102
float
radius = dir.length();
103
float
outerRadius = qMax(m_outerRadius, m_radius);
104
if
(radius > outerRadius || qFuzzyIsNull(radius))
105
return
;
106
107
if
(radius < m_radius)
108
d->position += dir * m_strength / radius;
109
else
110
d->position += dir * m_strength * (1.0f - qt_smoothstep(m_radius, outerRadius, radius)) / radius;
111
}
112
113
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qt_smoothstep
static float qt_smoothstep(float edge0, float edge1, float x)
Definition
qquick3dparticlerepeller.cpp:91
qtquick3d
src
quick3dparticles
qquick3dparticlerepeller.cpp
Generated on
for Qt by
1.18.0