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         if (initDefaults("Ring"))
00043         {
00044             // Add custom parameters
00045             ParamDictionary* pDict = getParamDictionary();
00046 
00047             pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
00048                 "shape which is hollow.", PT_REAL), &msCmdInnerX);
00049             pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
00050                 "shape which is hollow.", PT_REAL), &msCmdInnerY);
00051         }
00052         // default is half empty
00053         setInnerSize(0.5,0.5);
00054     }
00055     //-----------------------------------------------------------------------
00056     void RingEmitter::_initParticle(Particle* pParticle)
00057     {
00058         Real a, b, x, y, z;
00059 
00060         // Call superclass
00061         AreaEmitter::_initParticle(pParticle);
00062         // create a random angle from 0 .. PI*2
00063         Radian alpha ( Math::RangeRandom(0,Math::TWO_PI) );
00064   
00065         // create two random radius values that are bigger than the inner size
00066         a = Math::RangeRandom(mInnerSizex,1.0);
00067         b = Math::RangeRandom(mInnerSizey,1.0);
00068 
00069         // with a and b we have defined a random ellipse inside the inner
00070         // ellipse and the outer circle (radius 1.0)
00071         // with alpha, and a and b we select a random point on this ellipse
00072         // and calculate it's coordinates
00073         x = a * Math::Sin(alpha);
00074         y = b * Math::Cos(alpha);
00075         // the height is simple -1 to 1
00076         z = Math::SymmetricRandom();     
00077 
00078         // scale the found point to the ring's size and move it
00079         // relatively to the center of the emitter point
00080 
00081         pParticle->mPosition = mPosition + 
00082          + x * mXRange + y * mYRange + z * mZRange;
00083 
00084         // Generate complex data by reference
00085         genEmissionColour(pParticle->mColour);
00086         genEmissionDirection(pParticle->mDirection);
00087         genEmissionVelocity(pParticle->mDirection);
00088 
00089         // Generate simpler data
00090         pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL();
00091         
00092     }
00093     //-----------------------------------------------------------------------
00094     void RingEmitter::setInnerSize(Real x, Real y)
00095     {
00096         // TODO: should really throw some exception
00097         if ((x > 0) && (x < 1.0) &&
00098             (y > 0) && (y < 1.0))
00099             {
00100             mInnerSizex = x;
00101             mInnerSizey = y;
00102             }
00103     }
00104     //-----------------------------------------------------------------------
00105     void RingEmitter::setInnerSizeX(Real x)
00106     {
00107         assert(x > 0 && x < 1.0);
00108 
00109         mInnerSizex = x;
00110     }
00111     //-----------------------------------------------------------------------
00112     void RingEmitter::setInnerSizeY(Real y)
00113     {
00114         assert(y > 0 && y < 1.0);
00115 
00116         mInnerSizey = y;
00117     }
00118     //-----------------------------------------------------------------------
00119     Real RingEmitter::getInnerSizeX(void) const
00120     {
00121         return mInnerSizex;
00122     }
00123     //-----------------------------------------------------------------------
00124     Real RingEmitter::getInnerSizeY(void) const
00125     {
00126         return mInnerSizey;
00127     }
00128     //-----------------------------------------------------------------------
00129     //-----------------------------------------------------------------------
00130     // Command objects
00131     //-----------------------------------------------------------------------
00132     //-----------------------------------------------------------------------
00133     String RingEmitter::CmdInnerX::doGet(const void* target) const
00134     {
00135         return StringConverter::toString(
00136             static_cast<const RingEmitter*>(target)->getInnerSizeX() );
00137     }
00138     void RingEmitter::CmdInnerX::doSet(void* target, const String& val)
00139     {
00140         static_cast<RingEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
00141     }
00142     //-----------------------------------------------------------------------
00143     String RingEmitter::CmdInnerY::doGet(const void* target) const
00144     {
00145         return StringConverter::toString(
00146             static_cast<const RingEmitter*>(target)->getInnerSizeY() );
00147     }
00148     void RingEmitter::CmdInnerY::doSet(void* target, const String& val)
00149     {
00150         static_cast<RingEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
00151     }
00152 
00153 }
00154 
00155 

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:43 2004