Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dparticletrailemitter.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
5
7
23
32{
33 return m_follow;
34}
35
37{
38 if (m_follow == follow)
39 return;
40
41 m_follow = follow;
43}
44
54{
55 if (!system())
56 return;
59 burst.amount = count;
60 m_bursts << burst;
61}
62
63// Returns true if there are any dynamic bursts
65{
66 bool dynamicBursts = false;
67 for (auto *burst : std::as_const(m_emitBursts)) {
68 if (qobject_cast<QQuick3DParticleDynamicBurst *>(burst)) {
69 dynamicBursts = true;
70 break;
71 }
72 }
73 return !m_bursts.empty() || dynamicBursts;
74}
75
76// Called to emit set of particles
77void QQuick3DParticleTrailEmitter::emitTrailParticles(const QVector3D &centerPos, int emitAmount, int triggerType)
78{
79 if (!system())
80 return;
81
82 if (!enabled())
83 return;
84
85 const int systemTime = system()->currentTime();
86 for (auto particle : std::as_const(m_system->m_particles)) {
87 if (particle == m_particle) {
88 emitAmount += getEmitAmountFromDynamicBursts(triggerType);
89 emitAmount = std::min(emitAmount, int(particle->maxAmount()));
90 float addTime = ((systemTime - m_prevEmitTime) / 1000.0f) / emitAmount;
91 for (int i = 0; i < emitAmount; i++) {
92 // Distribute evenly between previous and current time, important especially
93 // when time has jumped a lot (like a starttime).
94 float startTime = (m_prevEmitTime / 1000.0f) + addTime * float(i);
96 }
97 // Emit bursts, if any
98 for (auto burst : std::as_const(m_bursts)) {
99 int burstAmount = std::min(burst.amount, int(particle->maxAmount()));
100 float burstTime = float(burst.time / 1000.0f);
101 for (int i = 0; i < burstAmount; i++)
102 emitParticle(particle, burstTime, QMatrix4x4(), QQuaternion(), centerPos);
103 }
104 }
105 }
106
107 m_prevEmitTime = systemTime;
108}
109
111{
112 // After bursts have been emitted, clear the list
113 m_bursts.clear();
114}
115
bool empty() const noexcept
Definition qlist.h:685
void clear()
Definition qlist.h:434
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
The QQuaternion class represents a quaternion consisting of a vector and scalar.
int getEmitAmountFromDynamicBursts(int triggerType=0)
QQuick3DParticleSystem * system
void emitParticle(QQuick3DParticle *particle, float startTime, const QMatrix4x4 &transform, const QQuaternion &parentRotation, const QVector3D &centerPos, int index=-1)
int currentTime() const
Returns the current time of the system (m_time + m_startTime).
Q_INVOKABLE void burst(int count) override
\qmlmethod vector3d TrailEmitter3D::burst(int count)
void emitTrailParticles(const QVector3D &centerPos, int emitAmount, int triggerType)
void setFollow(QQuick3DParticle *follow)
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
qint64 startTime
GLenum GLenum GLsizei count
#define Q_EMIT