Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/PlugIns/ParticleFX/src/OgreCylinderEmitter.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 3.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright ) 2002 Tels <http://bloodgate.com> based on EllipsoidEmitter
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus 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
39namespace 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
Note: See TracBrowser for help on using the repository browser.