Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

c:/home/kevn/src/animaniac/ani/Dynamics/operators/FlameEmitter.h

Go to the documentation of this file.
00001 #ifndef FLAME_EMITTER
00002 #define FLAME_EMITTER
00003 
00004 #include "gmtl/Math.h"
00005 #include "ani/Dynamics/Operator.h"
00006 #include "ani/Dynamics/DynamicSystem.h"
00007 #include "ani/Dynamics/operators/Emitter.h"
00008 
00009 namespace ani
00010 {
00012    template<class __EntityType>
00013    class FlameEmitter : public Emitter<__EntityType>
00014    {
00015    public:
00016       typedef boost::shared_ptr<__EntityType> EntityTypePtr;
00017 
00018    public:
00019       FlameEmitter() : Emitter<__EntityType>(), 
00020                       x(0), 
00021                       velocitizer(0), 
00022                       kRandMax( RAND_MAX ), 
00023                       mSize( 8 ) 
00024       { 
00025           srand(2); 
00026       }
00027 
00028       virtual ~FlameEmitter() {}
00029       void setPos( const gmtl::Vec3f& pos )
00030       {
00031          mPos = pos;  
00032       }   
00033       void setSize( float size ) { mSize = size; }
00034       virtual void exec( DynamicSystem<__EntityType>& sys, float timeDelta )
00035       {
00036          for (x += sys.timeDelta(); x > mRate; x -= mRate )
00037          {
00038             EntityTypePtr p( new __EntityType );
00039             p->setMass( 1.0f ); // 1 kilogram
00040             float r1 = rand(), r2 = rand(), r3, r4 = rand(), r5 = rand();
00041             r1 /= kRandMax;
00042             r2 /= kRandMax;
00043             r4 /= kRandMax;
00044             r5 /= kRandMax;
00045             r3 = (r1 + r2) * 0.5f;
00046 
00047             // compute random position within the space.
00048             float posx = -mSize * 0.5f + r4 * mSize;
00049             float posz = -mSize * 0.5f + r5 * mSize;
00050 
00051             // make the velocity increase in the middle.
00052             float vely = 1.0f - gmtl::Math::Min( gmtl::Math::abs(posx / mSize), gmtl::Math::abs(posz / mSize) );
00053             const float multifactor = 3.0f;
00054 
00055             float velx = r1 * 2.0f - 1.0f;
00056             float velz = r2 * 2.0f - 1.0f;
00057             gmtl::Vec3f velocity( velx, (r3 * 1.0f + 3.8f) * (vely * multifactor), velz );
00058 
00059             gmtl::Vec3f position( posx + mPos[0], 0.0f + mPos[1], posz + mPos[2] );
00060             gmtl::Vec4f color( 0.0f, 0.0f, 0.0f, 1.0f );
00061             p->setVelocity( velocity );
00062             p->setPosition( position );
00063             p->setColor( color );
00064             p->setAgeOfDeath( mAgeOfDeath );
00065             sys.push_back( p );
00066          }
00067 
00068          if (x < 0) x = 0;
00069       }
00070 
00071       float x;
00072       float velocitizer;
00073       const float kRandMax;
00074       float mSize;
00075       gmtl::Vec3f mPos;
00076    };
00077 } // end namespace
00078 
00079 #endif

Generated on Wed Jun 12 01:54:01 2002 for Animaniac by doxygen1.2.15