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 ) 2002 Tels <http://bloodgate.com> based on BoxEmitter
|
---|
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 "OgreHollowEllipsoidEmitter.h"
|
---|
26 | #include "OgreParticle.h"
|
---|
27 | #include "OgreException.h"
|
---|
28 | #include "OgreStringConverter.h"
|
---|
29 | #include "OgreMath.h"
|
---|
30 |
|
---|
31 | /* Implements an Emitter whose emitting points all lie inside an ellipsoid.
|
---|
32 | See <http://mathworld.wolfram.com/Ellipsoid.html> for mathematical details.
|
---|
33 |
|
---|
34 | If the lengths of two axes of an ellipsoid are the same, the figure is
|
---|
35 | called a 'spheroid' (depending on whether c < a or c > a, an 'oblate
|
---|
36 | spheroid' or 'prolate spheroid', respectively), and if all three are the
|
---|
37 | same, it is a 'sphere' (ball).
|
---|
38 | */
|
---|
39 |
|
---|
40 | namespace Ogre {
|
---|
41 |
|
---|
42 | HollowEllipsoidEmitter::CmdInnerX HollowEllipsoidEmitter::msCmdInnerX;
|
---|
43 | HollowEllipsoidEmitter::CmdInnerY HollowEllipsoidEmitter::msCmdInnerY;
|
---|
44 | HollowEllipsoidEmitter::CmdInnerZ HollowEllipsoidEmitter::msCmdInnerZ;
|
---|
45 |
|
---|
46 |
|
---|
47 | //-----------------------------------------------------------------------
|
---|
48 | HollowEllipsoidEmitter::HollowEllipsoidEmitter(ParticleSystem* psys)
|
---|
49 | : EllipsoidEmitter(psys)
|
---|
50 | {
|
---|
51 | if (initDefaults("HollowEllipsoid"))
|
---|
52 | {
|
---|
53 | // Add custom parameters
|
---|
54 | ParamDictionary* pDict = getParamDictionary();
|
---|
55 |
|
---|
56 | pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
|
---|
57 | "shape which is hollow.", PT_REAL), &msCmdInnerX);
|
---|
58 | pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
|
---|
59 | "shape which is hollow.", PT_REAL), &msCmdInnerY);
|
---|
60 | pDict->addParameter(ParameterDef("inner_depth", "Parametric value describing the proportion of the "
|
---|
61 | "shape which is hollow.", PT_REAL), &msCmdInnerZ);
|
---|
62 | }
|
---|
63 | // default is half empty
|
---|
64 | setInnerSize(0.5,0.5,0.5);
|
---|
65 | }
|
---|
66 | //-----------------------------------------------------------------------
|
---|
67 | void HollowEllipsoidEmitter::_initParticle(Particle* pParticle)
|
---|
68 | {
|
---|
69 | Real a, b, c, x, y, z;
|
---|
70 |
|
---|
71 | // Init dimensions
|
---|
72 | pParticle->resetDimensions();
|
---|
73 |
|
---|
74 | // create two random angles alpha and beta
|
---|
75 | // with these two angles, we are able to select any point on an
|
---|
76 | // ellipsoid's surface
|
---|
77 | Radian alpha ( Math::RangeRandom(0,Math::TWO_PI) );
|
---|
78 | Radian beta ( Math::RangeRandom(0,Math::PI) );
|
---|
79 |
|
---|
80 | // create three random radius values that are bigger than the inner
|
---|
81 | // size, but smaller/equal than/to the outer size 1.0 (inner size is
|
---|
82 | // between 0 and 1)
|
---|
83 | a = Math::RangeRandom(mInnerSize.x,1.0);
|
---|
84 | b = Math::RangeRandom(mInnerSize.y,1.0);
|
---|
85 | c = Math::RangeRandom(mInnerSize.z,1.0);
|
---|
86 |
|
---|
87 | // with a,b,c we have defined a random ellipsoid between the inner
|
---|
88 | // ellipsoid and the outer sphere (radius 1.0)
|
---|
89 | // with alpha and beta we select on point on this random ellipsoid
|
---|
90 | // and calculate the 3D coordinates of this point
|
---|
91 | Real sinbeta ( Math::Sin(beta) );
|
---|
92 | x = a * Math::Cos(alpha) * sinbeta;
|
---|
93 | y = b * Math::Sin(alpha) * sinbeta;
|
---|
94 | z = c * Math::Cos(beta);
|
---|
95 |
|
---|
96 | // scale the found point to the ellipsoid's size and move it
|
---|
97 | // relatively to the center of the emitter point
|
---|
98 |
|
---|
99 | pParticle->position = mPosition +
|
---|
100 | + x * mXRange + y * mYRange + z * mZRange;
|
---|
101 |
|
---|
102 | // Generate complex data by reference
|
---|
103 | genEmissionColour(pParticle->colour);
|
---|
104 | genEmissionDirection(pParticle->direction);
|
---|
105 | genEmissionVelocity(pParticle->direction);
|
---|
106 |
|
---|
107 | // Generate simpler data
|
---|
108 | pParticle->timeToLive = pParticle->totalTimeToLive = genEmissionTTL();
|
---|
109 |
|
---|
110 | }
|
---|
111 | //-----------------------------------------------------------------------
|
---|
112 | void HollowEllipsoidEmitter::setInnerSize(Real x, Real y, Real z)
|
---|
113 | {
|
---|
114 | assert((x > 0) && (x < 1.0) &&
|
---|
115 | (y > 0) && (y < 1.0) &&
|
---|
116 | (z > 0) && (z < 1.0));
|
---|
117 |
|
---|
118 | mInnerSize.x = x;
|
---|
119 | mInnerSize.y = y;
|
---|
120 | mInnerSize.z = z;
|
---|
121 | }
|
---|
122 | //-----------------------------------------------------------------------
|
---|
123 | void HollowEllipsoidEmitter::setInnerSizeX(Real x)
|
---|
124 | {
|
---|
125 | assert(x > 0 && x < 1.0);
|
---|
126 |
|
---|
127 | mInnerSize.x = x;
|
---|
128 | }
|
---|
129 | //-----------------------------------------------------------------------
|
---|
130 | void HollowEllipsoidEmitter::setInnerSizeY(Real y)
|
---|
131 | {
|
---|
132 | assert(y > 0 && y < 1.0);
|
---|
133 |
|
---|
134 | mInnerSize.y = y;
|
---|
135 | }
|
---|
136 | //-----------------------------------------------------------------------
|
---|
137 | void HollowEllipsoidEmitter::setInnerSizeZ(Real z)
|
---|
138 | {
|
---|
139 | assert(z > 0 && z < 1.0);
|
---|
140 |
|
---|
141 | mInnerSize.z = z;
|
---|
142 | }
|
---|
143 | //-----------------------------------------------------------------------
|
---|
144 | Real HollowEllipsoidEmitter::getInnerSizeX(void) const
|
---|
145 | {
|
---|
146 | return mInnerSize.x;
|
---|
147 | }
|
---|
148 | //-----------------------------------------------------------------------
|
---|
149 | Real HollowEllipsoidEmitter::getInnerSizeY(void) const
|
---|
150 | {
|
---|
151 | return mInnerSize.y;
|
---|
152 | }
|
---|
153 | //-----------------------------------------------------------------------
|
---|
154 | Real HollowEllipsoidEmitter::getInnerSizeZ(void) const
|
---|
155 | {
|
---|
156 | return mInnerSize.z;
|
---|
157 | }
|
---|
158 | //-----------------------------------------------------------------------
|
---|
159 | //-----------------------------------------------------------------------
|
---|
160 | // Command objects
|
---|
161 | //-----------------------------------------------------------------------
|
---|
162 | //-----------------------------------------------------------------------
|
---|
163 | String HollowEllipsoidEmitter::CmdInnerX::doGet(const void* target) const
|
---|
164 | {
|
---|
165 | return StringConverter::toString(
|
---|
166 | static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeX() );
|
---|
167 | }
|
---|
168 | void HollowEllipsoidEmitter::CmdInnerX::doSet(void* target, const String& val)
|
---|
169 | {
|
---|
170 | static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
|
---|
171 | }
|
---|
172 | //-----------------------------------------------------------------------
|
---|
173 | String HollowEllipsoidEmitter::CmdInnerY::doGet(const void* target) const
|
---|
174 | {
|
---|
175 | return StringConverter::toString(
|
---|
176 | static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeY() );
|
---|
177 | }
|
---|
178 | void HollowEllipsoidEmitter::CmdInnerY::doSet(void* target, const String& val)
|
---|
179 | {
|
---|
180 | static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
|
---|
181 | }
|
---|
182 | //-----------------------------------------------------------------------
|
---|
183 | String HollowEllipsoidEmitter::CmdInnerZ::doGet(const void* target) const
|
---|
184 | {
|
---|
185 | return StringConverter::toString(
|
---|
186 | static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeZ() );
|
---|
187 | }
|
---|
188 | void HollowEllipsoidEmitter::CmdInnerZ::doSet(void* target, const String& val)
|
---|
189 | {
|
---|
190 | static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeZ(StringConverter::parseReal(val));
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|