Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreColourFaderAffector2.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreColourFaderAffector2.h"
    00026 #include "OgreParticleSystem.h"
    00027 #include "OgreStringConverter.h"
    00028 #include "OgreParticle.h"
    00029
    00030
    00031 namespace Ogre {
    00032
    00033     // init statics
    00034     // Phase 1
    00035     ColourFaderAffector2::CmdRedAdjust1 ColourFaderAffector2::msRedCmd1;
    00036     ColourFaderAffector2::CmdGreenAdjust1 ColourFaderAffector2::msGreenCmd1;
    00037     ColourFaderAffector2::CmdBlueAdjust1 ColourFaderAffector2::msBlueCmd1;
    00038     ColourFaderAffector2::CmdAlphaAdjust1 ColourFaderAffector2::msAlphaCmd1;
    00039
    00040     // Phase 2
    00041     ColourFaderAffector2::CmdRedAdjust2 ColourFaderAffector2::msRedCmd2;
    00042     ColourFaderAffector2::CmdGreenAdjust2 ColourFaderAffector2::msGreenCmd2;
    00043     ColourFaderAffector2::CmdBlueAdjust2 ColourFaderAffector2::msBlueCmd2;
    00044     ColourFaderAffector2::CmdAlphaAdjust2 ColourFaderAffector2::msAlphaCmd2;
    00045
    00046     ColourFaderAffector2::CmdStateChange ColourFaderAffector2::msStateCmd;
    00047
    00048
    00049     //-----------------------------------------------------------------------
    00050     ColourFaderAffector2::ColourFaderAffector2()
    00051     {
    00052         mRedAdj1 = mGreenAdj1 = mBlueAdj1 = mAlphaAdj1 = 0;
    00053         mRedAdj2 = mGreenAdj2 = mBlueAdj2 = mAlphaAdj2 = 0;
    00054         mType = "ColourFader2";
    00055         StateChangeVal = 1; // Switch when there is 1 second left on the TTL
    00056
    00057         // Init parameters
    00058         if (createParamDictionary("ColourFaderAffector2"))
    00059         {
    00060             ParamDictionary* dict = getParamDictionary();
    00061
    00062             // Phase 1
    00063             dict->addParameter(ParameterDef("red1",
    00064                 "The amount by which to adjust the red component of particles per second.",
    00065                 PT_REAL), &msRedCmd1);
    00066             dict->addParameter(ParameterDef("green1",
    00067                 "The amount by which to adjust the green component of particles per second.",
    00068                 PT_REAL), &msGreenCmd1);
    00069             dict->addParameter(ParameterDef("blue1",
    00070                 "The amount by which to adjust the blue component of particles per second.",
    00071                 PT_REAL), &msBlueCmd1);
    00072             dict->addParameter(ParameterDef("alpha1",
    00073                 "The amount by which to adjust the alpha component of particles per second.",
    00074                 PT_REAL), &msAlphaCmd1);
    00075
    00076             // Phase 2
    00077             dict->addParameter(ParameterDef("red2",
    00078                 "The amount by which to adjust the red component of particles per second.",
    00079                 PT_REAL), &msRedCmd2);
    00080             dict->addParameter(ParameterDef("green2",
    00081                 "The amount by which to adjust the green component of particles per second.",
    00082                 PT_REAL), &msGreenCmd2);
    00083             dict->addParameter(ParameterDef("blue2",
    00084                 "The amount by which to adjust the blue component of particles per second.",
    00085                 PT_REAL), &msBlueCmd2);
    00086             dict->addParameter(ParameterDef("alpha2",
    00087                 "The amount by which to adjust the alpha component of particles per second.",
    00088                 PT_REAL), &msAlphaCmd2);
    00089
    00090             // State Change Value
    00091             dict->addParameter(ParameterDef("state_change",
    00092                 "When the particle has this much time to live left, it will switch to state 2.",
    00093                 PT_REAL), &msStateCmd);
    00094
    00095         }
    00096     }
    00097     //-----------------------------------------------------------------------
    00098     void ColourFaderAffector2::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
    00099     {
    00100         ParticleIterator pi = pSystem->_getIterator();
    00101         Particle *p;
    00102         Real dr1, dg1, db1, da1;
    00103         Real dr2, dg2, db2, da2;
    00104
    00105         // Scale adjustments by time
    00106         dr1 = mRedAdj1   * timeElapsed;
    00107         dg1 = mGreenAdj1 * timeElapsed;
    00108         db1 = mBlueAdj1  * timeElapsed;
    00109         da1 = mAlphaAdj1 * timeElapsed;
    00110
    00111         // Scale adjustments by time
    00112         dr2 = mRedAdj2   * timeElapsed;
    00113         dg2 = mGreenAdj2 * timeElapsed;
    00114         db2 = mBlueAdj2  * timeElapsed;
    00115         da2 = mAlphaAdj2 * timeElapsed;
    00116
    00117         while (!pi.end())
    00118         {
    00119             p = pi.getNext();
    00120
    00121             if( p->mTimeToLive > StateChangeVal )
    00122             {
    00123                 applyAdjustWithClamp(&p->mColour.r, dr1);
    00124                 applyAdjustWithClamp(&p->mColour.g, dg1);
    00125                 applyAdjustWithClamp(&p->mColour.b, db1);
    00126                 applyAdjustWithClamp(&p->mColour.a, da1);
    00127             }
    00128             else
    00129             {
    00130                 applyAdjustWithClamp(&p->mColour.r, dr2);
    00131                 applyAdjustWithClamp(&p->mColour.g, dg2);
    00132                 applyAdjustWithClamp(&p->mColour.b, db2);
    00133                 applyAdjustWithClamp(&p->mColour.a, da2);
    00134             }
    00135         }
    00136
    00137     }
    00138     //-----------------------------------------------------------------------
    00139     void ColourFaderAffector2::setAdjust1(Real red, Real green, Real blue, Real alpha)
    00140     {
    00141         mRedAdj1 = red;
    00142         mGreenAdj1 = green;
    00143         mBlueAdj1 = blue;
    00144         mAlphaAdj1 = alpha;
    00145     }
    00146     //-----------------------------------------------------------------------
    00147     void ColourFaderAffector2::setAdjust2(Real red, Real green, Real blue, Real alpha)
    00148     {
    00149         mRedAdj2 = red;
    00150         mGreenAdj2 = green;
    00151         mBlueAdj2 = blue;
    00152         mAlphaAdj2 = alpha;
    00153     }
    00154
    00155     //-----------------------------------------------------------------------
    00156     void ColourFaderAffector2::setRedAdjust1(Real red)
    00157     {
    00158         mRedAdj1 = red;
    00159     }
    00160     //-----------------------------------------------------------------------
    00161     void ColourFaderAffector2::setRedAdjust2(Real red)
    00162     {
    00163         mRedAdj2 = red;
    00164     }
    00165     //-----------------------------------------------------------------------
    00166     Real ColourFaderAffector2::getRedAdjust1(void) const
    00167     {
    00168         return mRedAdj1;
    00169     }
    00170     //-----------------------------------------------------------------------
    00171     Real ColourFaderAffector2::getRedAdjust2(void) const
    00172     {
    00173         return mRedAdj2;
    00174     }
    00175     //-----------------------------------------------------------------------
    00176     void ColourFaderAffector2::setGreenAdjust1(Real green)
    00177     {
    00178         mGreenAdj1 = green;
    00179     }
    00180     //-----------------------------------------------------------------------
    00181     void ColourFaderAffector2::setGreenAdjust2(Real green)
    00182     {
    00183         mGreenAdj2 = green;
    00184     }
    00185     //-----------------------------------------------------------------------
    00186     Real ColourFaderAffector2::getGreenAdjust1(void) const
    00187     {
    00188         return mGreenAdj1;
    00189     }
    00190     //-----------------------------------------------------------------------
    00191     Real ColourFaderAffector2::getGreenAdjust2(void) const
    00192     {
    00193         return mGreenAdj2;
    00194     }
    00195     //-----------------------------------------------------------------------
    00196     void ColourFaderAffector2::setBlueAdjust1(Real blue)
    00197     {
    00198         mBlueAdj1 = blue;
    00199     }
    00200     //-----------------------------------------------------------------------
    00201     void ColourFaderAffector2::setBlueAdjust2(Real blue)
    00202     {
    00203         mBlueAdj2 = blue;
    00204     }
    00205     //-----------------------------------------------------------------------
    00206     Real ColourFaderAffector2::getBlueAdjust1(void) const
    00207     {
    00208         return mBlueAdj1;
    00209     }
    00210     //-----------------------------------------------------------------------
    00211     Real ColourFaderAffector2::getBlueAdjust2(void) const
    00212     {
    00213         return mBlueAdj2;
    00214     }
    00215     //-----------------------------------------------------------------------
    00216     void ColourFaderAffector2::setAlphaAdjust1(Real alpha)
    00217     {
    00218         mAlphaAdj1 = alpha;
    00219     }
    00220     //-----------------------------------------------------------------------
    00221     void ColourFaderAffector2::setAlphaAdjust2(Real alpha)
    00222     {
    00223         mAlphaAdj2 = alpha;
    00224     }
    00225     //-----------------------------------------------------------------------
    00226     Real ColourFaderAffector2::getAlphaAdjust1(void) const
    00227     {
    00228         return mAlphaAdj1;
    00229     }
    00230     //-----------------------------------------------------------------------
    00231     Real ColourFaderAffector2::getAlphaAdjust2(void) const
    00232     {
    00233         return mAlphaAdj2;
    00234     }
    00235     //-----------------------------------------------------------------------
    00236     void ColourFaderAffector2::setStateChange(Real NewValue)
    00237     {
    00238         StateChangeVal = NewValue;
    00239     }
    00240     //-----------------------------------------------------------------------
    00241     Real ColourFaderAffector2::getStateChange(void) const
    00242     {
    00243         return StateChangeVal;
    00244     }
    00245     //-----------------------------------------------------------------------
    00246     //-----------------------------------------------------------------------
    00247     //-----------------------------------------------------------------------
    00248     // Command objects
    00249     //-----------------------------------------------------------------------
    00250     //-----------------------------------------------------------------------
    00251     String ColourFaderAffector2::CmdRedAdjust1::doGet(const void* target) const
    00252     {
    00253         return StringConverter::toString(
    00254             static_cast<const ColourFaderAffector2*>(target)->getRedAdjust1() );
    00255     }
    00256     void ColourFaderAffector2::CmdRedAdjust1::doSet(void* target, const String& val)
    00257     {
    00258         static_cast<ColourFaderAffector2*>(target)->setRedAdjust1(
    00259             StringConverter::parseReal(val));
    00260     }
    00261     String ColourFaderAffector2::CmdRedAdjust2::doGet(const void* target) const
    00262     {
    00263         return StringConverter::toString(
    00264             static_cast<const ColourFaderAffector2*>(target)->getRedAdjust2() );
    00265     }
    00266     void ColourFaderAffector2::CmdRedAdjust2::doSet(void* target, const String& val)
    00267     {
    00268         static_cast<ColourFaderAffector2*>(target)->setRedAdjust2(
    00269             StringConverter::parseReal(val));
    00270     }
    00271     //-----------------------------------------------------------------------
    00272     String ColourFaderAffector2::CmdGreenAdjust1::doGet(const void* target) const
    00273     {
    00274         return StringConverter::toString(
    00275             static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust1() );
    00276     }
    00277     void ColourFaderAffector2::CmdGreenAdjust1::doSet(void* target, const String& val)
    00278     {
    00279         static_cast<ColourFaderAffector2*>(target)->setGreenAdjust1(
    00280             StringConverter::parseReal(val));
    00281     }
    00282     String ColourFaderAffector2::CmdGreenAdjust2::doGet(const void* target) const
    00283     {
    00284         return StringConverter::toString(
    00285             static_cast<const ColourFaderAffector2*>(target)->getGreenAdjust2() );
    00286     }
    00287     void ColourFaderAffector2::CmdGreenAdjust2::doSet(void* target, const String& val)
    00288     {
    00289         static_cast<ColourFaderAffector2*>(target)->setGreenAdjust2(
    00290             StringConverter::parseReal(val));
    00291     }
    00292     //-----------------------------------------------------------------------
    00293     String ColourFaderAffector2::CmdBlueAdjust1::doGet(const void* target) const
    00294     {
    00295         return StringConverter::toString(
    00296             static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust1() );
    00297     }
    00298     void ColourFaderAffector2::CmdBlueAdjust1::doSet(void* target, const String& val)
    00299     {
    00300         static_cast<ColourFaderAffector2*>(target)->setBlueAdjust1(
    00301             StringConverter::parseReal(val));
    00302     }
    00303     String ColourFaderAffector2::CmdBlueAdjust2::doGet(const void* target) const
    00304     {
    00305         return StringConverter::toString(
    00306             static_cast<const ColourFaderAffector2*>(target)->getBlueAdjust2() );
    00307     }
    00308     void ColourFaderAffector2::CmdBlueAdjust2::doSet(void* target, const String& val)
    00309     {
    00310         static_cast<ColourFaderAffector2*>(target)->setBlueAdjust2(
    00311             StringConverter::parseReal(val));
    00312     }
    00313     //-----------------------------------------------------------------------
    00314     String ColourFaderAffector2::CmdAlphaAdjust1::doGet(const void* target) const
    00315     {
    00316         return StringConverter::toString(
    00317             static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust1() );
    00318     }
    00319     void ColourFaderAffector2::CmdAlphaAdjust1::doSet(void* target, const String& val)
    00320     {
    00321         static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust1(
    00322             StringConverter::parseReal(val));
    00323     }
    00324     String ColourFaderAffector2::CmdAlphaAdjust2::doGet(const void* target) const
    00325     {
    00326         return StringConverter::toString(
    00327             static_cast<const ColourFaderAffector2*>(target)->getAlphaAdjust2() );
    00328     }
    00329     void ColourFaderAffector2::CmdAlphaAdjust2::doSet(void* target, const String& val)
    00330     {
    00331         static_cast<ColourFaderAffector2*>(target)->setAlphaAdjust2(
    00332             StringConverter::parseReal(val));
    00333     }
    00334     //-----------------------------------------------------------------------
    00335     String ColourFaderAffector2::CmdStateChange::doGet(const void* target) const
    00336     {
    00337         return StringConverter::toString(
    00338             static_cast<const ColourFaderAffector2*>(target)->getStateChange() );
    00339     }
    00340     void ColourFaderAffector2::CmdStateChange::doSet(void* target, const String& val)
    00341     {
    00342         static_cast<ColourFaderAffector2*>(target)->setStateChange(
    00343             StringConverter::parseReal(val));
    00344     }
    00345 }
    00346
    00347
    00348

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:17 2004