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
qquick3dparticlerandomizer_p.h
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
4
#
ifndef
QQUICK3DPARTICLERANDOMIZER_H
5
#
define
QQUICK3DPARTICLERANDOMIZER_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QRandomGenerator
>
19
#
include
<
QList
>
20
#
include
<
private
/
qglobal_p
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
/*
25
26
Simple helper to get pseudo-random numbers which remain the same per particle & user.
27
Particles don't need strong randomization and the ability to seed can be useful.
28
29
Based on brief testing on my laptop, getting 1.000.000 random numbers:
30
31
1) Using QRandomGenerator::global()->generateDouble()
32
-> ~120ms
33
34
2) Using QPRand::get(), with m_size 4096
35
-> ~8ms
36
37
3) Using QPRand::get(i, j), with m_size 4096
38
-> ~10ms
39
40
4) Using QPRand::get(i, j), with m_size 100000
41
-> ~10ms
42
43
So QPRand seems fast and increasing keys amount doesn't notably affect the performance,
44
just the memory usage. With more particles m_size should be relatively big to make sure
45
particles appear random enough.
46
47
Bounded usage tips:
48
- qrg->bounded(4.0) == QPRand::get() * 4.0
49
- qrg->bounded(4) == int(QPRand::get() * 4)
50
51
*/
52
53
class
QPRand
54
{
55
public
:
56
57
// Add here new enums for diferent "users".
58
// This way e.g. particle can vary little on colors but more on sizes.
59
enum
UserType
{
60
Default
= 0,
61
WanderXPS
,
// PaceStart
62
WanderYPS
,
63
WanderZPS
,
64
WanderXPV
,
// PaceVariation
65
WanderYPV
,
66
WanderZPV
,
67
WanderXAV
,
// AmountVariation
68
WanderYAV
,
69
WanderZAV
,
70
AttractorDurationV
,
71
AttractorPosVX
,
72
AttractorPosVY
,
73
AttractorPosVZ
,
74
Shape1
,
// Shape
75
Shape2
,
76
Shape3
,
77
Shape4
,
78
SpriteAnimationI
,
79
DeterministicSeparator
,
// Note: Enums before this must always be
80
// deterministic based on the particle index
81
LifeSpanV
,
// Emitter
82
ScaleV
,
83
ScaleEV
,
84
RotXV
,
85
RotYV
,
86
RotZV
,
87
RotXVV
,
88
RotYVV
,
89
RotZVV
,
90
ColorRV
,
91
ColorGV
,
92
ColorBV
,
93
ColorAV
,
94
TDirPosXV
,
// TargetDirection
95
TDirPosYV
,
96
TDirPosZV
,
97
TDirMagV
,
98
VDirXV
,
// VectorDirection
99
VDirYV
,
100
VDirZV
,
101
SpriteAnimationV
102
};
103
104
void
init
(quint32 seed,
int
size = 65536) {
105
m_size = size;
106
m_generator.seed(seed);
107
m_randomList.clear();
108
m_randomList.reserve(m_size);
109
for
(
int
i = 0; i < m_size; i++)
110
m_randomList <<
float
(m_generator.generateDouble());
111
}
112
113
void
setDeterministic
(
bool
deterministic) {
114
m_deterministic = deterministic;
115
}
116
117
// Return float 0.0 - 1.0
118
// With the same input values, returns always the same output.
119
inline
float
get
(
int
particleIndex,
UserType
user =
Default
) {
120
if
(!m_deterministic && user >
DeterministicSeparator
)
121
return
get
(
)
;
122
int
i = (particleIndex + user) % m_size;
123
return
m_randomList.at(i);
124
}
125
126
// Return float 0.0 - 1.0 from random list
127
// Note: Not deterministic between runs
128
inline
float
get
() {
129
m_index = (m_index < m_size - 1) ? m_index + 1 : 0;
130
return
m_randomList.at(m_index);
131
}
132
QRandomGenerator
generator
()
const
133
{
134
return
m_generator;
135
}
136
private
:
137
QRandomGenerator m_generator;
138
int
m_size = 0;
139
int
m_index = 0;
140
bool
m_deterministic =
false
;
141
QList<
float
> m_randomList;
142
143
};
144
145
QT_END_NAMESPACE
146
147
#
endif
// QQUICK3DPARTICLERANDOMIZER_H
QPRand
Definition
qquick3dparticlerandomizer_p.h:54
QPRand::get
float get()
Definition
qquick3dparticlerandomizer_p.h:128
QPRand::init
void init(quint32 seed, int size=65536)
Definition
qquick3dparticlerandomizer_p.h:104
QPRand::generator
QRandomGenerator generator() const
Definition
qquick3dparticlerandomizer_p.h:132
QPRand::get
float get(int particleIndex, UserType user=Default)
Definition
qquick3dparticlerandomizer_p.h:119
QPRand::setDeterministic
void setDeterministic(bool deterministic)
Definition
qquick3dparticlerandomizer_p.h:113
QPRand::UserType
UserType
Definition
qquick3dparticlerandomizer_p.h:59
QPRand::Shape4
@ Shape4
Definition
qquick3dparticlerandomizer_p.h:77
QPRand::WanderYPV
@ WanderYPV
Definition
qquick3dparticlerandomizer_p.h:65
QPRand::DeterministicSeparator
@ DeterministicSeparator
Definition
qquick3dparticlerandomizer_p.h:79
QPRand::RotXV
@ RotXV
Definition
qquick3dparticlerandomizer_p.h:84
QPRand::Default
@ Default
Definition
qquick3dparticlerandomizer_p.h:60
QPRand::ScaleEV
@ ScaleEV
Definition
qquick3dparticlerandomizer_p.h:83
QPRand::LifeSpanV
@ LifeSpanV
Definition
qquick3dparticlerandomizer_p.h:81
QPRand::WanderYAV
@ WanderYAV
Definition
qquick3dparticlerandomizer_p.h:68
QPRand::WanderYPS
@ WanderYPS
Definition
qquick3dparticlerandomizer_p.h:62
QPRand::VDirYV
@ VDirYV
Definition
qquick3dparticlerandomizer_p.h:99
QPRand::ColorAV
@ ColorAV
Definition
qquick3dparticlerandomizer_p.h:93
QPRand::VDirZV
@ VDirZV
Definition
qquick3dparticlerandomizer_p.h:100
QPRand::WanderZPS
@ WanderZPS
Definition
qquick3dparticlerandomizer_p.h:63
QPRand::WanderZAV
@ WanderZAV
Definition
qquick3dparticlerandomizer_p.h:69
QPRand::VDirXV
@ VDirXV
Definition
qquick3dparticlerandomizer_p.h:98
QPRand::ColorRV
@ ColorRV
Definition
qquick3dparticlerandomizer_p.h:90
QPRand::AttractorDurationV
@ AttractorDurationV
Definition
qquick3dparticlerandomizer_p.h:70
QPRand::Shape2
@ Shape2
Definition
qquick3dparticlerandomizer_p.h:75
QPRand::AttractorPosVX
@ AttractorPosVX
Definition
qquick3dparticlerandomizer_p.h:71
QPRand::ColorBV
@ ColorBV
Definition
qquick3dparticlerandomizer_p.h:92
QPRand::RotZVV
@ RotZVV
Definition
qquick3dparticlerandomizer_p.h:89
QPRand::TDirPosYV
@ TDirPosYV
Definition
qquick3dparticlerandomizer_p.h:95
QPRand::TDirPosZV
@ TDirPosZV
Definition
qquick3dparticlerandomizer_p.h:96
QPRand::SpriteAnimationI
@ SpriteAnimationI
Definition
qquick3dparticlerandomizer_p.h:78
QPRand::ColorGV
@ ColorGV
Definition
qquick3dparticlerandomizer_p.h:91
QPRand::Shape1
@ Shape1
Definition
qquick3dparticlerandomizer_p.h:74
QPRand::WanderXAV
@ WanderXAV
Definition
qquick3dparticlerandomizer_p.h:67
QPRand::WanderXPS
@ WanderXPS
Definition
qquick3dparticlerandomizer_p.h:61
QPRand::RotYV
@ RotYV
Definition
qquick3dparticlerandomizer_p.h:85
QPRand::RotZV
@ RotZV
Definition
qquick3dparticlerandomizer_p.h:86
QPRand::AttractorPosVY
@ AttractorPosVY
Definition
qquick3dparticlerandomizer_p.h:72
QPRand::TDirMagV
@ TDirMagV
Definition
qquick3dparticlerandomizer_p.h:97
QPRand::RotYVV
@ RotYVV
Definition
qquick3dparticlerandomizer_p.h:88
QPRand::ScaleV
@ ScaleV
Definition
qquick3dparticlerandomizer_p.h:82
QPRand::RotXVV
@ RotXVV
Definition
qquick3dparticlerandomizer_p.h:87
QPRand::AttractorPosVZ
@ AttractorPosVZ
Definition
qquick3dparticlerandomizer_p.h:73
QPRand::Shape3
@ Shape3
Definition
qquick3dparticlerandomizer_p.h:76
QPRand::SpriteAnimationV
@ SpriteAnimationV
Definition
qquick3dparticlerandomizer_p.h:101
QPRand::WanderXPV
@ WanderXPV
Definition
qquick3dparticlerandomizer_p.h:64
QPRand::WanderZPV
@ WanderZPV
Definition
qquick3dparticlerandomizer_p.h:66
QPRand::TDirPosXV
@ TDirPosXV
Definition
qquick3dparticlerandomizer_p.h:94
QQuick3DParticleAttractor
Definition
qquick3dparticleattractor_p.h:24
QPlatformGraphicsBufferHelper
\inmodule QtGui
MIN_DURATION
QT_BEGIN_NAMESPACE const float MIN_DURATION
\qmltype Attractor3D \inherits Affector3D \inqmlmodule QtQuick3D.Particles3D
Definition
qquick3dparticleattractor.cpp:25
qtquick3d
src
quick3dparticles
qquick3dparticlerandomizer_p.h
Generated on
for Qt by
1.14.0