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

# OgreHollowEllipsoidEmitter.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 "OgreHollowEllipsoidEmitter.h"
    00026 #include "OgreParticle.h"
    00027 #include "OgreException.h"
    00028 #include "OgreStringConverter.h"
    00029 #include "OgreMath.h"
    00030
    00031 /* Implements an Emitter whose emitting points all lie inside an ellipsoid.
    00032    See <http://mathworld.wolfram.com/Ellipsoid.html> for mathematical details.
    00033
    00034   If the lengths of two axes of an ellipsoid are the same, the figure is
    00035   called a 'spheroid' (depending on whether c < a or c > a, an 'oblate
    00036   spheroid' or 'prolate spheroid', respectively), and if all three are the
    00037   same, it is a 'sphere' (ball).
    00038 */
    00039
    00040 namespace Ogre {
    00041
    00042     HollowEllipsoidEmitter::CmdInnerX HollowEllipsoidEmitter::msCmdInnerX;
    00043     HollowEllipsoidEmitter::CmdInnerY HollowEllipsoidEmitter::msCmdInnerY;
    00044     HollowEllipsoidEmitter::CmdInnerZ HollowEllipsoidEmitter::msCmdInnerZ;
    00045
    00046
    00047     //-----------------------------------------------------------------------
    00048     HollowEllipsoidEmitter::HollowEllipsoidEmitter()
    00049     {
    00050         if (initDefaults("HollowEllipsoid"))
    00051         {
    00052             // Add custom parameters
    00053             ParamDictionary* pDict = getParamDictionary();
    00054
    00055             pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the "
    00056                 "shape which is hollow.", PT_REAL), &msCmdInnerX);
    00057             pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the "
    00058                 "shape which is hollow.", PT_REAL), &msCmdInnerY);
    00059             pDict->addParameter(ParameterDef("inner_depth", "Parametric value describing the proportion of the "
    00060                 "shape which is hollow.", PT_REAL), &msCmdInnerZ);
    00061         }
    00062         // default is half empty
    00063         setInnerSize(0.5,0.5,0.5);
    00064     }
    00065     //-----------------------------------------------------------------------
    00066     void HollowEllipsoidEmitter::_initParticle(Particle* pParticle)
    00067     {
    00068         Real a, b, c, x, y, z;
    00069
    00070         // Init dimensions
    00071         pParticle->resetDimensions();
    00072
    00073         // create two random angles alpha and beta
    00074         // with these two angles, we are able to select any point on an
    00075         // ellipsoid's surface
    00076         Radian alpha ( Math::RangeRandom(0,Math::TWO_PI) );
    00077         Radian beta  ( Math::RangeRandom(0,Math::PI) );
    00078
    00079         // create three random radius values that are bigger than the inner
    00080         // size, but smaller/equal than/to the outer size 1.0 (inner size is
    00081         // between 0 and 1)
    00082         a = Math::RangeRandom(mInnerSize.x,1.0);
    00083         b = Math::RangeRandom(mInnerSize.y,1.0);
    00084         c = Math::RangeRandom(mInnerSize.z,1.0);
    00085
    00086         // with a,b,c we have defined a random ellipsoid between the inner
    00087         // ellipsoid and the outer sphere (radius 1.0)
    00088         // with alpha and beta we select on point on this random ellipsoid
    00089         // and calculate the 3D coordinates of this point
    00090         Real sinbeta ( Math::Sin(beta) );
    00091         x = a * Math::Cos(alpha) * sinbeta;
    00092         y = b * Math::Sin(alpha) * sinbeta;
    00093         z = c * Math::Cos(beta);
    00094
    00095         // scale the found point to the ellipsoid's size and move it
    00096         // relatively to the center of the emitter point
    00097
    00098         pParticle->mPosition = mPosition +
    00099          + x * mXRange + y * mYRange + z * mZRange;
    00100
    00101         // Generate complex data by reference
    00102         genEmissionColour(pParticle->mColour);
    00103         genEmissionDirection(pParticle->mDirection);
    00104         genEmissionVelocity(pParticle->mDirection);
    00105
    00106         // Generate simpler data
    00107         pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL();
    00108
    00109     }
    00110     //-----------------------------------------------------------------------
    00111     void HollowEllipsoidEmitter::setInnerSize(Real x, Real y, Real z)
    00112     {
    00113         assert((x > 0) && (x < 1.0) &&
    00114             (y > 0) && (y < 1.0) &&
    00115             (z > 0) && (z < 1.0));
    00116
    00117         mInnerSize.x = x;
    00118         mInnerSize.y = y;
    00119         mInnerSize.z = z;
    00120     }
    00121     //-----------------------------------------------------------------------
    00122     void HollowEllipsoidEmitter::setInnerSizeX(Real x)
    00123     {
    00124         assert(x > 0 && x < 1.0);
    00125
    00126         mInnerSize.x = x;
    00127     }
    00128     //-----------------------------------------------------------------------
    00129     void HollowEllipsoidEmitter::setInnerSizeY(Real y)
    00130     {
    00131         assert(y > 0 && y < 1.0);
    00132
    00133         mInnerSize.y = y;
    00134     }
    00135     //-----------------------------------------------------------------------
    00136     void HollowEllipsoidEmitter::setInnerSizeZ(Real z)
    00137     {
    00138         assert(z > 0 && z < 1.0);
    00139
    00140         mInnerSize.z = z;
    00141     }
    00142     //-----------------------------------------------------------------------
    00143     Real HollowEllipsoidEmitter::getInnerSizeX(void) const
    00144     {
    00145         return mInnerSize.x;
    00146     }
    00147     //-----------------------------------------------------------------------
    00148     Real HollowEllipsoidEmitter::getInnerSizeY(void) const
    00149     {
    00150         return mInnerSize.y;
    00151     }
    00152     //-----------------------------------------------------------------------
    00153     Real HollowEllipsoidEmitter::getInnerSizeZ(void) const
    00154     {
    00155         return mInnerSize.z;
    00156     }
    00157     //-----------------------------------------------------------------------
    00158     //-----------------------------------------------------------------------
    00159     // Command objects
    00160     //-----------------------------------------------------------------------
    00161     //-----------------------------------------------------------------------
    00162     String HollowEllipsoidEmitter::CmdInnerX::doGet(const void* target) const
    00163     {
    00164         return StringConverter::toString(
    00165             static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeX() );
    00166     }
    00167     void HollowEllipsoidEmitter::CmdInnerX::doSet(void* target, const String& val)
    00168     {
    00169         static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val));
    00170     }
    00171     //-----------------------------------------------------------------------
    00172     String HollowEllipsoidEmitter::CmdInnerY::doGet(const void* target) const
    00173     {
    00174         return StringConverter::toString(
    00175             static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeY() );
    00176     }
    00177     void HollowEllipsoidEmitter::CmdInnerY::doSet(void* target, const String& val)
    00178     {
    00179         static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val));
    00180     }
    00181     //-----------------------------------------------------------------------
    00182     String HollowEllipsoidEmitter::CmdInnerZ::doGet(const void* target) const
    00183     {
    00184         return StringConverter::toString(
    00185             static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeZ() );
    00186     }
    00187     void HollowEllipsoidEmitter::CmdInnerZ::doSet(void* target, const String& val)
    00188     {
    00189         static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeZ(StringConverter::parseReal(val));
    00190     }
    00191
    00192
    00193 }
    00194
    00195

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