/src/ogre/PlugIns/ParticleFX/src/OgreCylinderEmitter.cpp
Line | Count | Source |
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 (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | // Original author: Tels <http://bloodgate.com>, released as public domain |
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 | 0 | : AreaEmitter(psys) |
45 | 0 | { |
46 | 0 | initDefaults("Cylinder"); |
47 | 0 | } |
48 | | //----------------------------------------------------------------------- |
49 | | void CylinderEmitter::_initParticle(Particle* pParticle) |
50 | 0 | { |
51 | 0 | Real x, y, z; |
52 | | |
53 | | // Call superclass |
54 | 0 | 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 | 0 | while (true) |
62 | 0 | { |
63 | | /* ClearSpace not yet implemeted |
64 | | |
65 | | */ |
66 | | // three random values for one random point in 3D space |
67 | 0 | x = Math::SymmetricRandom(); |
68 | 0 | y = Math::SymmetricRandom(); |
69 | 0 | 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 | 0 | if ( x*x + y*y <= 1) |
76 | 0 | { |
77 | 0 | break; // found one valid point inside |
78 | 0 | } |
79 | 0 | } |
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 | 0 | pParticle->mPosition = mPosition + |
85 | 0 | + x * mXRange + y * mYRange + z * mZRange; |
86 | | |
87 | | // Generate complex data by reference |
88 | 0 | genEmissionColour(pParticle->mColour); |
89 | 0 | genEmissionDirection( pParticle->mPosition, pParticle->mDirection ); |
90 | 0 | genEmissionVelocity(pParticle->mDirection); |
91 | | |
92 | | // Generate simpler data |
93 | 0 | pParticle->mTimeToLive = pParticle->mTotalTimeToLive = genEmissionTTL(); |
94 | | |
95 | 0 | } |
96 | | |
97 | | } |
98 | | |
99 | | |