source: OGRE/trunk/ogrenew/PlugIns/ParticleFX/src/OgreRingEmitter.cpp @ 692

Revision 692, 5.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-----------------------------------------------------------------------------
24*/
25#include "OgreRingEmitter.h"
26#include "OgreParticle.h"
27#include "OgreException.h"
28#include "OgreStringConverter.h"
29
30
31/* Implements an Emitter whose emitting points all lie inside a ring.
32*/
33
34namespace Ogre {
35
36    RingEmitter::CmdInnerX RingEmitter::msCmdInnerX;
37    RingEmitter::CmdInnerY RingEmitter::msCmdInnerY;
38
39    //-----------------------------------------------------------------------
40    RingEmitter::RingEmitter(ParticleSystem* psys)
41        : AreaEmitter(psys)
42    {
43        if (initDefaults("Ring"))
44        {
45            // Add custom parameters
46            ParamDictionary* pDict = getParamDictionary();
47
48            pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
49                "shape which is hollow.", PT_REAL), &msCmdInnerX);
50            pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
51                "shape which is hollow.", PT_REAL), &msCmdInnerY);
52        }
53        // default is half empty
54        setInnerSize(0.5,0.5);
55    }
56    //-----------------------------------------------------------------------
57    void RingEmitter::_initParticle(Particle* pParticle)
58    {
59        Real a, b, x, y, z;
60
61        // Call superclass
62        AreaEmitter::_initParticle(pParticle);
63        // create a random angle from 0 .. PI*2
64        Radian alpha ( Math::RangeRandom(0,Math::TWO_PI) );
65 
66        // create two random radius values that are bigger than the inner size
67        a = Math::RangeRandom(mInnerSizex,1.0);
68        b = Math::RangeRandom(mInnerSizey,1.0);
69
70        // with a and b we have defined a random ellipse inside the inner
71        // ellipse and the outer circle (radius 1.0)
72        // with alpha, and a and b we select a random point on this ellipse
73        // and calculate it's coordinates
74        x = a * Math::Sin(alpha);
75        y = b * Math::Cos(alpha);
76        // the height is simple -1 to 1
77        z = Math::SymmetricRandom();     
78
79        // scale the found point to the ring's size and move it
80        // relatively to the center of the emitter point
81
82        pParticle->position = mPosition +
83         + x * mXRange + y * mYRange + z * mZRange;
84
85        // Generate complex data by reference
86        genEmissionColour(pParticle->colour);
87        genEmissionDirection(pParticle->direction);
88        genEmissionVelocity(pParticle->direction);
89
90        // Generate simpler data
91        pParticle->timeToLive = pParticle->totalTimeToLive = genEmissionTTL();
92       
93    }
94    //-----------------------------------------------------------------------
95    void RingEmitter::setInnerSize(Real x, Real y)
96    {
97        // TODO: should really throw some exception
98        if ((x > 0) && (x < 1.0) &&
99            (y > 0) && (y < 1.0))
100            {
101            mInnerSizex = x;
102            mInnerSizey = y;
103            }
104    }
105    //-----------------------------------------------------------------------
106    void RingEmitter::setInnerSizeX(Real x)
107    {
108        assert(x > 0 && x < 1.0);
109
110        mInnerSizex = x;
111    }
112    //-----------------------------------------------------------------------
113    void RingEmitter::setInnerSizeY(Real y)
114    {
115        assert(y > 0 && y < 1.0);
116
117        mInnerSizey = y;
118    }
119    //-----------------------------------------------------------------------
120    Real RingEmitter::getInnerSizeX(void) const
121    {
122        return mInnerSizex;
123    }
124    //-----------------------------------------------------------------------
125    Real RingEmitter::getInnerSizeY(void) const
126    {
127        return mInnerSizey;
128    }
129    //-----------------------------------------------------------------------
130    //-----------------------------------------------------------------------
131    // Command objects
132    //-----------------------------------------------------------------------
133    //-----------------------------------------------------------------------
134    String RingEmitter::CmdInnerX::doGet(const void* target) const
135    {
136        return StringConverter::toString(
137            static_cast<const RingEmitter*>(target)->getInnerSizeX() );
138    }
139    void RingEmitter::CmdInnerX::doSet(void* target, const String& val)
140    {
141        static_cast<RingEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
142    }
143    //-----------------------------------------------------------------------
144    String RingEmitter::CmdInnerY::doGet(const void* target) const
145    {
146        return StringConverter::toString(
147            static_cast<const RingEmitter*>(target)->getInnerSizeY() );
148    }
149    void RingEmitter::CmdInnerY::doSet(void* target, const String& val)
150    {
151        static_cast<RingEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
152    }
153
154}
155
156
Note: See TracBrowser for help on using the repository browser.