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
qquick3dparticlevectordirection.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
"qquick3dparticlevectordirection_p.h"
7
#
include
"qquick3dparticlerandomizer_p.h"
8
#
include
"qquick3dparticlesystem_p.h"
9
10
QT_BEGIN_NAMESPACE
11
12
/*!
13
\qmltype VectorDirection3D
14
\inherits Direction3D
15
\inqmlmodule QtQuick3D.Particles3D
16
\brief For specifying a direction towards the target direction.
17
\since 6.2
18
19
This element sets emitted particle velocity towards the target direction vector.
20
The length of the direction vector is used as the velocity magnitude.
21
22
For example, to emit particles towards some random direction within
23
x: 50..150, y: -20..20, z: 0:
24
25
\qml
26
ParticleEmitter3D {
27
...
28
velocity: VectorDirection3D {
29
direction: Qt.vector3d(100, 0, 0)
30
directionVariation: Qt.vector3d(50, 20, 0)
31
}
32
}
33
\endqml
34
35
*/
36
37
QQuick3DParticleVectorDirection::QQuick3DParticleVectorDirection(QObject *parent)
38
: QQuick3DParticleDirection(parent)
39
{
40
}
41
42
/*!
43
\qmlproperty vector3d VectorDirection3D::direction
44
45
This property defines the direction for particles target.
46
47
The default value is \c (0, 100, 0) (upwards on the y-axis).
48
49
\sa directionVariation
50
*/
51
QVector3D QQuick3DParticleVectorDirection::direction()
const
52
{
53
return
m_direction;
54
}
55
56
/*!
57
\qmlproperty vector3d VectorDirection3D::directionVariation
58
59
This property defines the direction variation for particles target.
60
61
The default value is \c (0, 0, 0) (no variation).
62
63
\sa direction
64
*/
65
QVector3D QQuick3DParticleVectorDirection::directionVariation()
const
66
{
67
return
m_directionVariation;
68
}
69
70
/*!
71
\qmlproperty bool VectorDirection3D::normalized
72
73
This property defines if the direction should be normalized after applying the variation.
74
When this is false, variation affects the magnitude of the particles velocity.
75
When set to true, variation affects the direction, but the magnitude is determined
76
by the original direction length.
77
78
The default value is \c false.
79
*/
80
bool
QQuick3DParticleVectorDirection::normalized()
const
81
{
82
return
m_normalized;
83
}
84
85
void
QQuick3DParticleVectorDirection::setDirection(
const
QVector3D &direction)
86
{
87
if
(m_direction == direction)
88
return
;
89
90
m_direction = direction;
91
Q_EMIT directionChanged();
92
}
93
94
void
QQuick3DParticleVectorDirection::setDirectionVariation(
const
QVector3D &directionVariation)
95
{
96
if
(m_directionVariation == directionVariation)
97
return
;
98
99
m_directionVariation = directionVariation;
100
Q_EMIT directionVariationChanged();
101
}
102
103
void
QQuick3DParticleVectorDirection::setNormalized(
bool
normalized)
104
{
105
if
(m_normalized == normalized)
106
return
;
107
108
m_normalized = normalized;
109
Q_EMIT normalizedChanged();
110
}
111
112
QVector3D QQuick3DParticleVectorDirection::sample(
const
QQuick3DParticleData &d)
113
{
114
QVector3D ret;
115
if
(!m_system)
116
return
ret;
117
auto
rand = m_system->rand();
118
ret.setX(m_direction.x() - m_directionVariation.x() + rand->get(d.index, QPRand::VDirXV) * m_directionVariation.x() * 2.0f);
119
ret.setY(m_direction.y() - m_directionVariation.y() + rand->get(d.index, QPRand::VDirYV) * m_directionVariation.y() * 2.0f);
120
ret.setZ(m_direction.z() - m_directionVariation.z() + rand->get(d.index, QPRand::VDirZV) * m_directionVariation.z() * 2.0f);
121
if
(m_normalized)
122
ret = m_direction.length() * ret.normalized();
123
return
ret;
124
}
125
126
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
quick3dparticles
qquick3dparticlevectordirection.cpp
Generated on
for Qt by
1.18.0