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"
47 \instantiates QQuickAgeAffector
48 \inqmlmodule QtQuick.Particles 2
50 \brief For altering particle ages
51 \ingroup qtquick-particles
53 The Age affector allows you to alter where the particle is in its lifecycle. Common uses
54 are to expire particles prematurely, possibly giving them time to animate out.
56 The Age affector is also sometimes known as a 'Kill' affector, because with the default
57 parameters it will immediately expire all particles which it affects.
59 The Age affector only applies to particles which are still alive.
62 \qmlproperty int QtQuick.Particles2::Age::lifeLeft
64 The amount of life to set the particle to have. Affected particles
65 will advance to a point in their life where they will have this many
66 milliseconds left to live.
70 \qmlproperty bool QtQuick.Particles2::Age::advancePosition
72 advancePosition determines whether position, veclocity and acceleration are included in
73 the simulated aging done by the affector. If advancePosition is false,
74 then the position, velocity and acceleration will remain the same and only
75 other attributes (such as opacity) will advance in the simulation to where
76 it would normally be for that point in the particle's life. With advancePosition set to
77 true the position, velocity and acceleration will also advance to where it would
78 normally be by that point in the particle's life, making it advance its position
81 Default value is true.
84 QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) :
85 QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
90 bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt)
94 qreal curT = (qreal)m_system->timeInt/1000.0;
95 qreal ttl = (qreal)m_lifeLeft/1000.0;
96 if (!m_advancePosition && ttl > 0){
98 qreal vx = d->curVX();
99 qreal ax = d->curAX();
101 qreal vy = d->curVY();
102 qreal ay = d->curAY();
103 d->t = curT - (d->lifeSpan - ttl);
104 d->setInstantaneousX(x);
105 d->setInstantaneousVX(vx);
106 d->setInstantaneousAX(ax);
107 d->setInstantaneousY(y);
108 d->setInstantaneousVY(vy);
109 d->setInstantaneousAY(ay);
111 d->t = curT - (d->lifeSpan - ttl);