1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquickage_p.h"
41#include "qquickparticleemitter_p.h"
42QT_BEGIN_NAMESPACE
43/*!
44 \qmltype Age
45 \instantiates QQuickAgeAffector
46 \inqmlmodule QtQuick.Particles
47 \inherits Affector
48 \brief For altering particle ages.
49 \ingroup qtquick-particles
50
51 The Age affector allows you to alter where the particle is in its lifecycle. Common uses
52 are to expire particles prematurely, possibly giving them time to animate out.
53
54 The Age affector is also sometimes known as a 'Kill' affector, because with the default
55 parameters it will immediately expire all particles which it affects.
56
57 The Age affector only applies to particles which are still alive.
58*/
59/*!
60 \qmlproperty int QtQuick.Particles::Age::lifeLeft
61
62 The amount of life to set the particle to have. Affected particles
63 will advance to a point in their life where they will have this many
64 milliseconds left to live.
65*/
66
67/*!
68 \qmlproperty bool QtQuick.Particles::Age::advancePosition
69
70 advancePosition determines whether position, veclocity and acceleration are included in
71 the simulated aging done by the affector. If advancePosition is false,
72 then the position, velocity and acceleration will remain the same and only
73 other attributes (such as opacity) will advance in the simulation to where
74 it would normally be for that point in the particle's life. With advancePosition set to
75 true the position, velocity and acceleration will also advance to where it would
76 normally be by that point in the particle's life, making it advance its position
77 on screen.
78
79 Default value is true.
80*/
81
82QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) :
83 QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
84{
85}
86
87
88bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt)
89{
90 Q_UNUSED(dt);
91 if (d->stillAlive(system: m_system)){
92 float curT = m_system->timeInt / 1000.0f;
93 float ttl = m_lifeLeft / 1000.0f;
94 if (!m_advancePosition && ttl > 0){
95 float x = d->curX(particleSystem: m_system);
96 float vx = d->curVX(particleSystem: m_system);
97 float ax = d->curAX();
98 float y = d->curY(particleSystem: m_system);
99 float vy = d->curVY(particleSystem: m_system);
100 float ay = d->curAY();
101 d->t = curT - (d->lifeSpan - ttl);
102 d->setInstantaneousX(x, particleSystem: m_system);
103 d->setInstantaneousVX(vx, particleSystem: m_system);
104 d->setInstantaneousAX(ax, particleSystem: m_system);
105 d->setInstantaneousY(y, particleSystem: m_system);
106 d->setInstantaneousVY(vy, particleSystem: m_system);
107 d->setInstantaneousAY(ay, particleSystem: m_system);
108 } else {
109 d->t = curT - (d->lifeSpan - ttl);
110 }
111 return true;
112 }
113 return false;
114}
115QT_END_NAMESPACE
116
117#include "moc_qquickage_p.cpp"
118

source code of qtdeclarative/src/particles/qquickage.cpp