Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/PlugIns/ParticleFX/src/OgreHollowEllipsoidEmitter.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 8.0 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright ) 2002 Tels <http://bloodgate.com> based on BoxEmitter
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreHollowEllipsoidEmitter.h"
30#include "OgreParticle.h"
31#include "OgreException.h"
32#include "OgreStringConverter.h"
33#include "OgreMath.h"
34
35/* Implements an Emitter whose emitting points all lie inside an ellipsoid.
36   See <http://mathworld.wolfram.com/Ellipsoid.html> for mathematical details.
37
38  If the lengths of two axes of an ellipsoid are the same, the figure is
39  called a 'spheroid' (depending on whether c < a or c > a, an 'oblate
40  spheroid' or 'prolate spheroid', respectively), and if all three are the
41  same, it is a 'sphere' (ball).
42*/
43
44namespace Ogre {
45
46    HollowEllipsoidEmitter::CmdInnerX HollowEllipsoidEmitter::msCmdInnerX;
47    HollowEllipsoidEmitter::CmdInnerY HollowEllipsoidEmitter::msCmdInnerY;
48    HollowEllipsoidEmitter::CmdInnerZ HollowEllipsoidEmitter::msCmdInnerZ;
49
50
51    //-----------------------------------------------------------------------
52    HollowEllipsoidEmitter::HollowEllipsoidEmitter(ParticleSystem* psys)
53        : EllipsoidEmitter(psys)
54    {
55        if (initDefaults("HollowEllipsoid"))
56        {
57            // Add custom parameters
58            ParamDictionary* pDict = getParamDictionary();
59
60            pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
61                "shape which is hollow.", PT_REAL), &msCmdInnerX);
62            pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
63                "shape which is hollow.", PT_REAL), &msCmdInnerY);
64            pDict->addParameter(ParameterDef("inner_depth", "Parametric value describing the proportion of the "
65                "shape which is hollow.", PT_REAL), &msCmdInnerZ);
66        }
67        // default is half empty
68        setInnerSize(0.5,0.5,0.5);
69    }
70    //-----------------------------------------------------------------------
71    void HollowEllipsoidEmitter::_initParticle(Particle* pParticle)
72    {
73        Real a, b, c, x, y, z;
74
75        // Init dimensions
76        pParticle->resetDimensions();
77
78        // create two random angles alpha and beta
79        // with these two angles, we are able to select any point on an
80        // ellipsoid's surface
81        Radian alpha ( Math::RangeRandom(0,Math::TWO_PI) );
82        Radian beta  ( Math::RangeRandom(0,Math::PI) );
83
84        // create three random radius values that are bigger than the inner
85        // size, but smaller/equal than/to the outer size 1.0 (inner size is
86        // between 0 and 1)
87        a = Math::RangeRandom(mInnerSize.x,1.0);
88        b = Math::RangeRandom(mInnerSize.y,1.0);
89        c = Math::RangeRandom(mInnerSize.z,1.0);
90
91        // with a,b,c we have defined a random ellipsoid between the inner
92        // ellipsoid and the outer sphere (radius 1.0)
93        // with alpha and beta we select on point on this random ellipsoid
94        // and calculate the 3D coordinates of this point
95                Real sinbeta ( Math::Sin(beta) );
96        x = a * Math::Cos(alpha) * sinbeta;
97        y = b * Math::Sin(alpha) * sinbeta;
98        z = c * Math::Cos(beta);
99
100        // scale the found point to the ellipsoid's size and move it
101        // relatively to the center of the emitter point
102
103        pParticle->position = mPosition + 
104         + x * mXRange + y * mYRange + z * mZRange;
105
106        // Generate complex data by reference
107        genEmissionColour(pParticle->colour);
108        genEmissionDirection(pParticle->direction);
109        genEmissionVelocity(pParticle->direction);
110
111        // Generate simpler data
112        pParticle->timeToLive = pParticle->totalTimeToLive = genEmissionTTL();
113       
114    }
115    //-----------------------------------------------------------------------
116    void HollowEllipsoidEmitter::setInnerSize(Real x, Real y, Real z)
117    {
118        assert((x > 0) && (x < 1.0) &&
119            (y > 0) && (y < 1.0) &&
120            (z > 0) && (z < 1.0));
121
122        mInnerSize.x = x;
123        mInnerSize.y = y;
124        mInnerSize.z = z;
125    }
126    //-----------------------------------------------------------------------
127    void HollowEllipsoidEmitter::setInnerSizeX(Real x)
128    {
129        assert(x > 0 && x < 1.0);
130
131        mInnerSize.x = x;
132    }
133    //-----------------------------------------------------------------------
134    void HollowEllipsoidEmitter::setInnerSizeY(Real y)
135    {
136        assert(y > 0 && y < 1.0);
137
138        mInnerSize.y = y;
139    }
140    //-----------------------------------------------------------------------
141    void HollowEllipsoidEmitter::setInnerSizeZ(Real z)
142    {
143        assert(z > 0 && z < 1.0);
144
145        mInnerSize.z = z;
146    }
147    //-----------------------------------------------------------------------
148    Real HollowEllipsoidEmitter::getInnerSizeX(void) const
149    {
150        return mInnerSize.x;
151    }
152    //-----------------------------------------------------------------------
153    Real HollowEllipsoidEmitter::getInnerSizeY(void) const
154    {
155        return mInnerSize.y;
156    }
157    //-----------------------------------------------------------------------
158    Real HollowEllipsoidEmitter::getInnerSizeZ(void) const
159    {
160        return mInnerSize.z;
161    }
162    //-----------------------------------------------------------------------
163    //-----------------------------------------------------------------------
164    // Command objects
165    //-----------------------------------------------------------------------
166    //-----------------------------------------------------------------------
167    String HollowEllipsoidEmitter::CmdInnerX::doGet(const void* target) const
168    {
169        return StringConverter::toString(
170            static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeX() );
171    }
172    void HollowEllipsoidEmitter::CmdInnerX::doSet(void* target, const String& val)
173    {
174        static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
175    }
176    //-----------------------------------------------------------------------
177    String HollowEllipsoidEmitter::CmdInnerY::doGet(const void* target) const
178    {
179        return StringConverter::toString(
180            static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeY() );
181    }
182    void HollowEllipsoidEmitter::CmdInnerY::doSet(void* target, const String& val)
183    {
184        static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
185    }
186    //-----------------------------------------------------------------------
187    String HollowEllipsoidEmitter::CmdInnerZ::doGet(const void* target) const
188    {
189        return StringConverter::toString(
190            static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeZ() );
191    }
192    void HollowEllipsoidEmitter::CmdInnerZ::doSet(void* target, const String& val)
193    {
194        static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeZ(StringConverter::parseReal(val));
195    }
196
197
198}
199
200
Note: See TracBrowser for help on using the repository browser.