1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQuick module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickage_p.h"
43 #include "qquickparticleemitter_p.h"
46 \qmlclass Age QQuickAgeAffector
47 \inqmlmodule QtQuick.Particles 2
49 \brief For altering particle ages
50 \ingroup qtquick-particles
52 The Age affector allows you to alter where the particle is in its lifecycle. Common uses
53 are to expire particles prematurely, possibly giving them time to animate out.
55 The Age affector is also sometimes known as a 'Kill' affector, because with the default
56 parameters it will immediately expire all particles which it affects.
58 The Age affector only applies to particles which are still alive.
61 \qmlproperty int QtQuick.Particles2::Age::lifeLeft
63 The amount of life to set the particle to have. Affected particles
64 will advance to a point in their life where they will have this many
65 milliseconds left to live.
69 \qmlproperty bool QtQuick.Particles2::Age::advancePosition
71 advancePosition determines whether position, veclocity and acceleration are included in
72 the simulated aging done by the affector. If advancePosition is false,
73 then the position, velocity and acceleration will remain the same and only
74 other attributes (such as opacity) will advance in the simulation to where
75 it would normally be for that point in the particle's life. With advancePosition set to
76 true the position, velocity and acceleration will also advance to where it would
77 normally be by that point in the particle's life, making it advance its position
80 Default value is true.
83 QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) :
84 QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
89 bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt)
93 qreal curT = (qreal)m_system->timeInt/1000.0;
94 qreal ttl = (qreal)m_lifeLeft/1000.0;
95 if (!m_advancePosition && ttl > 0){
97 qreal vx = d->curVX();
98 qreal ax = d->curAX();
100 qreal vy = d->curVY();
101 qreal ay = d->curAY();
102 d->t = curT - (d->lifeSpan - ttl);
103 d->setInstantaneousX(x);
104 d->setInstantaneousVX(vx);
105 d->setInstantaneousAX(ax);
106 d->setInstantaneousY(y);
107 d->setInstantaneousVY(vy);
108 d->setInstantaneousAY(ay);
110 d->t = curT - (d->lifeSpan - ttl);