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

OgreColourFaderAffector.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 "OgreColourFaderAffector.h"
00026 #include "OgreParticleSystem.h"
00027 #include "OgreStringConverter.h"
00028 #include "OgreParticle.h"
00029 
00030 
00031 namespace Ogre {
00032     
00033     // init statics
00034     ColourFaderAffector::CmdRedAdjust ColourFaderAffector::msRedCmd;
00035     ColourFaderAffector::CmdGreenAdjust ColourFaderAffector::msGreenCmd;
00036     ColourFaderAffector::CmdBlueAdjust ColourFaderAffector::msBlueCmd;
00037     ColourFaderAffector::CmdAlphaAdjust ColourFaderAffector::msAlphaCmd;
00038 
00039     //-----------------------------------------------------------------------
00040     ColourFaderAffector::ColourFaderAffector()
00041     {
00042         mRedAdj = mGreenAdj = mBlueAdj = mAlphaAdj = 0;
00043         mType = "ColourFader";
00044 
00045         // Init parameters
00046         if (createParamDictionary("ColourFaderAffector"))
00047         {
00048             ParamDictionary* dict = getParamDictionary();
00049 
00050             dict->addParameter(ParameterDef("red", 
00051                 "The amount by which to adjust the red component of particles per second.",
00052                 PT_REAL), &msRedCmd);
00053             dict->addParameter(ParameterDef("green", 
00054                 "The amount by which to adjust the green component of particles per second.",
00055                 PT_REAL), &msGreenCmd);
00056             dict->addParameter(ParameterDef("blue", 
00057                 "The amount by which to adjust the blue component of particles per second.",
00058                 PT_REAL), &msBlueCmd);
00059             dict->addParameter(ParameterDef("alpha", 
00060                 "The amount by which to adjust the alpha component of particles per second.",
00061                 PT_REAL), &msAlphaCmd);
00062 
00063 
00064         }
00065     }
00066     //-----------------------------------------------------------------------
00067     void ColourFaderAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
00068     {
00069         ParticleIterator pi = pSystem->_getIterator();
00070         Particle *p;
00071         Real dr, dg, db, da;
00072 
00073         // Scale adjustments by time
00074         dr = mRedAdj * timeElapsed;
00075         dg = mGreenAdj * timeElapsed;
00076         db = mBlueAdj * timeElapsed;
00077         da = mAlphaAdj * timeElapsed;
00078 
00079         while (!pi.end())
00080         {
00081             p = pi.getNext();
00082             applyAdjustWithClamp(&p->mColour.r, dr);
00083             applyAdjustWithClamp(&p->mColour.g, dg);
00084             applyAdjustWithClamp(&p->mColour.b, db);
00085             applyAdjustWithClamp(&p->mColour.a, da);
00086         }
00087 
00088     }
00089     //-----------------------------------------------------------------------
00090     void ColourFaderAffector::setAdjust(Real red, Real green, Real blue, Real alpha)
00091     {
00092         mRedAdj = red;
00093         mGreenAdj = green;
00094         mBlueAdj = blue;
00095         mAlphaAdj = alpha;
00096     }
00097     //-----------------------------------------------------------------------
00098     void ColourFaderAffector::setRedAdjust(Real red)
00099     {
00100         mRedAdj = red;
00101     }
00102     //-----------------------------------------------------------------------
00103     Real ColourFaderAffector::getRedAdjust(void) const
00104     {
00105         return mRedAdj;
00106     }
00107     //-----------------------------------------------------------------------
00108     void ColourFaderAffector::setGreenAdjust(Real green)
00109     {
00110         mGreenAdj = green;
00111     }
00112     //-----------------------------------------------------------------------
00113     Real ColourFaderAffector::getGreenAdjust(void) const
00114     {
00115         return mGreenAdj;
00116     }
00117     //-----------------------------------------------------------------------
00118     void ColourFaderAffector::setBlueAdjust(Real blue)
00119     {
00120         mBlueAdj = blue;
00121     }
00122     //-----------------------------------------------------------------------
00123     Real ColourFaderAffector::getBlueAdjust(void) const
00124     {
00125         return mBlueAdj;
00126     }
00127     //-----------------------------------------------------------------------
00128     void ColourFaderAffector::setAlphaAdjust(Real alpha)
00129     {
00130         mAlphaAdj = alpha;
00131     }
00132     //-----------------------------------------------------------------------
00133     Real ColourFaderAffector::getAlphaAdjust(void) const
00134     {
00135         return mAlphaAdj;
00136     }
00137     //-----------------------------------------------------------------------
00138     //-----------------------------------------------------------------------
00139     //-----------------------------------------------------------------------
00140     // Command objects
00141     //-----------------------------------------------------------------------
00142     //-----------------------------------------------------------------------
00143     String ColourFaderAffector::CmdRedAdjust::doGet(const void* target) const
00144     {
00145         return StringConverter::toString(
00146             static_cast<const ColourFaderAffector*>(target)->getRedAdjust() );
00147     }
00148     void ColourFaderAffector::CmdRedAdjust::doSet(void* target, const String& val)
00149     {
00150         static_cast<ColourFaderAffector*>(target)->setRedAdjust(
00151             StringConverter::parseReal(val));
00152     }
00153     //-----------------------------------------------------------------------
00154     String ColourFaderAffector::CmdGreenAdjust::doGet(const void* target) const
00155     {
00156         return StringConverter::toString(
00157             static_cast<const ColourFaderAffector*>(target)->getGreenAdjust() );
00158     }
00159     void ColourFaderAffector::CmdGreenAdjust::doSet(void* target, const String& val)
00160     {
00161         static_cast<ColourFaderAffector*>(target)->setGreenAdjust(
00162             StringConverter::parseReal(val));
00163     }
00164     //-----------------------------------------------------------------------
00165     String ColourFaderAffector::CmdBlueAdjust::doGet(const void* target) const
00166     {
00167         return StringConverter::toString(
00168             static_cast<const ColourFaderAffector*>(target)->getBlueAdjust() );
00169     }
00170     void ColourFaderAffector::CmdBlueAdjust::doSet(void* target, const String& val)
00171     {
00172         static_cast<ColourFaderAffector*>(target)->setBlueAdjust(
00173             StringConverter::parseReal(val));
00174     }
00175     //-----------------------------------------------------------------------
00176     String ColourFaderAffector::CmdAlphaAdjust::doGet(const void* target) const
00177     {
00178         return StringConverter::toString(
00179             static_cast<const ColourFaderAffector*>(target)->getAlphaAdjust() );
00180     }
00181     void ColourFaderAffector::CmdAlphaAdjust::doSet(void* target, const String& val)
00182     {
00183         static_cast<ColourFaderAffector*>(target)->setAlphaAdjust(
00184             StringConverter::parseReal(val));
00185     }
00186 
00187 }
00188 
00189 
00190 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:21:57 2004