1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright ) 2002 Tels <http://bloodgate.com> based on EllipsoidEmitter |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreCylinderEmitter.h" |
---|
30 | #include "OgreParticle.h" |
---|
31 | #include "OgreQuaternion.h" |
---|
32 | #include "OgreException.h" |
---|
33 | #include "OgreStringConverter.h" |
---|
34 | |
---|
35 | |
---|
36 | /* Implements an Emitter whose emitting points all lie inside a cylinder. |
---|
37 | */ |
---|
38 | |
---|
39 | namespace Ogre { |
---|
40 | |
---|
41 | |
---|
42 | //----------------------------------------------------------------------- |
---|
43 | CylinderEmitter::CylinderEmitter(ParticleSystem* psys) |
---|
44 | : AreaEmitter(psys) |
---|
45 | { |
---|
46 | initDefaults("Cylinder"); |
---|
47 | } |
---|
48 | //----------------------------------------------------------------------- |
---|
49 | void CylinderEmitter::_initParticle(Particle* pParticle) |
---|
50 | { |
---|
51 | Real x, y, z; |
---|
52 | |
---|
53 | // Call superclass |
---|
54 | AreaEmitter::_initParticle(pParticle); |
---|
55 | |
---|
56 | // First we create a random point inside a bounding cylinder with a |
---|
57 | // radius and height of 1 (this is easy to do). The distance of the |
---|
58 | // point from 0,0,0 must be <= 1 (== 1 means on the surface and we |
---|
59 | // count this as inside, too). |
---|
60 | |
---|
61 | while (true) |
---|
62 | { |
---|
63 | /* ClearSpace not yet implemeted |
---|
64 | |
---|
65 | */ |
---|
66 | // three random values for one random point in 3D space |
---|
67 | x = Math::SymmetricRandom(); |
---|
68 | y = Math::SymmetricRandom(); |
---|
69 | z = Math::SymmetricRandom(); |
---|
70 | |
---|
71 | // the distance of x,y from 0,0 is sqrt(x*x+y*y), but |
---|
72 | // as usual we can omit the sqrt(), since sqrt(1) == 1 and we |
---|
73 | // use the 1 as boundary. z is not taken into account, since |
---|
74 | // all values in the z-direction are inside the cylinder: |
---|
75 | if ( x*x + y*y <= 1) |
---|
76 | { |
---|
77 | break; // found one valid point inside |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | // scale the found point to the cylinder's size and move it |
---|
82 | // relatively to the center of the emitter point |
---|
83 | |
---|
84 | pParticle->position = mPosition + |
---|
85 | + x * mXRange + y * mYRange + z * mZRange; |
---|
86 | |
---|
87 | // Generate complex data by reference |
---|
88 | genEmissionColour(pParticle->colour); |
---|
89 | genEmissionDirection(pParticle->direction); |
---|
90 | genEmissionVelocity(pParticle->direction); |
---|
91 | |
---|
92 | // Generate simpler data |
---|
93 | pParticle->timeToLive = pParticle->totalTimeToLive = genEmissionTTL(); |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | |
---|