[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #include "OgreColourFaderAffector.h"
|
---|
| 26 | #include "OgreParticleSystem.h"
|
---|
| 27 | #include "OgreStringConverter.h"
|
---|
| 28 | #include "OgreParticle.h"
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | namespace Ogre {
|
---|
| 32 |
|
---|
| 33 | // init statics
|
---|
| 34 | ColourFaderAffector::CmdRedAdjust ColourFaderAffector::msRedCmd;
|
---|
| 35 | ColourFaderAffector::CmdGreenAdjust ColourFaderAffector::msGreenCmd;
|
---|
| 36 | ColourFaderAffector::CmdBlueAdjust ColourFaderAffector::msBlueCmd;
|
---|
| 37 | ColourFaderAffector::CmdAlphaAdjust ColourFaderAffector::msAlphaCmd;
|
---|
| 38 |
|
---|
| 39 | //-----------------------------------------------------------------------
|
---|
| 40 | ColourFaderAffector::ColourFaderAffector(ParticleSystem* psys) : ParticleAffector(psys)
|
---|
| 41 | {
|
---|
| 42 | mRedAdj = mGreenAdj = mBlueAdj = mAlphaAdj = 0;
|
---|
| 43 | mType = "ColourFader";
|
---|
| 44 |
|
---|
| 45 | // Init parameters
|
---|
| 46 | if (createParamDictionary("ColourFaderAffector"))
|
---|
| 47 | {
|
---|
| 48 | ParamDictionary* dict = getParamDictionary();
|
---|
| 49 |
|
---|
| 50 | dict->addParameter(ParameterDef("red",
|
---|
| 51 | "The amount by which to adjust the red component of particles per second.",
|
---|
| 52 | PT_REAL), &msRedCmd);
|
---|
| 53 | dict->addParameter(ParameterDef("green",
|
---|
| 54 | "The amount by which to adjust the green component of particles per second.",
|
---|
| 55 | PT_REAL), &msGreenCmd);
|
---|
| 56 | dict->addParameter(ParameterDef("blue",
|
---|
| 57 | "The amount by which to adjust the blue component of particles per second.",
|
---|
| 58 | PT_REAL), &msBlueCmd);
|
---|
| 59 | dict->addParameter(ParameterDef("alpha",
|
---|
| 60 | "The amount by which to adjust the alpha component of particles per second.",
|
---|
| 61 | PT_REAL), &msAlphaCmd);
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | //-----------------------------------------------------------------------
|
---|
| 67 | void ColourFaderAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
|
---|
| 68 | {
|
---|
| 69 | ParticleIterator pi = pSystem->_getIterator();
|
---|
| 70 | Particle *p;
|
---|
| 71 | float dr, dg, db, da;
|
---|
| 72 |
|
---|
| 73 | // Scale adjustments by time
|
---|
| 74 | dr = mRedAdj * timeElapsed;
|
---|
| 75 | dg = mGreenAdj * timeElapsed;
|
---|
| 76 | db = mBlueAdj * timeElapsed;
|
---|
| 77 | da = mAlphaAdj * timeElapsed;
|
---|
| 78 |
|
---|
| 79 | while (!pi.end())
|
---|
| 80 | {
|
---|
| 81 | p = pi.getNext();
|
---|
| 82 | applyAdjustWithClamp(&p->colour.r, dr);
|
---|
| 83 | applyAdjustWithClamp(&p->colour.g, dg);
|
---|
| 84 | applyAdjustWithClamp(&p->colour.b, db);
|
---|
| 85 | applyAdjustWithClamp(&p->colour.a, da);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | }
|
---|
| 89 | //-----------------------------------------------------------------------
|
---|
| 90 | void ColourFaderAffector::setAdjust(float red, float green, float blue, float alpha)
|
---|
| 91 | {
|
---|
| 92 | mRedAdj = red;
|
---|
| 93 | mGreenAdj = green;
|
---|
| 94 | mBlueAdj = blue;
|
---|
| 95 | mAlphaAdj = alpha;
|
---|
| 96 | }
|
---|
| 97 | //-----------------------------------------------------------------------
|
---|
| 98 | void ColourFaderAffector::setRedAdjust(float red)
|
---|
| 99 | {
|
---|
| 100 | mRedAdj = red;
|
---|
| 101 | }
|
---|
| 102 | //-----------------------------------------------------------------------
|
---|
| 103 | float ColourFaderAffector::getRedAdjust(void) const
|
---|
| 104 | {
|
---|
| 105 | return mRedAdj;
|
---|
| 106 | }
|
---|
| 107 | //-----------------------------------------------------------------------
|
---|
| 108 | void ColourFaderAffector::setGreenAdjust(float green)
|
---|
| 109 | {
|
---|
| 110 | mGreenAdj = green;
|
---|
| 111 | }
|
---|
| 112 | //-----------------------------------------------------------------------
|
---|
| 113 | float ColourFaderAffector::getGreenAdjust(void) const
|
---|
| 114 | {
|
---|
| 115 | return mGreenAdj;
|
---|
| 116 | }
|
---|
| 117 | //-----------------------------------------------------------------------
|
---|
| 118 | void ColourFaderAffector::setBlueAdjust(float blue)
|
---|
| 119 | {
|
---|
| 120 | mBlueAdj = blue;
|
---|
| 121 | }
|
---|
| 122 | //-----------------------------------------------------------------------
|
---|
| 123 | float ColourFaderAffector::getBlueAdjust(void) const
|
---|
| 124 | {
|
---|
| 125 | return mBlueAdj;
|
---|
| 126 | }
|
---|
| 127 | //-----------------------------------------------------------------------
|
---|
| 128 | void ColourFaderAffector::setAlphaAdjust(float alpha)
|
---|
| 129 | {
|
---|
| 130 | mAlphaAdj = alpha;
|
---|
| 131 | }
|
---|
| 132 | //-----------------------------------------------------------------------
|
---|
| 133 | float ColourFaderAffector::getAlphaAdjust(void) const
|
---|
| 134 | {
|
---|
| 135 | return mAlphaAdj;
|
---|
| 136 | }
|
---|
| 137 | //-----------------------------------------------------------------------
|
---|
| 138 | //-----------------------------------------------------------------------
|
---|
| 139 | //-----------------------------------------------------------------------
|
---|
| 140 | // Command objects
|
---|
| 141 | //-----------------------------------------------------------------------
|
---|
| 142 | //-----------------------------------------------------------------------
|
---|
| 143 | String ColourFaderAffector::CmdRedAdjust::doGet(const void* target) const
|
---|
| 144 | {
|
---|
| 145 | return StringConverter::toString(
|
---|
| 146 | static_cast<const ColourFaderAffector*>(target)->getRedAdjust() );
|
---|
| 147 | }
|
---|
| 148 | void ColourFaderAffector::CmdRedAdjust::doSet(void* target, const String& val)
|
---|
| 149 | {
|
---|
| 150 | static_cast<ColourFaderAffector*>(target)->setRedAdjust(
|
---|
| 151 | StringConverter::parseReal(val));
|
---|
| 152 | }
|
---|
| 153 | //-----------------------------------------------------------------------
|
---|
| 154 | String ColourFaderAffector::CmdGreenAdjust::doGet(const void* target) const
|
---|
| 155 | {
|
---|
| 156 | return StringConverter::toString(
|
---|
| 157 | static_cast<const ColourFaderAffector*>(target)->getGreenAdjust() );
|
---|
| 158 | }
|
---|
| 159 | void ColourFaderAffector::CmdGreenAdjust::doSet(void* target, const String& val)
|
---|
| 160 | {
|
---|
| 161 | static_cast<ColourFaderAffector*>(target)->setGreenAdjust(
|
---|
| 162 | StringConverter::parseReal(val));
|
---|
| 163 | }
|
---|
| 164 | //-----------------------------------------------------------------------
|
---|
| 165 | String ColourFaderAffector::CmdBlueAdjust::doGet(const void* target) const
|
---|
| 166 | {
|
---|
| 167 | return StringConverter::toString(
|
---|
| 168 | static_cast<const ColourFaderAffector*>(target)->getBlueAdjust() );
|
---|
| 169 | }
|
---|
| 170 | void ColourFaderAffector::CmdBlueAdjust::doSet(void* target, const String& val)
|
---|
| 171 | {
|
---|
| 172 | static_cast<ColourFaderAffector*>(target)->setBlueAdjust(
|
---|
| 173 | StringConverter::parseReal(val));
|
---|
| 174 | }
|
---|
| 175 | //-----------------------------------------------------------------------
|
---|
| 176 | String ColourFaderAffector::CmdAlphaAdjust::doGet(const void* target) const
|
---|
| 177 | {
|
---|
| 178 | return StringConverter::toString(
|
---|
| 179 | static_cast<const ColourFaderAffector*>(target)->getAlphaAdjust() );
|
---|
| 180 | }
|
---|
| 181 | void ColourFaderAffector::CmdAlphaAdjust::doSet(void* target, const String& val)
|
---|
| 182 | {
|
---|
| 183 | static_cast<ColourFaderAffector*>(target)->setAlphaAdjust(
|
---|
| 184 | StringConverter::parseReal(val));
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|