Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/PlugIns/ParticleFX/src/OgreColourFaderAffector2.cpp @ 6

Last change on this file since 6 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 13.7 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4        (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreColourFaderAffector2.h"
30#include "OgreParticleSystem.h"
31#include "OgreStringConverter.h"
32#include "OgreParticle.h"
33
34
35namespace Ogre {
36   
37    // init statics
38        // Phase 1
39    ColourFaderAffector2::CmdRedAdjust1 ColourFaderAffector2::msRedCmd1;
40    ColourFaderAffector2::CmdGreenAdjust1 ColourFaderAffector2::msGreenCmd1;
41    ColourFaderAffector2::CmdBlueAdjust1 ColourFaderAffector2::msBlueCmd1;
42    ColourFaderAffector2::CmdAlphaAdjust1 ColourFaderAffector2::msAlphaCmd1;
43
44        // Phase 2
45        ColourFaderAffector2::CmdRedAdjust2 ColourFaderAffector2::msRedCmd2;
46    ColourFaderAffector2::CmdGreenAdjust2 ColourFaderAffector2::msGreenCmd2;
47    ColourFaderAffector2::CmdBlueAdjust2 ColourFaderAffector2::msBlueCmd2;
48    ColourFaderAffector2::CmdAlphaAdjust2 ColourFaderAffector2::msAlphaCmd2;
49
50        ColourFaderAffector2::CmdStateChange ColourFaderAffector2::msStateCmd;
51
52
53    //-----------------------------------------------------------------------
54    ColourFaderAffector2::ColourFaderAffector2(ParticleSystem* psys) : ParticleAffector(psys)
55    {
56        mRedAdj1 = mGreenAdj1 = mBlueAdj1 = mAlphaAdj1 = 0;
57                mRedAdj2 = mGreenAdj2 = mBlueAdj2 = mAlphaAdj2 = 0;
58        mType = "ColourFader2";
59                StateChangeVal = 1;     // Switch when there is 1 second left on the TTL
60
61        // Init parameters
62        if (createParamDictionary("ColourFaderAffector2"))
63        {
64            ParamDictionary* dict = getParamDictionary();
65
66                        // Phase 1
67            dict->addParameter(ParameterDef("red1", 
68                "The amount by which to adjust the red component of particles per second.",
69                PT_REAL), &msRedCmd1);
70            dict->addParameter(ParameterDef("green1", 
71                "The amount by which to adjust the green component of particles per second.",
72                PT_REAL), &msGreenCmd1);
73            dict->addParameter(ParameterDef("blue1", 
74                "The amount by which to adjust the blue component of particles per second.",
75                PT_REAL), &msBlueCmd1);
76            dict->addParameter(ParameterDef("alpha1", 
77                "The amount by which to adjust the alpha component of particles per second.",
78                PT_REAL), &msAlphaCmd1);
79
80                        // Phase 2
81            dict->addParameter(ParameterDef("red2", 
82                "The amount by which to adjust the red component of particles per second.",
83                PT_REAL), &msRedCmd2);
84            dict->addParameter(ParameterDef("green2", 
85                "The amount by which to adjust the green component of particles per second.",
86                PT_REAL), &msGreenCmd2);
87            dict->addParameter(ParameterDef("blue2", 
88                "The amount by which to adjust the blue component of particles per second.",
89                PT_REAL), &msBlueCmd2);
90            dict->addParameter(ParameterDef("alpha2", 
91                "The amount by which to adjust the alpha component of particles per second.",
92                PT_REAL), &msAlphaCmd2);
93
94                        // State Change Value
95            dict->addParameter(ParameterDef("state_change", 
96                "When the particle has this much time to live left, it will switch to state 2.",
97                PT_REAL), &msStateCmd);
98
99        }
100    }
101    //-----------------------------------------------------------------------
102    void ColourFaderAffector2::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
103    {
104        ParticleIterator pi = pSystem->_getIterator();
105        Particle *p;
106        float dr1, dg1, db1, da1;
107                float dr2, dg2, db2, da2;
108
109                // Scale adjustments by time
110                dr1 = mRedAdj1   * timeElapsed;
111                dg1 = mGreenAdj1 * timeElapsed;
112                db1 = mBlueAdj1  * timeElapsed;
113                da1 = mAlphaAdj1 * timeElapsed;
114
115                // Scale adjustments by time
116                dr2 = mRedAdj2   * timeElapsed;
117                dg2 = mGreenAdj2 * timeElapsed;
118                db2 = mBlueAdj2  * timeElapsed;
119                da2 = mAlphaAdj2 * timeElapsed;
120
121        while (!pi.end())
122        {
123                        p = pi.getNext();
124
125                        if( p->timeToLive > StateChangeVal )
126                        {
127                                applyAdjustWithClamp(&p->colour.r, dr1);
128                                applyAdjustWithClamp(&p->colour.g, dg1);
129                                applyAdjustWithClamp(&p->colour.b, db1);
130                                applyAdjustWithClamp(&p->colour.a, da1);
131                        }
132                        else
133                        {
134                                applyAdjustWithClamp(&p->colour.r, dr2);
135                                applyAdjustWithClamp(&p->colour.g, dg2);
136                                applyAdjustWithClamp(&p->colour.b, db2);
137                                applyAdjustWithClamp(&p->colour.a, da2);
138                        }
139        }
140
141    }
142    //-----------------------------------------------------------------------
143    void ColourFaderAffector2::setAdjust1(float red, float green, float blue, float alpha)
144    {
145        mRedAdj1 = red;
146        mGreenAdj1 = green;
147        mBlueAdj1 = blue;
148        mAlphaAdj1 = alpha;
149    }
150        //-----------------------------------------------------------------------
151    void ColourFaderAffector2::setAdjust2(float red, float green, float blue, float alpha)
152    {
153        mRedAdj2 = red;
154        mGreenAdj2 = green;
155        mBlueAdj2 = blue;
156        mAlphaAdj2 = alpha;
157    }
158
159    //-----------------------------------------------------------------------
160    void ColourFaderAffector2::setRedAdjust1(float red)
161    {
162        mRedAdj1 = red;
163    }
164    //-----------------------------------------------------------------------
165    void ColourFaderAffector2::setRedAdjust2(float red)
166    {
167        mRedAdj2 = red;
168    }
169    //-----------------------------------------------------------------------
170    float ColourFaderAffector2::getRedAdjust1(void) const
171    {
172        return mRedAdj1;
173    }
174    //-----------------------------------------------------------------------
175    float ColourFaderAffector2::getRedAdjust2(void) const
176    {
177        return mRedAdj2;
178    }
179    //-----------------------------------------------------------------------
180    void ColourFaderAffector2::setGreenAdjust1(float green)
181    {
182        mGreenAdj1 = green;
183    }
184    //-----------------------------------------------------------------------
185    void ColourFaderAffector2::setGreenAdjust2(float green)
186    {
187        mGreenAdj2 = green;
188    }
189    //-----------------------------------------------------------------------
190    float ColourFaderAffector2::getGreenAdjust1(void) const
191    {
192        return mGreenAdj1;
193    }
194    //-----------------------------------------------------------------------
195    float ColourFaderAffector2::getGreenAdjust2(void) const
196    {
197        return mGreenAdj2;
198    }
199    //-----------------------------------------------------------------------
200    void ColourFaderAffector2::setBlueAdjust1(float blue)
201    {
202        mBlueAdj1 = blue;
203    }
204    //-----------------------------------------------------------------------
205    void ColourFaderAffector2::setBlueAdjust2(float blue)
206    {
207        mBlueAdj2 = blue;
208    }
209    //-----------------------------------------------------------------------
210    float ColourFaderAffector2::getBlueAdjust1(void) const
211    {
212        return mBlueAdj1;
213    }
214    //-----------------------------------------------------------------------
215    float ColourFaderAffector2::getBlueAdjust2(void) const
216    {
217        return mBlueAdj2;
218    }
219    //-----------------------------------------------------------------------
220    void ColourFaderAffector2::setAlphaAdjust1(float alpha)
221    {
222        mAlphaAdj1 = alpha;
223    }
224    //-----------------------------------------------------------------------
225    void ColourFaderAffector2::setAlphaAdjust2(float alpha)
226    {
227        mAlphaAdj2 = alpha;
228    }
229    //-----------------------------------------------------------------------
230    float ColourFaderAffector2::getAlphaAdjust1(void) const
231    {
232        return mAlphaAdj1;
233    }
234    //-----------------------------------------------------------------------
235    float ColourFaderAffector2::getAlphaAdjust2(void) const
236    {
237        return mAlphaAdj2;
238    }
239    //-----------------------------------------------------------------------
240    void ColourFaderAffector2::setStateChange(Real NewValue)
241    {
242        StateChangeVal = NewValue;
243    }
244    //-----------------------------------------------------------------------
245    Real ColourFaderAffector2::getStateChange(void) const
246    {
247        return StateChangeVal;
248    }
249    //-----------------------------------------------------------------------
250    //-----------------------------------------------------------------------
251    //-----------------------------------------------------------------------
252    // Command objects
253    //-----------------------------------------------------------------------
254    //-----------------------------------------------------------------------
255    String ColourFaderAffector2::CmdRedAdjust1::doGet(const void* target) const
256    {
257        return StringConverter::toString(
258            static_cast<const ColourFaderAffector2*>(target)->getRedAdjust1() );
259    }
260    void ColourFaderAffector2::CmdRedAdjust1::doSet(void* target, const String& val)
261    {
262        static_cast<ColourFaderAffector2*>(target)->setRedAdjust1(
263            StringConverter::parseReal(val));
264    }
265    String ColourFaderAffector2::CmdRedAdjust2::doGet(const void* target) const
266    {
267        return StringConverter::toString(
268            static_cast<const ColourFaderAffector2*>(target)->getRedAdjust2() );
269    }
270    void ColourFaderAffector2::CmdRedAdjust2::doSet(void* target, const String& val)
271    {
272        static_cast<ColourFaderAffector2*>(target)->setRedAdjust2(
273            StringConverter::parseReal(val));
274    }
275    //-----------------------------------------------------------------------
276    String ColourFaderAffector2::CmdGreenAdjust1::doGet(const void* target) const
277    {
278        return StringConverter::toString(
279            static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust1() );
280    }
281    void ColourFaderAffector2::CmdGreenAdjust1::doSet(void* target, const String& val)
282    {
283        static_cast<ColourFaderAffector2*>(target)->setGreenAdjust1(
284            StringConverter::parseReal(val));
285    }
286    String ColourFaderAffector2::CmdGreenAdjust2::doGet(const void* target) const
287    {
288        return StringConverter::toString(
289            static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust2() );
290    }
291    void ColourFaderAffector2::CmdGreenAdjust2::doSet(void* target, const String& val)
292    {
293        static_cast<ColourFaderAffector2*>(target)->setGreenAdjust2(
294            StringConverter::parseReal(val));
295    }
296    //-----------------------------------------------------------------------
297    String ColourFaderAffector2::CmdBlueAdjust1::doGet(const void* target) const
298    {
299        return StringConverter::toString(
300            static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust1() );
301    }
302    void ColourFaderAffector2::CmdBlueAdjust1::doSet(void* target, const String& val)
303    {
304        static_cast<ColourFaderAffector2*>(target)->setBlueAdjust1(
305            StringConverter::parseReal(val));
306    }
307    String ColourFaderAffector2::CmdBlueAdjust2::doGet(const void* target) const
308    {
309        return StringConverter::toString(
310            static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust2() );
311    }
312    void ColourFaderAffector2::CmdBlueAdjust2::doSet(void* target, const String& val)
313    {
314        static_cast<ColourFaderAffector2*>(target)->setBlueAdjust2(
315            StringConverter::parseReal(val));
316    }
317    //-----------------------------------------------------------------------
318    String ColourFaderAffector2::CmdAlphaAdjust1::doGet(const void* target) const
319    {
320        return StringConverter::toString(
321            static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust1() );
322    }
323    void ColourFaderAffector2::CmdAlphaAdjust1::doSet(void* target, const String& val)
324    {
325        static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust1(
326            StringConverter::parseReal(val));
327    }
328    String ColourFaderAffector2::CmdAlphaAdjust2::doGet(const void* target) const
329    {
330        return StringConverter::toString(
331            static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust2() );
332    }
333    void ColourFaderAffector2::CmdAlphaAdjust2::doSet(void* target, const String& val)
334    {
335        static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust2(
336            StringConverter::parseReal(val));
337    }
338    //-----------------------------------------------------------------------
339    String ColourFaderAffector2::CmdStateChange::doGet(const void* target) const
340    {
341        return StringConverter::toString(
342            static_cast<const ColourFaderAffector2*>(target)->getStateChange() );
343    }
344    void ColourFaderAffector2::CmdStateChange::doSet(void* target, const String& val)
345    {
346        static_cast<ColourFaderAffector2*>(target)->setStateChange(
347            StringConverter::parseReal(val));
348    }
349}
350
351
352
Note: See TracBrowser for help on using the repository browser.