[692] | 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 | */
|
---|
| 25 | #include "OgreCylinderEmitter.h"
|
---|
| 26 | #include "OgreParticle.h"
|
---|
| 27 | #include "OgreQuaternion.h"
|
---|
| 28 | #include "OgreException.h"
|
---|
| 29 | #include "OgreStringConverter.h"
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | /* Implements an Emitter whose emitting points all lie inside a cylinder.
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | namespace Ogre {
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | //-----------------------------------------------------------------------
|
---|
| 39 | CylinderEmitter::CylinderEmitter(ParticleSystem* psys)
|
---|
| 40 | : AreaEmitter(psys)
|
---|
| 41 | {
|
---|
| 42 | initDefaults("Cylinder");
|
---|
| 43 | }
|
---|
| 44 | //-----------------------------------------------------------------------
|
---|
| 45 | void CylinderEmitter::_initParticle(Particle* pParticle)
|
---|
| 46 | {
|
---|
| 47 | Real x, y, z;
|
---|
| 48 |
|
---|
| 49 | // Call superclass
|
---|
| 50 | AreaEmitter::_initParticle(pParticle);
|
---|
| 51 |
|
---|
| 52 | // First we create a random point inside a bounding cylinder with a
|
---|
| 53 | // radius and height of 1 (this is easy to do). The distance of the
|
---|
| 54 | // point from 0,0,0 must be <= 1 (== 1 means on the surface and we
|
---|
| 55 | // count this as inside, too).
|
---|
| 56 |
|
---|
| 57 | while (true)
|
---|
| 58 | {
|
---|
| 59 | /* ClearSpace not yet implemeted
|
---|
| 60 |
|
---|
| 61 | */
|
---|
| 62 | // three random values for one random point in 3D space
|
---|
| 63 | x = Math::SymmetricRandom();
|
---|
| 64 | y = Math::SymmetricRandom();
|
---|
| 65 | z = Math::SymmetricRandom();
|
---|
| 66 |
|
---|
| 67 | // the distance of x,y from 0,0 is sqrt(x*x+y*y), but
|
---|
| 68 | // as usual we can omit the sqrt(), since sqrt(1) == 1 and we
|
---|
| 69 | // use the 1 as boundary. z is not taken into account, since
|
---|
| 70 | // all values in the z-direction are inside the cylinder:
|
---|
| 71 | if ( x*x + y*y <= 1)
|
---|
| 72 | {
|
---|
| 73 | break; // found one valid point inside
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // scale the found point to the cylinder's size and move it
|
---|
| 78 | // relatively to the center of the emitter point
|
---|
| 79 |
|
---|
| 80 | pParticle->position = mPosition +
|
---|
| 81 | + x * mXRange + y * mYRange + z * mZRange;
|
---|
| 82 |
|
---|
| 83 | // Generate complex data by reference
|
---|
| 84 | genEmissionColour(pParticle->colour);
|
---|
| 85 | genEmissionDirection(pParticle->direction);
|
---|
| 86 | genEmissionVelocity(pParticle->direction);
|
---|
| 87 |
|
---|
| 88 | // Generate simpler data
|
---|
| 89 | pParticle->timeToLive = pParticle->totalTimeToLive = genEmissionTTL();
|
---|
| 90 |
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|