| [4597] | 1 | /*! | 
|---|
| [5039] | 2 |  * @file particle_emitter.h | 
|---|
| [4836] | 3 |   *  Definition of a ParticleEmitter | 
|---|
| [3926] | 4 | */ | 
|---|
 | 5 |  | 
|---|
 | 6 | #ifndef _PARTICLE_EMITTER_H | 
|---|
 | 7 | #define _PARTICLE_EMITTER_H | 
|---|
 | 8 |  | 
|---|
 | 9 | #include "p_node.h" | 
|---|
 | 10 |  | 
|---|
| [5405] | 11 | // FORWARD DECLARATION | 
|---|
| [3926] | 12 | class ParticleSystem; | 
|---|
| [4437] | 13 | class TiXmlElement; | 
|---|
| [3926] | 14 |  | 
|---|
| [4726] | 15 | // Default values | 
|---|
 | 16 | #define PARTICLE_EMITTER_DEFAULT_SIZE              1.0 | 
|---|
 | 17 | #define PARTICLE_EMITTER_DEFAULT_EMISSION_RATE     50 | 
|---|
 | 18 | #define PARTICLE_EMITTER_DEFAULT_TYPE              EMITTER_DOT | 
|---|
 | 19 | #define PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED     0.0 | 
|---|
 | 20 | #define PARTICLE_EMITTER_DEFAULT_SPREAD            M_PI | 
|---|
 | 21 |  | 
|---|
| [4338] | 22 | //! The form of the Emitter to emit from | 
|---|
| [4597] | 23 |   typedef enum EMITTER_TYPE | 
|---|
 | 24 | { | 
|---|
 | 25 |   EMITTER_DOT     = 1, | 
|---|
 | 26 |   EMITTER_PLANE   = 2, | 
|---|
 | 27 |   EMITTER_SPHERE  = 4, | 
|---|
 | 28 |   EMITTER_CUBE    = 8 | 
|---|
 | 29 | }; | 
|---|
| [3926] | 30 |  | 
|---|
| [4381] | 31 | //! A class to handle an Emitter. | 
|---|
| [3926] | 32 | class ParticleEmitter : public PNode { | 
|---|
 | 33 |  | 
|---|
 | 34 |  public: | 
|---|
| [4176] | 35 |   ParticleEmitter(const Vector& direction, float angle = .5, | 
|---|
| [4597] | 36 |                   float emissionRate = 1.0, float velocity = 1.0); | 
|---|
| [4437] | 37 |   ParticleEmitter(const TiXmlElement* root); | 
|---|
| [4746] | 38 |   virtual ~ParticleEmitter(); | 
|---|
| [4597] | 39 |  | 
|---|
| [4726] | 40 |   void init(); | 
|---|
| [4437] | 41 |   void loadParams(const TiXmlElement* root); | 
|---|
| [3926] | 42 |  | 
|---|
| [3929] | 43 |   /* controlling the emitter: interface */ | 
|---|
| [3927] | 44 |   void start(); | 
|---|
 | 45 |   void stop(); | 
|---|
| [3932] | 46 |   void tick(float dt, ParticleSystem* system); | 
|---|
| [3927] | 47 |  | 
|---|
| [3929] | 48 |   /* controlling the behavour: these can be used as Animation interfaces */ | 
|---|
| [4338] | 49 |   void setType(EMITTER_TYPE type); | 
|---|
| [4437] | 50 |   void setType(const char* type); | 
|---|
| [4338] | 51 |   void setSize(float emitterSize); | 
|---|
| [3931] | 52 |   void setEmissionRate(float emissionRate); | 
|---|
| [4493] | 53 |   void setInheritSpeed(float value); | 
|---|
| [3931] | 54 |   void setSpread(float angle, float randomAngle = 0.0); | 
|---|
| [4338] | 55 |   void setEmissionVelocity(float velocity, float randomVelocity = 0.0); | 
|---|
| [4690] | 56 |   void setEmissionMomentum(float momentum, float randomMomentum = 0.0); | 
|---|
| [3929] | 57 |  | 
|---|
| [4726] | 58 |   void setDirection(float x, float y, float z) { this->direction = Vector(x,y,z); }; //!< todo this should be done via PNODE | 
|---|
 | 59 |  | 
|---|
| [4836] | 60 |   /** @returns the type of the emitter */ | 
|---|
| [4746] | 61 |   inline EMITTER_TYPE getType() const { return this->type; }; | 
|---|
| [4836] | 62 |   /** @returns the Type as a const char * */ | 
|---|
| [4746] | 63 |   const char* getTypeC() const; | 
|---|
| [4836] | 64 |   /** @returns the Size of the emitter */ | 
|---|
| [4746] | 65 |   inline float getSize() const { return this->emitterSize; }; | 
|---|
| [4836] | 66 |   /** @returns the emissionRate */ | 
|---|
| [4746] | 67 |   inline float getEmissionRate() const { return this->emissionRate; }; | 
|---|
| [4836] | 68 |   /** @returns the inherit-speed-factor */ | 
|---|
| [4746] | 69 |   inline float getInheritSpeed() const { return this->inheritSpeed; }; | 
|---|
| [4836] | 70 |   /** @returns the SpreadAngle of the emitter */ | 
|---|
| [4746] | 71 |   inline float getSpread() const { return this->angle; }; | 
|---|
| [4836] | 72 |   /** @returns the EmissionVelocity of the emitter */ | 
|---|
| [4746] | 73 |   inline float getEmissionVelocity() const { return this->velocity; }; | 
|---|
| [4836] | 74 |   /** @returns the EmissionMomentum of this emitter */ | 
|---|
| [4746] | 75 |   inline float getEmissionMomentum() const { return this->momentum; }; | 
|---|
| [4338] | 76 |  | 
|---|
| [4746] | 77 |   void debug() const; | 
|---|
| [3944] | 78 |  | 
|---|
| [3926] | 79 |  private: | 
|---|
| [4690] | 80 |   EMITTER_TYPE    type;              //!< The type of emitter this is. | 
|---|
 | 81 |   float           emitterSize;       //!< The size of the emitter (not for EMITTER_DOT). | 
|---|
 | 82 |   float           inheritSpeed;      //!< How much speed the particle inherits from the Emitters speed. | 
|---|
 | 83 |   Vector          direction;         //!< emition direction. | 
|---|
| [4478] | 84 |   float           angle;             //!< max angle from the direction of the emitter | 
|---|
 | 85 |   float           randomAngle;       //!< random emission angle (angle +- angleRandom is the emitted angle. | 
|---|
 | 86 |   float           emissionRate;      //!< amount of particles per seconds emitted by emitter. | 
|---|
 | 87 |   float           velocity;          //!< the initial speed of a Particles. | 
|---|
 | 88 |   float           randomVelocity;    //!< the random variation from the initial Speed. | 
|---|
| [4690] | 89 |   float           momentum;          //!< The Initial spped of the Rotation. | 
|---|
 | 90 |   float           momentumRandom;    //!< The random variation of the Momentum. | 
|---|
| [3932] | 91 |  | 
|---|
| [4478] | 92 |   float           saveTime;          //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big). | 
|---|
| [3926] | 93 | }; | 
|---|
 | 94 |  | 
|---|
 | 95 | #endif /* _PARTICLE_EMITTER_H */ | 
|---|