Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreRingEmitter.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright ) 2002 Tels <http://bloodgate.com> based on BoxEmitter
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreRingEmitter.h"
00026 #include "OgreParticle.h"
00027 #include "OgreException.h"
00028 #include "OgreStringConverter.h"
00029 
00030 
00031 /* Implements an Emitter whose emitting points all lie inside a ring.
00032 */
00033 
00034 namespace Ogre {
00035 
00036     RingEmitter::CmdInnerX RingEmitter::msCmdInnerX;
00037     RingEmitter::CmdInnerY RingEmitter::msCmdInnerY;
00038 
00039     //-----------------------------------------------------------------------
00040     RingEmitter::RingEmitter()
00041     {
00042         initDefaults("Ring");
00043         // Add custom parameters
00044         ParamDictionary* pDict = getParamDictionary();
00045 
00046         pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
00047             "shape which is hollow.", PT_REAL), &msCmdInnerX);
00048         pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
00049             "shape which is hollow.", PT_REAL), &msCmdInnerY);
00050 
00051         // default is half empty
00052         setInnerSize(0.5,0.5);
00053     }
00054     //-----------------------------------------------------------------------
00055     void RingEmitter::_initParticle(Particle* pParticle)
00056     {
00057         Real alpha, a, b, x, y, z;
00058 
00059         // Call superclass
00060         AreaEmitter::_initParticle(pParticle);
00061         // create a random angle from 0 .. PI*2
00062         alpha = Math::RangeRandom(0,Math::TWO_PI);
00063   
00064         // create two random radius values that are bigger than the inner size
00065         a = Math::RangeRandom(mInnerSizex,1.0);
00066         b = Math::RangeRandom(mInnerSizey,1.0);
00067 
00068         // with a and b we have defined a random ellipse inside the inner
00069         // ellipse and the outer circle (radius 1.0)
00070         // with alpha, and a and b we select a random point on this ellipse
00071         // and calculate it's coordinates
00072         x = a * Math::Sin(alpha);
00073         y = b * Math::Cos(alpha);
00074         // the height is simple running from 0 to 1
00075         z = Math::UnitRandom();     // 0..1
00076 
00077         // scale the found point to the ring's size and move it
00078         // relatively to the center of the emitter point
00079 
00080         pParticle->mPosition = mPosition + 
00081          + x * mXRange + y * mYRange + z * mZRange;
00082 
00083         // Generate complex data by reference
00084         genEmissionColour(pParticle->mColour);
00085         genEmissionDirection(pParticle->mDirection);
00086         genEmissionVelocity(pParticle->mDirection);
00087 
00088         // Generate simpler data
00089         pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL();
00090         
00091     }
00092     //-----------------------------------------------------------------------
00093     void RingEmitter::setInnerSize(Real x, Real y)
00094     {
00095         // TODO: should really throw some exception
00096         if ((x > 0) && (x < 1.0) &&
00097             (y > 0) && (y < 1.0))
00098             {
00099             mInnerSizex = x;
00100             mInnerSizey = y;
00101             }
00102     }
00103     //-----------------------------------------------------------------------
00104     void RingEmitter::setInnerSizeX(Real x)
00105     {
00106         assert(x > 0 && x < 1.0);
00107 
00108         mInnerSizex = x;
00109     }
00110     //-----------------------------------------------------------------------
00111     void RingEmitter::setInnerSizeY(Real y)
00112     {
00113         assert(y > 0 && y < 1.0);
00114 
00115         mInnerSizey = y;
00116     }
00117     //-----------------------------------------------------------------------
00118     Real RingEmitter::getInnerSizeX(void) const
00119     {
00120         return mInnerSizex;
00121     }
00122     //-----------------------------------------------------------------------
00123     Real RingEmitter::getInnerSizeY(void) const
00124     {
00125         return mInnerSizey;
00126     }
00127     //-----------------------------------------------------------------------
00128     //-----------------------------------------------------------------------
00129     // Command objects
00130     //-----------------------------------------------------------------------
00131     //-----------------------------------------------------------------------
00132     String RingEmitter::CmdInnerX::doGet(const void* target) const
00133     {
00134         return StringConverter::toString(
00135             static_cast<const RingEmitter*>(target)->getInnerSizeX() );
00136     }
00137     void RingEmitter::CmdInnerX::doSet(void* target, const String& val)
00138     {
00139         static_cast<RingEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
00140     }
00141     //-----------------------------------------------------------------------
00142     String RingEmitter::CmdInnerY::doGet(const void* target) const
00143     {
00144         return StringConverter::toString(
00145             static_cast<const RingEmitter*>(target)->getInnerSizeY() );
00146     }
00147     void RingEmitter::CmdInnerY::doSet(void* target, const String& val)
00148     {
00149         static_cast<RingEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
00150     }
00151 
00152 }
00153 
00154 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:25 2004