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

# OgreColourInterpolatorAffector.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 "OgreColourInterpolatorAffector.h"
    00026 #include "OgreParticleSystem.h"
    00027 #include "OgreStringConverter.h"
    00028 #include "OgreParticle.h"
    00029
    00030
    00031 namespace Ogre {
    00032
    00033     // init statics
    00034     ColourInterpolatorAffector::CmdColourAdjust     ColourInterpolatorAffector::msColourCmd[MAX_STAGES];
    00035     ColourInterpolatorAffector::CmdTimeAdjust       ColourInterpolatorAffector::msTimeCmd[MAX_STAGES];
    00036
    00037     //-----------------------------------------------------------------------
    00038     ColourInterpolatorAffector::ColourInterpolatorAffector()
    00039     {
    00040         for (int i=0;i<MAX_STAGES;i++)
    00041         {
    00042             // set default colour to transparent grey, transparent since we might not want to display the particle here
    00043             // grey because when a colour component is 0.5f the maximum difference to another colour component is 0.5f
    00044             mColourAdj[i]   = ColourValue(0.5f, 0.5f, 0.5f, 0.0f);
    00045             mTimeAdj[i]     = 1.0f;
    00046         }
    00047
    00048         mType = "ColourInterpolator";
    00049
    00050         // Init parameters
    00051         if (createParamDictionary("ColourInterpolatorAffector"))
    00052         {
    00053             ParamDictionary* dict = getParamDictionary();
    00054
    00055             for (int i=0;i<MAX_STAGES;i++)
    00056             {
    00057                 msColourCmd[i].mIndex   = i;
    00058                 msTimeCmd[i].mIndex     = i;
    00059
    00060                 StringUtil::StrStreamType stage;
    00061                 stage << i;
    00062                 String  colour_title    = String("colour") + stage.str();
    00063                 String  time_title      = String("time") + stage.str();
    00064                 String  colour_descr    = String("Stage ") + stage.str() + String(" colour.");
    00065                 String  time_descr      = String("Stage ") + stage.str() + String(" time.");
    00066
    00067                 dict->addParameter(ParameterDef(colour_title, colour_descr, PT_COLOURVALUE), &msColourCmd[i]);
    00068                 dict->addParameter(ParameterDef(time_title,   time_descr,   PT_REAL),        &msTimeCmd[i]);
    00069             }
    00070         }
    00071     }
    00072     //-----------------------------------------------------------------------
    00073     void ColourInterpolatorAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
    00074     {
    00075         Particle*           p;
    00076         ParticleIterator    pi              = pSystem->_getIterator();
    00077
    00078
    00079         while (!pi.end())
    00080         {
    00081             p = pi.getNext();
    00082             const Real      life_time       = p->mTotalTimeToLive;
    00083             Real            particle_time   = 1.0f - (p->mTimeToLive / life_time);
    00084
    00085             if (particle_time <= mTimeAdj[0])
    00086             {
    00087                 p->mColour = mColourAdj[0];
    00088             } else
    00089             if (particle_time >= mTimeAdj[MAX_STAGES - 1])
    00090             {
    00091                 p->mColour = mColourAdj[MAX_STAGES-1];
    00092             } else
    00093             {
    00094                 for (int i=0;i<MAX_STAGES-1;i++)
    00095                 {
    00096                     if (particle_time >= mTimeAdj[i] && particle_time < mTimeAdj[i + 1])
    00097                     {
    00098                         particle_time -= mTimeAdj[i];
    00099                         particle_time /= (mTimeAdj[i+1]-mTimeAdj[i]);
    00100                         p->mColour.r = ((mColourAdj[i+1].r * particle_time) + (mColourAdj[i].r * (1.0f - particle_time)));
    00101                         p->mColour.g = ((mColourAdj[i+1].g * particle_time) + (mColourAdj[i].g * (1.0f - particle_time)));
    00102                         p->mColour.b = ((mColourAdj[i+1].b * particle_time) + (mColourAdj[i].b * (1.0f - particle_time)));
    00103                         p->mColour.a = ((mColourAdj[i+1].a * particle_time) + (mColourAdj[i].a * (1.0f - particle_time)));
    00104                         break;
    00105                     }
    00106                 }
    00107             }
    00108         }
    00109     }
    00110
    00111     //-----------------------------------------------------------------------
    00112     void ColourInterpolatorAffector::setColourAdjust(size_t index, ColourValue colour)
    00113     {
    00114         mColourAdj[index] = colour;
    00115     }
    00116     //-----------------------------------------------------------------------
    00117     ColourValue ColourInterpolatorAffector::getColourAdjust(size_t index) const
    00118     {
    00119         return mColourAdj[index];
    00120     }
    00121
    00122
    00123     //-----------------------------------------------------------------------
    00124     void ColourInterpolatorAffector::setTimeAdjust(size_t index, Real time)
    00125     {
    00126         mTimeAdj[index] = time;
    00127     }
    00128     //-----------------------------------------------------------------------
    00129     Real ColourInterpolatorAffector::getTimeAdjust(size_t index) const
    00130     {
    00131         return mTimeAdj[index];
    00132     }
    00133
    00134
    00135     //-----------------------------------------------------------------------
    00136     //-----------------------------------------------------------------------
    00137     //-----------------------------------------------------------------------
    00138     // Command objects
    00139     //-----------------------------------------------------------------------
    00140     //-----------------------------------------------------------------------
    00141     String ColourInterpolatorAffector::CmdColourAdjust::doGet(const void* target) const
    00142     {
    00143         return StringConverter::toString(
    00144             static_cast<const ColourInterpolatorAffector*>(target)->getColourAdjust(mIndex) );
    00145     }
    00146     void ColourInterpolatorAffector::CmdColourAdjust::doSet(void* target, const String& val)
    00147     {
    00148         static_cast<ColourInterpolatorAffector*>(target)->setColourAdjust(mIndex,
    00149             StringConverter::parseColourValue(val));
    00150     }
    00151     //-----------------------------------------------------------------------
    00152     String ColourInterpolatorAffector::CmdTimeAdjust::doGet(const void* target) const
    00153     {
    00154         return StringConverter::toString(
    00155             static_cast<const ColourInterpolatorAffector*>(target)->getTimeAdjust(mIndex) );
    00156     }
    00157     void ColourInterpolatorAffector::CmdTimeAdjust::doSet(void* target, const String& val)
    00158     {
    00159         static_cast<ColourInterpolatorAffector*>(target)->setTimeAdjust(mIndex,
    00160             StringConverter::parseReal(val));
    00161     }
    00162
    00163 }
    00164
    00165
    00166

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