source: OGRE/trunk/ogrenew/PlugIns/ParticleFX/src/OgreColourFaderAffector2.cpp @ 692

Revision 692, 13.8 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#include "OgreColourFaderAffector2.h"
26#include "OgreParticleSystem.h"
27#include "OgreStringConverter.h"
28#include "OgreParticle.h"
29
30
31namespace Ogre {
32   
33    // init statics
34        // Phase 1
35    ColourFaderAffector2::CmdRedAdjust1 ColourFaderAffector2::msRedCmd1;
36    ColourFaderAffector2::CmdGreenAdjust1 ColourFaderAffector2::msGreenCmd1;
37    ColourFaderAffector2::CmdBlueAdjust1 ColourFaderAffector2::msBlueCmd1;
38    ColourFaderAffector2::CmdAlphaAdjust1 ColourFaderAffector2::msAlphaCmd1;
39
40        // Phase 2
41        ColourFaderAffector2::CmdRedAdjust2 ColourFaderAffector2::msRedCmd2;
42    ColourFaderAffector2::CmdGreenAdjust2 ColourFaderAffector2::msGreenCmd2;
43    ColourFaderAffector2::CmdBlueAdjust2 ColourFaderAffector2::msBlueCmd2;
44    ColourFaderAffector2::CmdAlphaAdjust2 ColourFaderAffector2::msAlphaCmd2;
45
46        ColourFaderAffector2::CmdStateChange ColourFaderAffector2::msStateCmd;
47
48
49    //-----------------------------------------------------------------------
50    ColourFaderAffector2::ColourFaderAffector2(ParticleSystem* psys) : ParticleAffector(psys)
51    {
52        mRedAdj1 = mGreenAdj1 = mBlueAdj1 = mAlphaAdj1 = 0;
53                mRedAdj2 = mGreenAdj2 = mBlueAdj2 = mAlphaAdj2 = 0;
54        mType = "ColourFader2";
55                StateChangeVal = 1;     // Switch when there is 1 second left on the TTL
56
57        // Init parameters
58        if (createParamDictionary("ColourFaderAffector2"))
59        {
60            ParamDictionary* dict = getParamDictionary();
61
62                        // Phase 1
63            dict->addParameter(ParameterDef("red1",
64                "The amount by which to adjust the red component of particles per second.",
65                PT_REAL), &msRedCmd1);
66            dict->addParameter(ParameterDef("green1",
67                "The amount by which to adjust the green component of particles per second.",
68                PT_REAL), &msGreenCmd1);
69            dict->addParameter(ParameterDef("blue1",
70                "The amount by which to adjust the blue component of particles per second.",
71                PT_REAL), &msBlueCmd1);
72            dict->addParameter(ParameterDef("alpha1",
73                "The amount by which to adjust the alpha component of particles per second.",
74                PT_REAL), &msAlphaCmd1);
75
76                        // Phase 2
77            dict->addParameter(ParameterDef("red2",
78                "The amount by which to adjust the red component of particles per second.",
79                PT_REAL), &msRedCmd2);
80            dict->addParameter(ParameterDef("green2",
81                "The amount by which to adjust the green component of particles per second.",
82                PT_REAL), &msGreenCmd2);
83            dict->addParameter(ParameterDef("blue2",
84                "The amount by which to adjust the blue component of particles per second.",
85                PT_REAL), &msBlueCmd2);
86            dict->addParameter(ParameterDef("alpha2",
87                "The amount by which to adjust the alpha component of particles per second.",
88                PT_REAL), &msAlphaCmd2);
89
90                        // State Change Value
91            dict->addParameter(ParameterDef("state_change",
92                "When the particle has this much time to live left, it will switch to state 2.",
93                PT_REAL), &msStateCmd);
94
95        }
96    }
97    //-----------------------------------------------------------------------
98    void ColourFaderAffector2::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
99    {
100        ParticleIterator pi = pSystem->_getIterator();
101        Particle *p;
102        float dr1, dg1, db1, da1;
103                float dr2, dg2, db2, da2;
104
105                // Scale adjustments by time
106                dr1 = mRedAdj1   * timeElapsed;
107                dg1 = mGreenAdj1 * timeElapsed;
108                db1 = mBlueAdj1  * timeElapsed;
109                da1 = mAlphaAdj1 * timeElapsed;
110
111                // Scale adjustments by time
112                dr2 = mRedAdj2   * timeElapsed;
113                dg2 = mGreenAdj2 * timeElapsed;
114                db2 = mBlueAdj2  * timeElapsed;
115                da2 = mAlphaAdj2 * timeElapsed;
116
117        while (!pi.end())
118        {
119                        p = pi.getNext();
120
121                        if( p->timeToLive > StateChangeVal )
122                        {
123                                applyAdjustWithClamp(&p->colour.r, dr1);
124                                applyAdjustWithClamp(&p->colour.g, dg1);
125                                applyAdjustWithClamp(&p->colour.b, db1);
126                                applyAdjustWithClamp(&p->colour.a, da1);
127                        }
128                        else
129                        {
130                                applyAdjustWithClamp(&p->colour.r, dr2);
131                                applyAdjustWithClamp(&p->colour.g, dg2);
132                                applyAdjustWithClamp(&p->colour.b, db2);
133                                applyAdjustWithClamp(&p->colour.a, da2);
134                        }
135        }
136
137    }
138    //-----------------------------------------------------------------------
139    void ColourFaderAffector2::setAdjust1(float red, float green, float blue, float alpha)
140    {
141        mRedAdj1 = red;
142        mGreenAdj1 = green;
143        mBlueAdj1 = blue;
144        mAlphaAdj1 = alpha;
145    }
146        //-----------------------------------------------------------------------
147    void ColourFaderAffector2::setAdjust2(float red, float green, float blue, float alpha)
148    {
149        mRedAdj2 = red;
150        mGreenAdj2 = green;
151        mBlueAdj2 = blue;
152        mAlphaAdj2 = alpha;
153    }
154
155    //-----------------------------------------------------------------------
156    void ColourFaderAffector2::setRedAdjust1(float red)
157    {
158        mRedAdj1 = red;
159    }
160    //-----------------------------------------------------------------------
161    void ColourFaderAffector2::setRedAdjust2(float red)
162    {
163        mRedAdj2 = red;
164    }
165    //-----------------------------------------------------------------------
166    float ColourFaderAffector2::getRedAdjust1(void) const
167    {
168        return mRedAdj1;
169    }
170    //-----------------------------------------------------------------------
171    float ColourFaderAffector2::getRedAdjust2(void) const
172    {
173        return mRedAdj2;
174    }
175    //-----------------------------------------------------------------------
176    void ColourFaderAffector2::setGreenAdjust1(float green)
177    {
178        mGreenAdj1 = green;
179    }
180    //-----------------------------------------------------------------------
181    void ColourFaderAffector2::setGreenAdjust2(float green)
182    {
183        mGreenAdj2 = green;
184    }
185    //-----------------------------------------------------------------------
186    float ColourFaderAffector2::getGreenAdjust1(void) const
187    {
188        return mGreenAdj1;
189    }
190    //-----------------------------------------------------------------------
191    float ColourFaderAffector2::getGreenAdjust2(void) const
192    {
193        return mGreenAdj2;
194    }
195    //-----------------------------------------------------------------------
196    void ColourFaderAffector2::setBlueAdjust1(float blue)
197    {
198        mBlueAdj1 = blue;
199    }
200    //-----------------------------------------------------------------------
201    void ColourFaderAffector2::setBlueAdjust2(float blue)
202    {
203        mBlueAdj2 = blue;
204    }
205    //-----------------------------------------------------------------------
206    float ColourFaderAffector2::getBlueAdjust1(void) const
207    {
208        return mBlueAdj1;
209    }
210    //-----------------------------------------------------------------------
211    float ColourFaderAffector2::getBlueAdjust2(void) const
212    {
213        return mBlueAdj2;
214    }
215    //-----------------------------------------------------------------------
216    void ColourFaderAffector2::setAlphaAdjust1(float alpha)
217    {
218        mAlphaAdj1 = alpha;
219    }
220    //-----------------------------------------------------------------------
221    void ColourFaderAffector2::setAlphaAdjust2(float alpha)
222    {
223        mAlphaAdj2 = alpha;
224    }
225    //-----------------------------------------------------------------------
226    float ColourFaderAffector2::getAlphaAdjust1(void) const
227    {
228        return mAlphaAdj1;
229    }
230    //-----------------------------------------------------------------------
231    float ColourFaderAffector2::getAlphaAdjust2(void) const
232    {
233        return mAlphaAdj2;
234    }
235    //-----------------------------------------------------------------------
236    void ColourFaderAffector2::setStateChange(Real NewValue)
237    {
238        StateChangeVal = NewValue;
239    }
240    //-----------------------------------------------------------------------
241    Real ColourFaderAffector2::getStateChange(void) const
242    {
243        return StateChangeVal;
244    }
245    //-----------------------------------------------------------------------
246    //-----------------------------------------------------------------------
247    //-----------------------------------------------------------------------
248    // Command objects
249    //-----------------------------------------------------------------------
250    //-----------------------------------------------------------------------
251    String ColourFaderAffector2::CmdRedAdjust1::doGet(const void* target) const
252    {
253        return StringConverter::toString(
254            static_cast<const ColourFaderAffector2*>(target)->getRedAdjust1() );
255    }
256    void ColourFaderAffector2::CmdRedAdjust1::doSet(void* target, const String& val)
257    {
258        static_cast<ColourFaderAffector2*>(target)->setRedAdjust1(
259            StringConverter::parseReal(val));
260    }
261    String ColourFaderAffector2::CmdRedAdjust2::doGet(const void* target) const
262    {
263        return StringConverter::toString(
264            static_cast<const ColourFaderAffector2*>(target)->getRedAdjust2() );
265    }
266    void ColourFaderAffector2::CmdRedAdjust2::doSet(void* target, const String& val)
267    {
268        static_cast<ColourFaderAffector2*>(target)->setRedAdjust2(
269            StringConverter::parseReal(val));
270    }
271    //-----------------------------------------------------------------------
272    String ColourFaderAffector2::CmdGreenAdjust1::doGet(const void* target) const
273    {
274        return StringConverter::toString(
275            static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust1() );
276    }
277    void ColourFaderAffector2::CmdGreenAdjust1::doSet(void* target, const String& val)
278    {
279        static_cast<ColourFaderAffector2*>(target)->setGreenAdjust1(
280            StringConverter::parseReal(val));
281    }
282    String ColourFaderAffector2::CmdGreenAdjust2::doGet(const void* target) const
283    {
284        return StringConverter::toString(
285            static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust2() );
286    }
287    void ColourFaderAffector2::CmdGreenAdjust2::doSet(void* target, const String& val)
288    {
289        static_cast<ColourFaderAffector2*>(target)->setGreenAdjust2(
290            StringConverter::parseReal(val));
291    }
292    //-----------------------------------------------------------------------
293    String ColourFaderAffector2::CmdBlueAdjust1::doGet(const void* target) const
294    {
295        return StringConverter::toString(
296            static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust1() );
297    }
298    void ColourFaderAffector2::CmdBlueAdjust1::doSet(void* target, const String& val)
299    {
300        static_cast<ColourFaderAffector2*>(target)->setBlueAdjust1(
301            StringConverter::parseReal(val));
302    }
303    String ColourFaderAffector2::CmdBlueAdjust2::doGet(const void* target) const
304    {
305        return StringConverter::toString(
306            static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust2() );
307    }
308    void ColourFaderAffector2::CmdBlueAdjust2::doSet(void* target, const String& val)
309    {
310        static_cast<ColourFaderAffector2*>(target)->setBlueAdjust2(
311            StringConverter::parseReal(val));
312    }
313    //-----------------------------------------------------------------------
314    String ColourFaderAffector2::CmdAlphaAdjust1::doGet(const void* target) const
315    {
316        return StringConverter::toString(
317            static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust1() );
318    }
319    void ColourFaderAffector2::CmdAlphaAdjust1::doSet(void* target, const String& val)
320    {
321        static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust1(
322            StringConverter::parseReal(val));
323    }
324    String ColourFaderAffector2::CmdAlphaAdjust2::doGet(const void* target) const
325    {
326        return StringConverter::toString(
327            static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust2() );
328    }
329    void ColourFaderAffector2::CmdAlphaAdjust2::doSet(void* target, const String& val)
330    {
331        static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust2(
332            StringConverter::parseReal(val));
333    }
334    //-----------------------------------------------------------------------
335    String ColourFaderAffector2::CmdStateChange::doGet(const void* target) const
336    {
337        return StringConverter::toString(
338            static_cast<const ColourFaderAffector2*>(target)->getStateChange() );
339    }
340    void ColourFaderAffector2::CmdStateChange::doSet(void* target, const String& val)
341    {
342        static_cast<ColourFaderAffector2*>(target)->setStateChange(
343            StringConverter::parseReal(val));
344    }
345}
346
347
348
Note: See TracBrowser for help on using the repository browser.