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

# OgreCylinderEmitter.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 EllipsoidEmitter
    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 "OgreCylinderEmitter.h"
    00026 #include "OgreParticle.h"
    00027 #include "OgreQuaternion.h"
    00028 #include "OgreException.h"
    00029 #include "OgreStringConverter.h"
    00030
    00031
    00032 /* Implements an Emitter whose emitting points all lie inside a cylinder.
    00033 */
    00034
    00035 namespace Ogre {
    00036
    00037
    00038     //-----------------------------------------------------------------------
    00039     CylinderEmitter::CylinderEmitter()
    00040     {
    00041         initDefaults("Cylinder");
    00042     }
    00043     //-----------------------------------------------------------------------
    00044     void CylinderEmitter::_initParticle(Particle* pParticle)
    00045     {
    00046         Real x, y, z;
    00047
    00048         // Call superclass
    00049         AreaEmitter::_initParticle(pParticle);
    00050
    00051         // First we create a random point inside a bounding cylinder with a
    00052         // radius and height of 1 (this is easy to do). The distance of the
    00053         // point from 0,0,0 must be <= 1 (== 1 means on the surface and we
    00054         // count this as inside, too).
    00055
    00056         while (true)
    00057         {
    00058 /* ClearSpace not yet implemeted
    00059
    00060 */
    00061                 // three random values for one random point in 3D space
    00062                 x = Math::SymmetricRandom();
    00063                 y = Math::SymmetricRandom();
    00064                 z = Math::SymmetricRandom();
    00065
    00066                 // the distance of x,y from 0,0 is sqrt(x*x+y*y), but
    00067                 // as usual we can omit the sqrt(), since sqrt(1) == 1 and we
    00068                 // use the 1 as boundary. z is not taken into account, since
    00069                 // all values in the z-direction are inside the cylinder:
    00070                 if ( x*x + y*y <= 1)
    00071                 {
    00072                         break;          // found one valid point inside
    00073                 }
    00074         }
    00075
    00076         // scale the found point to the cylinder's size and move it
    00077         // relatively to the center of the emitter point
    00078
    00079         pParticle->mPosition = mPosition +
    00080          + x * mXRange + y * mYRange + z * mZRange;
    00081
    00082         // Generate complex data by reference
    00083         genEmissionColour(pParticle->mColour);
    00084         genEmissionDirection(pParticle->mDirection);
    00085         genEmissionVelocity(pParticle->mDirection);
    00086
    00087         // Generate simpler data
    00088         pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL();
    00089
    00090     }
    00091
    00092 }
    00093
    00094

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