source: OGRE/trunk/ogrenew/PlugIns/ParticleFX/src/OgreEllipsoidEmitter.cpp @ 692

Revision 692, 3.5 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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