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 "OgreEllipsoidEmitter.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 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 00043 //----------------------------------------------------------------------- 00044 EllipsoidEmitter::EllipsoidEmitter() 00045 { 00046 initDefaults("Ellipsoid"); 00047 } 00048 //----------------------------------------------------------------------- 00049 void EllipsoidEmitter::_initParticle(Particle* pParticle) 00050 { 00051 Real x, y, z; 00052 00053 // Call superclass 00054 AreaEmitter::_initParticle(pParticle); 00055 // First we create a random point inside a bounding sphere with a 00056 // radius of 1 (this is easy to do). The distance of the point from 00057 // 0,0,0 must be <= 1 (== 1 means on the surface and we count this as 00058 // inside, too). 00059 00060 while (true) 00061 { 00062 // three random values for one random point in 3D space 00063 00064 x = Math::SymmetricRandom(); 00065 y = Math::SymmetricRandom(); 00066 z = Math::SymmetricRandom(); 00067 00068 // the distance of x,y,z from 0,0,0 is sqrt(x*x+y*y+z*z), but 00069 // as usual we can omit the sqrt(), since sqrt(1) == 1 and we 00070 // use the 1 as boundary: 00071 if ( x*x + y*y + z*z <= 1) 00072 { 00073 break; // found one valid point inside 00074 } 00075 } 00076 00077 // scale the found point to the ellipsoid'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 } 00094 00095
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:07 2004