<html> <head> <title>OgreRingEmitter.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>OgreRingEmitter.cpp</h1><a href="OgreRingEmitter_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="OgreRingEmitter_8h.html">OgreRingEmitter.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 00030 00031 <font class="comment">/* Implements an Emitter whose emitting points all lie inside a ring.</font> 00032 <font class="comment">*/</font> 00033 00034 <font class="keyword">namespace </font>Ogre { 00035 <a name="l00036"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmitterq0">00036</a> <a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerX.html">RingEmitter::CmdInnerX</a> RingEmitter::msCmdInnerX; <a name="l00037"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmitterq1">00037</a> <a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerY.html">RingEmitter::CmdInnerY</a> RingEmitter::msCmdInnerY; 00038 00039 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00040"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera0">00040</a> RingEmitter::RingEmitter() 00041 { 00042 <a class="code" href="classOgre_1_1AreaEmitter.html#Ogre_1_1RingEmitterb1">initDefaults</a>(<font class="stringliteral">"Ring"</font>); 00043 <font class="comment">// Add custom parameters</font> 00044 <a class="code" href="classOgre_1_1ParamDictionary.html">ParamDictionary</a>* pDict = <a class="code" href="classOgre_1_1StringInterface.html#Ogre_1_1TTYGuiElementa79">getParamDictionary</a>(); 00045 00046 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> 00047 <font class="stringliteral">"shape which is hollow."</font>, <a class="code" href="namespaceOgre.html#a646a423">PT_REAL</a>), &<a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmitterq0">msCmdInnerX</a>); 00048 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> 00049 <font class="stringliteral">"shape which is hollow."</font>, <a class="code" href="namespaceOgre.html#a646a423">PT_REAL</a>), &<a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmitterq1">msCmdInnerY</a>); 00050 00051 <font class="comment">// default is half empty</font> 00052 <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera2">setInnerSize</a>(0.5,0.5); 00053 } 00054 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00055"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera1">00055</a> <font class="keywordtype">void</font> RingEmitter::_initParticle(<a class="code" href="classOgre_1_1Particle.html">Particle</a>* pParticle) 00056 { 00057 <a class="code" href="namespaceOgre.html#a349">Real</a> alpha, a, b, x, y, z; 00058 00059 <font class="comment">// Call superclass</font> 00060 AreaEmitter::_initParticle(pParticle); 00061 <font class="comment">// create a random angle from 0 .. PI*2</font> 00062 alpha = Math::RangeRandom(0,Math::TWO_PI); 00063 00064 <font class="comment">// create two random radius values that are bigger than the inner size</font> 00065 a = Math::RangeRandom(<a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern0">mInnerSizex</a>,1.0); 00066 b = Math::RangeRandom(<a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern1">mInnerSizey</a>,1.0); 00067 00068 <font class="comment">// with a and b we have defined a random ellipse inside the inner</font> 00069 <font class="comment">// ellipse and the outer circle (radius 1.0)</font> 00070 <font class="comment">// with alpha, and a and b we select a random point on this ellipse</font> 00071 <font class="comment">// and calculate it's coordinates</font> 00072 x = a * Math::Sin(alpha); 00073 y = b * Math::Cos(alpha); 00074 <font class="comment">// the height is simple running from 0 to 1</font> 00075 z = Math::UnitRandom(); <font class="comment">// 0..1</font> 00076 00077 <font class="comment">// scale the found point to the ring's size and move it</font> 00078 <font class="comment">// relatively to the center of the emitter point</font> 00079 00080 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> + 00081 + 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>; 00082 00083 <font class="comment">// Generate complex data by reference</font> 00084 <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>); 00085 <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>); 00086 <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>); 00087 00088 <font class="comment">// Generate simpler data</font> 00089 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>(); 00090 00091 } 00092 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00093"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera2">00093</a> <font class="keywordtype">void</font> RingEmitter::setInnerSize(<a class="code" href="namespaceOgre.html#a349">Real</a> x, <a class="code" href="namespaceOgre.html#a349">Real</a> y) 00094 { 00095 <font class="comment">// TODO: should really throw some exception</font> 00096 <font class="keywordflow">if</font> ((x > 0) && (x < 1.0) && 00097 (y > 0) && (y < 1.0)) 00098 { 00099 <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern0">mInnerSizex</a> = x; 00100 <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern1">mInnerSizey</a> = y; 00101 } 00102 } 00103 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00104"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera3">00104</a> <font class="keywordtype">void</font> RingEmitter::setInnerSizeX(<a class="code" href="namespaceOgre.html#a349">Real</a> x) 00105 { 00106 assert(x > 0 && x < 1.0); 00107 00108 <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern0">mInnerSizex</a> = x; 00109 } 00110 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00111"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera4">00111</a> <font class="keywordtype">void</font> RingEmitter::setInnerSizeY(<a class="code" href="namespaceOgre.html#a349">Real</a> y) 00112 { 00113 assert(y > 0 && y < 1.0); 00114 00115 <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern1">mInnerSizey</a> = y; 00116 } 00117 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00118"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera5">00118</a> <a class="code" href="namespaceOgre.html#a349">Real</a> RingEmitter::getInnerSizeX(<font class="keywordtype">void</font>)<font class="keyword"> const</font> 00119 <font class="keyword"> </font>{ 00120 <font class="keywordflow">return</font> <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern0">mInnerSizex</a>; 00121 } 00122 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00123"></a><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera6">00123</a> <a class="code" href="namespaceOgre.html#a349">Real</a> RingEmitter::getInnerSizeY(<font class="keywordtype">void</font>)<font class="keyword"> const</font> 00124 <font class="keyword"> </font>{ 00125 <font class="keywordflow">return</font> <a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittern1">mInnerSizey</a>; 00126 } 00127 <font class="comment">//-----------------------------------------------------------------------</font> 00128 <font class="comment">//-----------------------------------------------------------------------</font> 00129 <font class="comment">// Command objects</font> 00130 <font class="comment">//-----------------------------------------------------------------------</font> 00131 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00132"></a><a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerX.html#Ogre_1_1RingEmitter_1_1CmdInnerXa0">00132</a> <a class="code" href="classOgre_1_1String.html">String</a> RingEmitter::CmdInnerX::doGet(<font class="keyword">const</font> <font class="keywordtype">void</font>* target)<font class="keyword"> const</font> 00133 <font class="keyword"> </font>{ 00134 <font class="keywordflow">return</font> StringConverter::toString( 00135 static_cast<const RingEmitter*>(target)-><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera5">getInnerSizeX</a>() ); 00136 } <a name="l00137"></a><a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerX.html#Ogre_1_1RingEmitter_1_1CmdInnerXa1">00137</a> <font class="keywordtype">void</font> RingEmitter::CmdInnerX::doSet(<font class="keywordtype">void</font>* target, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>& val) 00138 { 00139 static_cast<RingEmitter*>(target)->setInnerSizeX(StringConverter::parseReal(val)); 00140 } 00141 <font class="comment">//-----------------------------------------------------------------------</font> <a name="l00142"></a><a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerY.html#Ogre_1_1RingEmitter_1_1CmdInnerYa0">00142</a> <a class="code" href="classOgre_1_1String.html">String</a> RingEmitter::CmdInnerY::doGet(<font class="keyword">const</font> <font class="keywordtype">void</font>* target)<font class="keyword"> const</font> 00143 <font class="keyword"> </font>{ 00144 <font class="keywordflow">return</font> StringConverter::toString( 00145 static_cast<const RingEmitter*>(target)-><a class="code" href="classOgre_1_1RingEmitter.html#Ogre_1_1RingEmittera6">getInnerSizeY</a>() ); 00146 } <a name="l00147"></a><a class="code" href="classOgre_1_1RingEmitter_1_1CmdInnerY.html#Ogre_1_1RingEmitter_1_1CmdInnerYa1">00147</a> <font class="keywordtype">void</font> RingEmitter::CmdInnerY::doSet(<font class="keywordtype">void</font>* target, <font class="keyword">const</font> <a class="code" href="classOgre_1_1String.html">String</a>& val) 00148 { 00149 static_cast<RingEmitter*>(target)->setInnerSizeY(StringConverter::parseReal(val)); 00150 } 00151 00152 } 00153 00154 </pre></div><p> Copyright © 2002-2003 by The OGRE Team<br /> Last modified Wed Jan 21 00:10:25 2004 </p> </body> </html>