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
qquick3dparticlegravity.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
6
#
include
"qquick3dparticlegravity_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\qmltype Gravity3D
12
\inherits Affector3D
13
\inqmlmodule QtQuick3D.Particles3D
14
\brief Accelerates particles to a vector of the specified magnitude in the specified direction.
15
\since 6.2
16
17
This element models the gravity of a massive object whose center of gravity is far away (and thus the
18
gravitational pull is effectively constant across the scene). To model the gravity of an object near
19
or inside the scene, use \l Attractor3D.
20
*/
21
22
QQuick3DParticleGravity::QQuick3DParticleGravity(QQuick3DNode *parent)
23
: QQuick3DParticleAffector(parent)
24
{
25
}
26
27
/*!
28
\qmlproperty real Gravity3D::magnitude
29
30
This property defines the magnitude in position change per second. Negative magnitude
31
accelerates the opposite way from the \l {Gravity3D::direction}{direction}.
32
33
The default value is \c 100.0.
34
*/
35
float
QQuick3DParticleGravity::magnitude()
const
36
{
37
return
m_magnitude;
38
}
39
40
void
QQuick3DParticleGravity::setMagnitude(
float
magnitude)
41
{
42
if
(qFuzzyCompare(m_magnitude, magnitude))
43
return
;
44
45
m_magnitude = magnitude;
46
Q_EMIT magnitudeChanged();
47
Q_EMIT update();
48
}
49
50
/*!
51
\qmlproperty vector3d Gravity3D::direction
52
53
This property defines the direction the gravity will affect toward. Values will be
54
automatically normalized to a unit vector.
55
56
The default value is \c (0.0, -1.0, 0.0) (downwards).
57
*/
58
const
QVector3D &QQuick3DParticleGravity::direction()
const
59
{
60
return
m_direction;
61
}
62
63
void
QQuick3DParticleGravity::setDirection(
const
QVector3D &direction)
64
{
65
if
(m_direction == direction)
66
return
;
67
68
m_direction = direction;
69
m_directionNormalized = m_direction.normalized();
70
Q_EMIT directionChanged();
71
Q_EMIT update();
72
}
73
74
void
QQuick3DParticleGravity::affectParticle(
const
QQuick3DParticleData &sd, QQuick3DParticleDataCurrent *d,
float
time)
75
{
76
Q_UNUSED(sd);
77
float
velocity = 0.5f * m_magnitude * (time * time);
78
d->position += velocity * m_directionNormalized;
79
}
80
81
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
qtquick3d
src
quick3dparticles
qquick3dparticlegravity.cpp
Generated on
for Qt by
1.16.1