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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreColourFaderAffector.h" |
---|
30 | #include "OgreParticleSystem.h" |
---|
31 | #include "OgreStringConverter.h" |
---|
32 | #include "OgreParticle.h" |
---|
33 | |
---|
34 | |
---|
35 | namespace Ogre { |
---|
36 | |
---|
37 | // init statics |
---|
38 | ColourFaderAffector::CmdRedAdjust ColourFaderAffector::msRedCmd; |
---|
39 | ColourFaderAffector::CmdGreenAdjust ColourFaderAffector::msGreenCmd; |
---|
40 | ColourFaderAffector::CmdBlueAdjust ColourFaderAffector::msBlueCmd; |
---|
41 | ColourFaderAffector::CmdAlphaAdjust ColourFaderAffector::msAlphaCmd; |
---|
42 | |
---|
43 | //----------------------------------------------------------------------- |
---|
44 | ColourFaderAffector::ColourFaderAffector(ParticleSystem* psys) : ParticleAffector(psys) |
---|
45 | { |
---|
46 | mRedAdj = mGreenAdj = mBlueAdj = mAlphaAdj = 0; |
---|
47 | mType = "ColourFader"; |
---|
48 | |
---|
49 | // Init parameters |
---|
50 | if (createParamDictionary("ColourFaderAffector")) |
---|
51 | { |
---|
52 | ParamDictionary* dict = getParamDictionary(); |
---|
53 | |
---|
54 | dict->addParameter(ParameterDef("red", |
---|
55 | "The amount by which to adjust the red component of particles per second.", |
---|
56 | PT_REAL), &msRedCmd); |
---|
57 | dict->addParameter(ParameterDef("green", |
---|
58 | "The amount by which to adjust the green component of particles per second.", |
---|
59 | PT_REAL), &msGreenCmd); |
---|
60 | dict->addParameter(ParameterDef("blue", |
---|
61 | "The amount by which to adjust the blue component of particles per second.", |
---|
62 | PT_REAL), &msBlueCmd); |
---|
63 | dict->addParameter(ParameterDef("alpha", |
---|
64 | "The amount by which to adjust the alpha component of particles per second.", |
---|
65 | PT_REAL), &msAlphaCmd); |
---|
66 | |
---|
67 | |
---|
68 | } |
---|
69 | } |
---|
70 | //----------------------------------------------------------------------- |
---|
71 | void ColourFaderAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed) |
---|
72 | { |
---|
73 | ParticleIterator pi = pSystem->_getIterator(); |
---|
74 | Particle *p; |
---|
75 | float dr, dg, db, da; |
---|
76 | |
---|
77 | // Scale adjustments by time |
---|
78 | dr = mRedAdj * timeElapsed; |
---|
79 | dg = mGreenAdj * timeElapsed; |
---|
80 | db = mBlueAdj * timeElapsed; |
---|
81 | da = mAlphaAdj * timeElapsed; |
---|
82 | |
---|
83 | while (!pi.end()) |
---|
84 | { |
---|
85 | p = pi.getNext(); |
---|
86 | applyAdjustWithClamp(&p->colour.r, dr); |
---|
87 | applyAdjustWithClamp(&p->colour.g, dg); |
---|
88 | applyAdjustWithClamp(&p->colour.b, db); |
---|
89 | applyAdjustWithClamp(&p->colour.a, da); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | //----------------------------------------------------------------------- |
---|
94 | void ColourFaderAffector::setAdjust(float red, float green, float blue, float alpha) |
---|
95 | { |
---|
96 | mRedAdj = red; |
---|
97 | mGreenAdj = green; |
---|
98 | mBlueAdj = blue; |
---|
99 | mAlphaAdj = alpha; |
---|
100 | } |
---|
101 | //----------------------------------------------------------------------- |
---|
102 | void ColourFaderAffector::setRedAdjust(float red) |
---|
103 | { |
---|
104 | mRedAdj = red; |
---|
105 | } |
---|
106 | //----------------------------------------------------------------------- |
---|
107 | float ColourFaderAffector::getRedAdjust(void) const |
---|
108 | { |
---|
109 | return mRedAdj; |
---|
110 | } |
---|
111 | //----------------------------------------------------------------------- |
---|
112 | void ColourFaderAffector::setGreenAdjust(float green) |
---|
113 | { |
---|
114 | mGreenAdj = green; |
---|
115 | } |
---|
116 | //----------------------------------------------------------------------- |
---|
117 | float ColourFaderAffector::getGreenAdjust(void) const |
---|
118 | { |
---|
119 | return mGreenAdj; |
---|
120 | } |
---|
121 | //----------------------------------------------------------------------- |
---|
122 | void ColourFaderAffector::setBlueAdjust(float blue) |
---|
123 | { |
---|
124 | mBlueAdj = blue; |
---|
125 | } |
---|
126 | //----------------------------------------------------------------------- |
---|
127 | float ColourFaderAffector::getBlueAdjust(void) const |
---|
128 | { |
---|
129 | return mBlueAdj; |
---|
130 | } |
---|
131 | //----------------------------------------------------------------------- |
---|
132 | void ColourFaderAffector::setAlphaAdjust(float alpha) |
---|
133 | { |
---|
134 | mAlphaAdj = alpha; |
---|
135 | } |
---|
136 | //----------------------------------------------------------------------- |
---|
137 | float ColourFaderAffector::getAlphaAdjust(void) const |
---|
138 | { |
---|
139 | return mAlphaAdj; |
---|
140 | } |
---|
141 | //----------------------------------------------------------------------- |
---|
142 | //----------------------------------------------------------------------- |
---|
143 | //----------------------------------------------------------------------- |
---|
144 | // Command objects |
---|
145 | //----------------------------------------------------------------------- |
---|
146 | //----------------------------------------------------------------------- |
---|
147 | String ColourFaderAffector::CmdRedAdjust::doGet(const void* target) const |
---|
148 | { |
---|
149 | return StringConverter::toString( |
---|
150 | static_cast<const ColourFaderAffector*>(target)->getRedAdjust() ); |
---|
151 | } |
---|
152 | void ColourFaderAffector::CmdRedAdjust::doSet(void* target, const String& val) |
---|
153 | { |
---|
154 | static_cast<ColourFaderAffector*>(target)->setRedAdjust( |
---|
155 | StringConverter::parseReal(val)); |
---|
156 | } |
---|
157 | //----------------------------------------------------------------------- |
---|
158 | String ColourFaderAffector::CmdGreenAdjust::doGet(const void* target) const |
---|
159 | { |
---|
160 | return StringConverter::toString( |
---|
161 | static_cast<const ColourFaderAffector*>(target)->getGreenAdjust() ); |
---|
162 | } |
---|
163 | void ColourFaderAffector::CmdGreenAdjust::doSet(void* target, const String& val) |
---|
164 | { |
---|
165 | static_cast<ColourFaderAffector*>(target)->setGreenAdjust( |
---|
166 | StringConverter::parseReal(val)); |
---|
167 | } |
---|
168 | //----------------------------------------------------------------------- |
---|
169 | String ColourFaderAffector::CmdBlueAdjust::doGet(const void* target) const |
---|
170 | { |
---|
171 | return StringConverter::toString( |
---|
172 | static_cast<const ColourFaderAffector*>(target)->getBlueAdjust() ); |
---|
173 | } |
---|
174 | void ColourFaderAffector::CmdBlueAdjust::doSet(void* target, const String& val) |
---|
175 | { |
---|
176 | static_cast<ColourFaderAffector*>(target)->setBlueAdjust( |
---|
177 | StringConverter::parseReal(val)); |
---|
178 | } |
---|
179 | //----------------------------------------------------------------------- |
---|
180 | String ColourFaderAffector::CmdAlphaAdjust::doGet(const void* target) const |
---|
181 | { |
---|
182 | return StringConverter::toString( |
---|
183 | static_cast<const ColourFaderAffector*>(target)->getAlphaAdjust() ); |
---|
184 | } |
---|
185 | void ColourFaderAffector::CmdAlphaAdjust::doSet(void* target, const String& val) |
---|
186 | { |
---|
187 | static_cast<ColourFaderAffector*>(target)->setAlphaAdjust( |
---|
188 | StringConverter::parseReal(val)); |
---|
189 | } |
---|
190 | |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|