1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquickage_p.h" |
5 | #include "qquickparticleemitter_p.h" |
6 | QT_BEGIN_NAMESPACE |
7 | /*! |
8 | \qmltype Age |
9 | \instantiates QQuickAgeAffector |
10 | \inqmlmodule QtQuick.Particles |
11 | \inherits Affector |
12 | \brief For altering particle ages. |
13 | \ingroup qtquick-particles |
14 | |
15 | The Age affector allows you to alter where the particle is in its lifecycle. Common uses |
16 | are to expire particles prematurely, possibly giving them time to animate out. |
17 | |
18 | The Age affector is also sometimes known as a 'Kill' affector, because with the default |
19 | parameters it will immediately expire all particles which it affects. |
20 | |
21 | The Age affector only applies to particles which are still alive. |
22 | */ |
23 | /*! |
24 | \qmlproperty int QtQuick.Particles::Age::lifeLeft |
25 | |
26 | The amount of life to set the particle to have. Affected particles |
27 | will advance to a point in their life where they will have this many |
28 | milliseconds left to live. |
29 | */ |
30 | |
31 | /*! |
32 | \qmlproperty bool QtQuick.Particles::Age::advancePosition |
33 | |
34 | advancePosition determines whether position, veclocity and acceleration are included in |
35 | the simulated aging done by the affector. If advancePosition is false, |
36 | then the position, velocity and acceleration will remain the same and only |
37 | other attributes (such as opacity) will advance in the simulation to where |
38 | it would normally be for that point in the particle's life. With advancePosition set to |
39 | true the position, velocity and acceleration will also advance to where it would |
40 | normally be by that point in the particle's life, making it advance its position |
41 | on screen. |
42 | |
43 | Default value is true. |
44 | */ |
45 | |
46 | QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) : |
47 | QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true) |
48 | { |
49 | } |
50 | |
51 | |
52 | bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt) |
53 | { |
54 | Q_UNUSED(dt); |
55 | if (d->stillAlive(system: m_system)){ |
56 | float curT = m_system->timeInt / 1000.0f; |
57 | float ttl = m_lifeLeft / 1000.0f; |
58 | if (!m_advancePosition && ttl > 0){ |
59 | float x = d->curX(particleSystem: m_system); |
60 | float vx = d->curVX(particleSystem: m_system); |
61 | float ax = d->curAX(); |
62 | float y = d->curY(particleSystem: m_system); |
63 | float vy = d->curVY(particleSystem: m_system); |
64 | float ay = d->curAY(); |
65 | d->t = curT - (d->lifeSpan - ttl); |
66 | d->setInstantaneousX(x, particleSystem: m_system); |
67 | d->setInstantaneousVX(vx, particleSystem: m_system); |
68 | d->setInstantaneousAX(ax, particleSystem: m_system); |
69 | d->setInstantaneousY(y, particleSystem: m_system); |
70 | d->setInstantaneousVY(vy, particleSystem: m_system); |
71 | d->setInstantaneousAY(ay, particleSystem: m_system); |
72 | } else { |
73 | d->t = curT - (d->lifeSpan - ttl); |
74 | } |
75 | return true; |
76 | } |
77 | return false; |
78 | } |
79 | QT_END_NAMESPACE |
80 | |
81 | #include "moc_qquickage_p.cpp" |
82 | |