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