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 initDefaults("HollowEllipsoid"); 00051 // Add custom parameters 00052 ParamDictionary* pDict = getParamDictionary(); 00053 00054 pDict->addParameter(ParameterDef("inner_width", "Parametric value describing the proportion of the " 00055 "shape which is hollow.", PT_REAL), &msCmdInnerX); 00056 pDict->addParameter(ParameterDef("inner_height", "Parametric value describing the proportion of the " 00057 "shape which is hollow.", PT_REAL), &msCmdInnerY); 00058 pDict->addParameter(ParameterDef("inner_depth", "Parametric value describing the proportion of the " 00059 "shape which is hollow.", PT_REAL), &msCmdInnerZ); 00060 00061 // default is half empty 00062 setInnerSize(0.5,0.5,0.5); 00063 } 00064 //----------------------------------------------------------------------- 00065 void HollowEllipsoidEmitter::_initParticle(Particle* pParticle) 00066 { 00067 Real alpha, beta, a, b, c, x, y, z; 00068 00069 // Init dimensions 00070 pParticle->resetDimensions(); 00071 00072 // create two random angles alpha and beta 00073 // with these two angles, we are able to select any point on an 00074 // ellipsoid's surface 00075 alpha = Math::RangeRandom(0,Math::TWO_PI); 00076 beta = Math::RangeRandom(0,Math::PI); 00077 00078 // create three random radius values that are bigger than the inner 00079 // size, but smaller/equal than/to the outer size 1.0 (inner size is 00080 // between 0 and 1) 00081 a = Math::RangeRandom(mInnerSize.x,1.0); 00082 b = Math::RangeRandom(mInnerSize.y,1.0); 00083 c = Math::RangeRandom(mInnerSize.z,1.0); 00084 00085 // with a,b,c we have defined a random ellipsoid between the inner 00086 // ellipsoid and the outer sphere (radius 1.0) 00087 // with alpha and beta we select on point on this random ellipsoid 00088 // and calculate the 3D coordinates of this point 00089 x = a * Math::Cos(alpha) * Math::Sin(beta); 00090 y = b * Math::Sin(alpha) * Math::Sin(beta); 00091 z = c * Math::Cos(beta); 00092 00093 // scale the found point to the ellipsoid's size and move it 00094 // relatively to the center of the emitter point 00095 00096 pParticle->mPosition = mPosition + 00097 + x * mXRange + y * mYRange + z * mZRange; 00098 00099 // Generate complex data by reference 00100 genEmissionColour(pParticle->mColour); 00101 genEmissionDirection(pParticle->mDirection); 00102 genEmissionVelocity(pParticle->mDirection); 00103 00104 // Generate simpler data 00105 pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL(); 00106 00107 } 00108 //----------------------------------------------------------------------- 00109 void HollowEllipsoidEmitter::setInnerSize(Real x, Real y, Real z) 00110 { 00111 assert((x > 0) && (x < 1.0) && 00112 (y > 0) && (y < 1.0) && 00113 (z > 0) && (z < 1.0)); 00114 00115 mInnerSize.x = x; 00116 mInnerSize.y = y; 00117 mInnerSize.z = z; 00118 } 00119 //----------------------------------------------------------------------- 00120 void HollowEllipsoidEmitter::setInnerSizeX(Real x) 00121 { 00122 assert(x > 0 && x < 1.0); 00123 00124 mInnerSize.x = x; 00125 } 00126 //----------------------------------------------------------------------- 00127 void HollowEllipsoidEmitter::setInnerSizeY(Real y) 00128 { 00129 assert(y > 0 && y < 1.0); 00130 00131 mInnerSize.y = y; 00132 } 00133 //----------------------------------------------------------------------- 00134 void HollowEllipsoidEmitter::setInnerSizeZ(Real z) 00135 { 00136 assert(z > 0 && z < 1.0); 00137 00138 mInnerSize.z = z; 00139 } 00140 //----------------------------------------------------------------------- 00141 Real HollowEllipsoidEmitter::getInnerSizeX(void) const 00142 { 00143 return mInnerSize.x; 00144 } 00145 //----------------------------------------------------------------------- 00146 Real HollowEllipsoidEmitter::getInnerSizeY(void) const 00147 { 00148 return mInnerSize.y; 00149 } 00150 //----------------------------------------------------------------------- 00151 Real HollowEllipsoidEmitter::getInnerSizeZ(void) const 00152 { 00153 return mInnerSize.z; 00154 } 00155 //----------------------------------------------------------------------- 00156 //----------------------------------------------------------------------- 00157 // Command objects 00158 //----------------------------------------------------------------------- 00159 //----------------------------------------------------------------------- 00160 String HollowEllipsoidEmitter::CmdInnerX::doGet(const void* target) const 00161 { 00162 return StringConverter::toString( 00163 static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeX() ); 00164 } 00165 void HollowEllipsoidEmitter::CmdInnerX::doSet(void* target, const String& val) 00166 { 00167 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val)); 00168 } 00169 //----------------------------------------------------------------------- 00170 String HollowEllipsoidEmitter::CmdInnerY::doGet(const void* target) const 00171 { 00172 return StringConverter::toString( 00173 static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeY() ); 00174 } 00175 void HollowEllipsoidEmitter::CmdInnerY::doSet(void* target, const String& val) 00176 { 00177 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val)); 00178 } 00179 //----------------------------------------------------------------------- 00180 String HollowEllipsoidEmitter::CmdInnerZ::doGet(const void* target) const 00181 { 00182 return StringConverter::toString( 00183 static_cast<const HollowEllipsoidEmitter*>(target)->getInnerSizeZ() ); 00184 } 00185 void HollowEllipsoidEmitter::CmdInnerZ::doSet(void* target, const String& val) 00186 { 00187 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeZ(StringConverter::parseReal(val)); 00188 } 00189 00190 00191 } 00192 00193
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:17 2004