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
qquick3dparticlespritesequence.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
6
8
27
29{
30 if (m_parentParticle)
31 m_parentParticle->setSpriteSequence(nullptr);
32}
33
51{
52 return m_frameCount;
53}
54
72{
73 return m_frameIndex;
74}
75
87{
88 return m_interpolate;
89}
90
102{
103 return m_duration;
104}
105
116{
117 return m_durationVariation;
118}
119
131{
132 return m_randomStart;
133}
134
168
170{
171 if (m_frameCount == frameCount)
172 return;
173 m_frameCount = std::max(1, frameCount);
174 markNodesDirty();
176}
177
179{
180 if (m_frameIndex == frameIndex)
181 return;
182 m_frameIndex = std::max(0, frameIndex);
183 markNodesDirty();
185}
186
188{
189 if (m_interpolate == interpolate)
190 return;
191 m_interpolate = interpolate;
192 markNodesDirty();
194}
195
197{
198 if (m_duration == duration)
199 return;
200
201 m_duration = duration;
202 markNodesDirty();
204}
205
207{
208 if (m_durationVariation == durationVariation)
209 return;
210
211 m_durationVariation = durationVariation;
212 markNodesDirty();
214}
215
217{
218 if (m_randomStart == randomStart)
219 return;
220 m_randomStart = randomStart;
221 markNodesDirty();
223}
224
226{
227 if (m_animationDirection == animationDirection)
228 return;
229 m_animationDirection = animationDirection;
230 markNodesDirty();
232}
233
235{
236 m_parentParticle = qobject_cast<QQuick3DParticleSpriteParticle *>(parent());
237 if (!m_parentParticle)
238 qWarning() << "SpriteSequence3D requires parent SpriteParticle3D to function correctly!";
239}
240
241void QQuick3DParticleSpriteSequence::markNodesDirty()
242{
243 if (m_parentParticle)
244 m_parentParticle->markNodesDirty();
245}
246
247// Returns the first frame of the sequence.
248// Return range [0..1) where 0.0 is the first frame and 0.9999 is the last.
249float QQuick3DParticleSpriteSequence::firstFrame(int index, bool singleFrame)
250{
251 float firstFrame = 0.0f;
252 if (m_randomStart) {
253 if (!m_parentParticle || !m_parentParticle->m_system)
254 return firstFrame;
255 auto rand = m_parentParticle->m_system->rand();
256 firstFrame = rand->get(index, QPRand::SpriteAnimationI);
257 } else if (m_frameCount > 1 && m_frameIndex > 0) {
258 int frameIndex = std::min(m_frameIndex, m_frameCount - 1);
259 if (singleFrame)
260 firstFrame = float(frameIndex) / (float(m_frameCount - 1) + 0.0001f);
261 else
262 firstFrame = float(frameIndex) / float(m_frameCount);
263 }
264 return firstFrame;
265}
266
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
void setSpriteSequence(QQuick3DParticleSpriteSequence *spriteSequence)
void setAnimationDirection(QQuick3DParticleSpriteSequence::AnimationDirection animationDirection)
QQuick3DParticleSpriteSequence(QObject *parent=nullptr)
\qmltype SpriteSequence3D \inherits QtObject \inqmlmodule QtQuick3D.Particles3D
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Combined button and popup list for selecting options.
static qreal interpolate(const QPair< QGraphicsAnchorLayoutPrivate::Interval, qreal > &factor, qreal min, qreal minPref, qreal pref, qreal maxPref, qreal max)
#define qWarning
Definition qlogging.h:166
GLuint index
[2]
#define Q_EMIT