00001
00002 #include <stdlib.h>
00003 #include <vector>
00004
00005 #include <boost/smart_ptr.hpp>
00006
00007 #include "ani/Dynamics/Particle.h"
00008 #include "ani/Dynamics/Body.h"
00009 #include "ani/Dynamics/DynamicSystem.h"
00010 #include "ani/Dynamics/Operator.h"
00011
00012
00013 #include "ani/Dynamics/operators/FlameEmitter.h"
00014 #include "ani/Dynamics/operators/ViscousDragOperator.h"
00015 #include "ani/Dynamics/operators/GrimReaperOperator.h"
00016 #include "ani/Dynamics/operators/CurrentOperator.h"
00017 #include "ani/Dynamics/operators/ColorWithAgeOperator.h"
00018 #include "ani/Dynamics/operators/GrowWithAgeOperator.h"
00019
00020 namespace ani
00021 {
00023 class FireParticle : public ani::Body
00024 {
00025 public:
00026 FireParticle() : mAge(0), mAgeOfDeath(0)
00027 {
00028 this->setParticle( true );
00029 }
00030
00031 const gmtl::Vec4f& color() const { return mColor; }
00032 void setColor( const gmtl::Vec4f& color ) { mColor = color; }
00033 void setAgeOfDeath( float age ) { mAgeOfDeath = age; }
00034 float ageOfDeath() const { return mAgeOfDeath; }
00035 float age() const { return mAge; }
00036 void growOlder( float age ) { mAge += age; }
00037 float mAge, mAgeOfDeath;
00038 gmtl::Vec4f mColor;
00039 };
00040
00042 template<class __EntityType = FireParticle>
00043 class Torch : public ani::DynamicSystem<__EntityType>
00044 {
00045 public:
00046 Torch() : ani::DynamicSystem<__EntityType>()
00047 {
00048
00049 std::vector<gmtl::Vec4f> colorTransitions;
00050 gmtl::Vec4f a;
00051 a.set( 0, 0, 181, 255 );
00052 colorTransitions.push_back( a );
00053
00054 a.set( 249, 188, 0, 255 );
00055 colorTransitions.push_back( a );
00056
00057 a.set( 249, 188, 0, 255 );
00058 colorTransitions.push_back( a );
00059
00060 a.set( 249, 117, 10, 255 );
00061 colorTransitions.push_back( a );
00062
00063 a.set( 155, 29, 29, 255 );
00064 colorTransitions.push_back( a );
00065
00066 a.set( 155, 29, 29, 255 );
00067 colorTransitions.push_back( a );
00068
00069 a.set( 131, 129, 155, 255 );
00070 colorTransitions.push_back( a );
00071
00072 a.set( 131, 129, 155, 255 );
00073 colorTransitions.push_back( a );
00074
00075 a.set( 131, 129, 155, 200 );
00076 colorTransitions.push_back( a );
00077
00078 a.set( 131, 129, 155, 128 );
00079 colorTransitions.push_back( a );
00080
00081 a.set( 131, 129, 155, 0 );
00082 colorTransitions.push_back( a );
00083
00084 for (unsigned int b = 0; b < colorTransitions.size(); ++b)
00085 {
00086 colorTransitions[b] *= 1.0f / 255.0f;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096 this->setSolver( "euler" );
00097
00098
00099 boost::shared_ptr< ViscousDragOperator<__EntityType> > drag( new ViscousDragOperator<__EntityType> );
00100 drag->setDrag( 0.40f );
00101 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( drag ) );
00102
00103 fe.reset( new FlameEmitter<__EntityType> );
00104 fe->setSize( 2.5f );
00105 fe->setAgeOfDeath( .3f );
00106 fe->setEmissionRate( 0.014 );
00107 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( fe ) );
00108
00109 boost::shared_ptr< GrimReaperOperator<__EntityType> > reaper( new GrimReaperOperator<__EntityType> );
00110 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( reaper )
00111 );
00112
00113 boost::shared_ptr< CurrentOperator<__EntityType> > cur( new CurrentOperator<__EntityType> );
00114 cur->setSpeed( gmtl::Vec3f( -1,0,0 ) );
00115 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( cur ) );
00116
00117 boost::shared_ptr< ColorWithAgeOperator<__EntityType> > cwa( new ColorWithAgeOperator<__EntityType> );
00118 cwa->setColors( colorTransitions );
00119 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( cwa ) );
00120
00121 boost::shared_ptr< GrowWithAgeOperator<__EntityType> > gwa( new GrowWithAgeOperator<__EntityType> );
00122 std::vector<float> sizes;
00123 sizes.push_back( 2.5f );
00124 sizes.push_back( 5.0f );
00125 sizes.push_back( 10.0f );
00126 gwa->setVolumes( sizes );
00127 this->push_back( boost::shared_dynamic_cast< ani::Operator<__EntityType> >( gwa ) );
00128 }
00129
00130 void setPos( const gmtl::Vec3f& pos )
00131 {
00132 fe->setPos( pos );
00133 }
00134
00135 boost::shared_ptr< FlameEmitter<__EntityType> > fe;
00136 };
00137
00138
00139 }