<html> <head> <title>OgreHollowEllipsoidEmitter.cpp Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link type="text/css" rel="stylesheet" href="style.css"> </head> <body> <!-- Generated by Doxygen 1.2.16 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>OgreHollowEllipsoidEmitter.cpp</h1><a href="OgreHollowEllipsoidEmitter_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font> 00002 <font class="comment">-----------------------------------------------------------------------------</font> 00003 <font class="comment">This source file is part of OGRE</font> 00004 <font class="comment"> (Object-oriented Graphics Rendering Engine)</font> 00005 <font class="comment">For the latest info, see http://www.ogre3d.org/</font> 00006 <font class="comment"></font> 00007 <font class="comment">Copyright ) 2002 Tels <http://bloodgate.com> based on BoxEmitter</font> 00008 <font class="comment">Also see acknowledgements in Readme.html</font> 00009 <font class="comment"></font> 00010 <font class="comment">This program is free software; you can redistribute it and/or modify it under</font> 00011 <font class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</font> 00012 <font class="comment">Foundation; either version 2 of the License, or (at your option) any later</font> 00013 <font class="comment">version.</font> 00014 <font class="comment"></font> 00015 <font class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</font> 00016 <font class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</font> 00017 <font class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</font> 00018 <font class="comment"></font> 00019 <font class="comment">You should have received a copy of the GNU Lesser General Public License along with</font> 00020 <font class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</font> 00021 <font class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</font> 00022 <font class="comment">http://www.gnu.org/copyleft/lesser.txt.</font> 00023 <font class="comment">-----------------------------------------------------------------------------</font> 00024 <font class="comment">*/</font> 00025 <font class="preprocessor">#include "<a class="code" href="OgreHollowEllipsoidEmitter_8h.html">OgreHollowEllipsoidEmitter.h</a>"</font> 00026 <font class="preprocessor">#include "<a class="code" href="OgreParticle_8h.html">OgreParticle.h</a>"</font> 00027 <font class="preprocessor">#include "<a class="code" href="OgreException_8h.html">OgreException.h</a>"</font> 00028 <font class="preprocessor">#include "<a class="code" href="OgreStringConverter_8h.html">OgreStringConverter.h</a>"</font> 00029 <font class="preprocessor">#include "<a class="code" href="OgreMath_8h.html">OgreMath.h</a>"</font> 00030 00031 <font class="comment">/* Implements an Emitter whose emitting points all lie inside an ellipsoid.</font> 00032 <font class="comment"> See <http://mathworld.wolfram.com/Ellipsoid.html> for mathematical details.</font> 00033 <font class="comment"></font> 00034 <font class="comment"> If the lengths of two axes of an ellipsoid are the same, the figure is</font> 00035 <font class="comment"> called a 'spheroid' (depending on whether c < a or c > a, an 'oblate</font> 00036 <font class="comment"> spheroid' or 'prolate spheroid', respectively), and if all three are the</font> 00037 <font class="comment"> same, it is a 'sphere' (ball).</font> 00038 <font class="comment">*/</font> 00039 00040 <font class="keyword">namespace </font>Ogre { 00041 <a name="l00042"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq0">00042</a> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerX.html">HollowEllipsoidEmitter::CmdInnerX</a> HollowEllipsoidEmitter::msCmdInnerX; <a name="l00043"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq1">00043</a> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerY.html">HollowEllipsoidEmitter::CmdInnerY</a> HollowEllipsoidEmitter::msCmdInnerY; <a name="l00044"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq2">00044</a> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerZ.html">HollowEllipsoidEmitter::CmdInnerZ</a> HollowEllipsoidEmitter::msCmdInnerZ; 00045 00046 00047 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00048"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera0">00048</a> HollowEllipsoidEmitter::HollowEllipsoidEmitter() 00049 { 00050 <a class="code" href="classOgre_1_1AreaEmitter.html#Ogre_1_1RingEmitterb1">initDefaults</a>(<font class="stringliteral">"HollowEllipsoid"</font>); 00051 <font class="comment">// Add custom parameters</font> 00052 <a class="code" href="classOgre_1_1ParamDictionary.html">ParamDictionary</a>* pDict = <a class="code" href="classOgre_1_1StringInterface.html#Ogre_1_1TTYGuiElementa79">getParamDictionary</a>(); 00053 00054 pDict-><a class="code" href="classOgre_1_1ParamDictionary.html#Ogre_1_1ParamDictionarya1">addParameter</a>(<a class="code" href="classOgre_1_1ParameterDef.html">ParameterDef</a>(<font class="stringliteral">"inner_width"</font>, <font class="stringliteral">"Parametric value describing the proportion of the "</font> 00055 <font class="stringliteral">"shape which is hollow."</font>, <a class="code" href="namespaceOgre.html#a646a423">PT_REAL</a>), &<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq0">msCmdInnerX</a>); 00056 pDict-><a class="code" href="classOgre_1_1ParamDictionary.html#Ogre_1_1ParamDictionarya1">addParameter</a>(<a class="code" href="classOgre_1_1ParameterDef.html">ParameterDef</a>(<font class="stringliteral">"inner_height"</font>, <font class="stringliteral">"Parametric value describing the proportion of the "</font> 00057 <font class="stringliteral">"shape which is hollow."</font>, <a class="code" href="namespaceOgre.html#a646a423">PT_REAL</a>), &<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq1">msCmdInnerY</a>); 00058 pDict-><a class="code" href="classOgre_1_1ParamDictionary.html#Ogre_1_1ParamDictionarya1">addParameter</a>(<a class="code" href="classOgre_1_1ParameterDef.html">ParameterDef</a>(<font class="stringliteral">"inner_depth"</font>, <font class="stringliteral">"Parametric value describing the proportion of the "</font> 00059 <font class="stringliteral">"shape which is hollow."</font>, <a class="code" href="namespaceOgre.html#a646a423">PT_REAL</a>), &<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmitterq2">msCmdInnerZ</a>); 00060 00061 <font class="comment">// default is half empty</font> 00062 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera2">setInnerSize</a>(0.5,0.5,0.5); 00063 } 00064 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00065"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera1">00065</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::_initParticle(<a class="code" href="classOgre_1_1Particle.html">Particle</a>* pParticle) 00066 { 00067 <a class="code" href="namespaceOgre.html#a349">Real</a> alpha, beta, a, b, c, x, y, z; 00068 00069 <font class="comment">// Init dimensions</font> 00070 pParticle-><a class="code" href="classOgre_1_1Billboard.html#Ogre_1_1Particlea9">resetDimensions</a>(); 00071 00072 <font class="comment">// create two random angles alpha and beta</font> 00073 <font class="comment">// with these two angles, we are able to select any point on an</font> 00074 <font class="comment">// ellipsoid's surface</font> 00075 alpha = Math::RangeRandom(0,Math::TWO_PI); 00076 beta = Math::RangeRandom(0,Math::PI); 00077 00078 <font class="comment">// create three random radius values that are bigger than the inner</font> 00079 <font class="comment">// size, but smaller/equal than/to the outer size 1.0 (inner size is</font> 00080 <font class="comment">// between 0 and 1)</font> 00081 a = Math::RangeRandom(<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m0">x</a>,1.0); 00082 b = Math::RangeRandom(<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m1">y</a>,1.0); 00083 c = Math::RangeRandom(<a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m2">z</a>,1.0); 00084 00085 <font class="comment">// with a,b,c we have defined a random ellipsoid between the inner</font> 00086 <font class="comment">// ellipsoid and the outer sphere (radius 1.0)</font> 00087 <font class="comment">// with alpha and beta we select on point on this random ellipsoid</font> 00088 <font class="comment">// and calculate the 3D coordinates of this point</font> 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 <font class="comment">// scale the found point to the ellipsoid's size and move it</font> 00094 <font class="comment">// relatively to the center of the emitter point</font> 00095 00096 pParticle-><a class="code" href="classOgre_1_1Billboard.html#Ogre_1_1Particlem3">mPosition</a> = <a class="code" href="classOgre_1_1ParticleEmitter.html#Ogre_1_1RingEmittern6">mPosition</a> + 00097 + x * <a class="code" href="classOgre_1_1AreaEmitter.html#Ogre_1_1RingEmittern3">mXRange</a> + y * <a class="code" href="classOgre_1_1AreaEmitter.html#Ogre_1_1RingEmittern4">mYRange</a> + z * <a class="code" href="classOgre_1_1AreaEmitter.html#Ogre_1_1RingEmittern5">mZRange</a>; 00098 00099 <font class="comment">// Generate complex data by reference</font> 00100 <a class="code" href="classOgre_1_1ParticleEmitter.html#Ogre_1_1RingEmitterb5">genEmissionColour</a>(pParticle-><a class="code" href="classOgre_1_1Billboard.html#Ogre_1_1Particlem6">mColour</a>); 00101 <a class="code" href="classOgre_1_1ParticleEmitter.html#Ogre_1_1RingEmitterb2">genEmissionDirection</a>(pParticle-><a class="code" href="classOgre_1_1Billboard.html#Ogre_1_1Particlem4">mDirection</a>); 00102 <a class="code" href="classOgre_1_1ParticleEmitter.html#Ogre_1_1RingEmitterb3">genEmissionVelocity</a>(pParticle-><a class="code" href="classOgre_1_1Billboard.html#Ogre_1_1Particlem4">mDirection</a>); 00103 00104 <font class="comment">// Generate simpler data</font> 00105 pParticle-><a class="code" href="classOgre_1_1Particle.html#Ogre_1_1Particlem0">mTimeToLive</a> = pParticle-><a class="code" href="classOgre_1_1Particle.html#Ogre_1_1Particlem1">mTotalTimeToLive</a> = <a class="code" href="classOgre_1_1ParticleEmitter.html#Ogre_1_1RingEmitterb4">genEmissionTTL</a>(); 00106 00107 } 00108 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00109"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera2">00109</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::setInnerSize(<a class="code" href="namespaceOgre.html#a349">Real</a> x, <a class="code" href="namespaceOgre.html#a349">Real</a> y, <a class="code" href="namespaceOgre.html#a349">Real</a> z) 00110 { 00111 assert((x > 0) && (x < 1.0) && 00112 (y > 0) && (y < 1.0) && 00113 (z > 0) && (z < 1.0)); 00114 00115 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m0">x</a> = x; 00116 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m1">y</a> = y; 00117 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m2">z</a> = z; 00118 } 00119 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00120"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera3">00120</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::setInnerSizeX(<a class="code" href="namespaceOgre.html#a349">Real</a> x) 00121 { 00122 assert(x > 0 && x < 1.0); 00123 00124 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m0">x</a> = x; 00125 } 00126 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00127"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera4">00127</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::setInnerSizeY(<a class="code" href="namespaceOgre.html#a349">Real</a> y) 00128 { 00129 assert(y > 0 && y < 1.0); 00130 00131 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m1">y</a> = y; 00132 } 00133 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00134"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera5">00134</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::setInnerSizeZ(<a class="code" href="namespaceOgre.html#a349">Real</a> z) 00135 { 00136 assert(z > 0 && z < 1.0); 00137 00138 <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m2">z</a> = z; 00139 } 00140 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00141"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera6">00141</a> <a class="code" href="namespaceOgre.html#a349">Real</a> HollowEllipsoidEmitter::getInnerSizeX(<font class="keywordtype">void</font>)<font class="keyword"> const</font> 00142 <font class="keyword"> </font>{ 00143 <font class="keywordflow">return</font> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m0">x</a>; 00144 } 00145 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00146"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera7">00146</a> <a class="code" href="namespaceOgre.html#a349">Real</a> HollowEllipsoidEmitter::getInnerSizeY(<font class="keywordtype">void</font>)<font class="keyword"> const</font> 00147 <font class="keyword"> </font>{ 00148 <font class="keywordflow">return</font> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m1">y</a>; 00149 } 00150 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00151"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera8">00151</a> <a class="code" href="namespaceOgre.html#a349">Real</a> HollowEllipsoidEmitter::getInnerSizeZ(<font class="keywordtype">void</font>)<font class="keyword"> const</font> 00152 <font class="keyword"> </font>{ 00153 <font class="keywordflow">return</font> <a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittern0">mInnerSize</a>.<a class="code" href="classOgre_1_1Vector3.html#Ogre_1_1Vector3m2">z</a>; 00154 } 00155 <font class="comment">//-----------------------------------------------------------------------</font> 00156 <font class="comment">//-----------------------------------------------------------------------</font> 00157 <font class="comment">// Command objects</font> 00158 <font class="comment">//-----------------------------------------------------------------------</font> 00159 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00160"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerX.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerXa0">00160</a> <a class="code" href="classOgre_1_1String.html">String</a> HollowEllipsoidEmitter::CmdInnerX::doGet(<font class="keyword">const</font> <font class="keywordtype">void</font>* target)<font class="keyword"> const</font> 00161 <font class="keyword"> </font>{ 00162 <font class="keywordflow">return</font> StringConverter::toString( 00163 static_cast<const HollowEllipsoidEmitter*>(target)-><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera6">getInnerSizeX</a>() ); 00164 } <a name="l00165"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerX.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerXa1">00165</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::CmdInnerX::doSet(<font class="keywordtype">void</font>* target, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>& val) 00166 { 00167 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val)); 00168 } 00169 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00170"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerY.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerYa0">00170</a> <a class="code" href="classOgre_1_1String.html">String</a> HollowEllipsoidEmitter::CmdInnerY::doGet(<font class="keyword">const</font> <font class="keywordtype">void</font>* target)<font class="keyword"> const</font> 00171 <font class="keyword"> </font>{ 00172 <font class="keywordflow">return</font> StringConverter::toString( 00173 static_cast<const HollowEllipsoidEmitter*>(target)-><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera7">getInnerSizeY</a>() ); 00174 } <a name="l00175"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerY.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerYa1">00175</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::CmdInnerY::doSet(<font class="keywordtype">void</font>* target, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>& val) 00176 { 00177 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val)); 00178 } 00179 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00180"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerZ.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerZa0">00180</a> <a class="code" href="classOgre_1_1String.html">String</a> HollowEllipsoidEmitter::CmdInnerZ::doGet(<font class="keyword">const</font> <font class="keywordtype">void</font>* target)<font class="keyword"> const</font> 00181 <font class="keyword"> </font>{ 00182 <font class="keywordflow">return</font> StringConverter::toString( 00183 static_cast<const HollowEllipsoidEmitter*>(target)-><a class="code" href="classOgre_1_1HollowEllipsoidEmitter.html#Ogre_1_1HollowEllipsoidEmittera8">getInnerSizeZ</a>() ); 00184 } <a name="l00185"></a><a class="code" href="classOgre_1_1HollowEllipsoidEmitter_1_1CmdInnerZ.html#Ogre_1_1HollowEllipsoidEmitter_1_1CmdInnerZa1">00185</a> <font class="keywordtype">void</font> HollowEllipsoidEmitter::CmdInnerZ::doSet(<font class="keywordtype">void</font>* target, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>& val) 00186 { 00187 static_cast<HollowEllipsoidEmitter*>(target)->setInnerSizeZ(StringConverter::parseReal(val)); 00188 } 00189 00190 00191 } 00192 00193 </pre></div><p> Copyright © 2002-2003 by The OGRE Team<br /> Last modified Wed Jan 21 00:10:14 2004 </p> </body> </html>