Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / examples / particles / affectors / doc / src / affectors.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
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 Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file.  Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: http://www.gnu.org/copyleft/fdl.html.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29     \title QtQuick.Particles Examples - Affectors
30     \example particles/affectors
31     \brief This is a collection of examples using Affectors in the QML particle system.
32     \image qml-affectors-example.png
33
34     This is a collection of small QML examples relating to using Affectors in the particle system.
35     Each example is a small QML file emphasizing a particular element or feature.
36
37     Age demonstrates using an Age affector to prematurely end the lives of particles.
38     \snippet examples/particles/affectors/content/age.qml 0
39
40     As you move the affector around the screen, the particles inside it
41     (which haven't already been affected) jump to a period near the end
42     of their life. This gives them a short period to finish fading out,
43     but changing lifeLeft to 0 (the default), would cause them to reach
44     the end of their life instantly.
45
46     Attractor demonstrates using an Attractor affector to simulate a black hole
47     \snippet examples/particles/affectors/content/attractor.qml 0
48
49     All particles in the scene, including the rocket ship's exhaust and pellets, are pulled
50     towards the black hole. This effect is stronger closer to the black hole, so the
51     asteroids near the top of the screen are barely affected at all, while the ones
52     towards the middle sometimes curve drastically. To complete the effect, an Age
53     affector covers the black hole to destroy particles which come in contact with it.
54
55     Custom Affector manipulates the properties of the particles directly in javascript.
56     One Affector is used to make the leaves rock back and forth as they fall, looking more
57     leaf-like than just spinning in circles:
58     \snippet examples/particles/affectors/content/customaffector.qml 0
59     Another is used to provide a slightly varying friction to the leaves as they 'land',
60     to look more natural:
61     \snippet examples/particles/affectors/content/customaffector.qml 1
62
63     Friction is similar to the falling leaves in the custom affector, except that it uses a
64     flat friction the whole way down instead of custom affectors.
65     \snippet examples/particles/affectors/content/friction.qml 0
66
67     Gravity is a convenience affector for applying a constant acceleration to particles inside it
68     \snippet examples/particles/affectors/content/gravity.qml 0
69
70     GroupGoal sets up two particle groups for flaming and non-flaming balls, and gives you various
71     ways to transition between them.
72     \snippet examples/particles/affectors/content/groupgoal.qml unlit
73     The non-flaming balls have a one in a hundred chance of lighting on their own each second, but they also
74     have a GroupGoal set on the whole group. This affector affects all particles of the unlit group, when colliding
75     with particles in the lit group, and cause them to move to the lighting group.
76     \snippet examples/particles/affectors/content/groupgoal.qml lighting
77     lighting is an intermediate group so that the glow builds up and the transition is less jarring. So it automatically
78     moves into the lit group after 100ms.
79     \snippet examples/particles/affectors/content/groupgoal.qml lit
80     The lit group also has TrailEmitters on it for additional fire and smoke, but does not transition anywhere.
81     There are two more GroupGoal elements that allow particles in the unlit group to transition to the lighting group
82     (and then to the lit group).
83     \snippet examples/particles/affectors/content/groupgoal.qml groupgoal-pilot
84     The first is just an area bound to the location of an image of a pilot flame. When unlit balls pass through the flame,
85     they go straight to lit because the pilot flame is so hot.
86     \snippet examples/particles/affectors/content/groupgoal.qml groupgoal-ma
87     The second is bound to the location of the last pointer interaction, so that touching or clicking on unlit balls (which
88     is hard due to their constant movement) causes them to move to the lighting group.
89
90     Move shows some simple effects you can get by altering trajectory midway.
91     The red particles have an affector that affects their position, jumping them forwards by 120px.
92     \snippet examples/particles/affectors/content/move.qml A
93     The green particles have an affector that affects their velocity, but with some angle variation. By adding some random direction
94     velocity to their existing forwards velocity, they begin to spray off in a cone.
95     \snippet examples/particles/affectors/content/move.qml B
96     The blue particles have an affector that affects their acceleration, and because it sets relative to false this resets the acceleration instead of
97     adding to it. Once the blue particles reach the affector, their horizontal velocity stops increasing as their vertical velocity decreases.
98     \snippet examples/particles/affectors/content/move.qml C
99
100     SpriteGoal has an affector which interacts with the sprite engine of particles, if they are being drawn as sprites by ImageParticle.
101     \snippet examples/particles/affectors/content/spritegoal.qml 0
102     The SpriteGoal follows the image of the rocket ship on screen, and when it interacts with particles drawn by ImageParticle as sprites,
103     it instructs them to move immediately to the "explode" state, which in this case is the animation of the asteroid breaking into many pieces.
104
105     Turbulence has a flame with smoke, and both sets of particles being affected by a Turbulence affector. This gives a faint wind effect.
106     \snippet examples/particles/affectors/content/turbulence.qml 0
107     To make the wind change direction, subsitute a black and white noise image in the noiseSource parameter (it currently uses a default noise source).
108
109     Wander uses a Wander affector to add some horizontal drift to snowflakes as they fall down.
110     \snippet examples/particles/affectors/content/wander.qml 0
111     There are different movements given by applying the Wander to different attributes of the trajectory, so the example makes it easy to play around and see the difference.
112 */
113