/*! \file particle_system.h */ #ifndef _PARTICLE_SYSTEM_H #define _PARTICLE_SYSTEM_H #include "base_object.h" #include "physics_interface.h" #include "glincl.h" #include "vector.h" #define PARTICLE_DOT_MASK 0x000001 #define PARTICLE_SPARK_MASK 0x000010 #define PARTICLE_SPRITE_MASK 0x000100 #define PARTICLE_MODEL_MASK 0x001000 #define PARTICLE_WORDL_ENTITY_MASK 0x010000 #define PARTICLE_MULTI_MASK 0x100000 //! An enumerator for the different types of particles. typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, PARTICLE_SPARK = PARTICLE_SPARK_MASK, PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, PARTICLE_MODEL = PARTICLE_MODEL_MASK, PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK}; #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< a default count of particles in the system. #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. // FORWARD DEFINITION class Material; class ParticleEmitter; class Field; //! A struct for one Particle typedef struct Particle { float lifeTime; //!< The time this particle has to live. float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) Vector position; //!< The current position of this particle. Vector velocity; //!< The current velocity of this particle. Vector extForce; //!< The external Force that influences this Particle. Quaternion rotation; //!< The current rotation of this particle. float mass; //!< The mass of this particle. float radius; //!< The current size of this particle. float radiusIt; //!< The difference of the Size per second. GLfloat color [4]; //!< A Color for the particles. PARTICLE_TYPE type; Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) }; //! A class to handle particle Systems class ParticleSystem : public PhysicsInterface { friend class ParticleEmitter; public: ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); virtual ~ParticleSystem(); void setName(const char* name); const char* getName(void) const; void setType(PARTICLE_TYPE particleType, int count = 0); void setMaterial(Material* material); void setInheritSpeed(float value); void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); void setRadius(float startRadius, float endRadius, float randomStartRadius = 0.0, float randomEndRadius = 0.0); void setConserve(float conserve); void setMass(float mass, float randomMass = 0.0); void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea); /** \returns the Type of the particles */ inline PARTICLE_TYPE getType(void) const { return this->particleType; }; /** \returns the Material that lies on this particles */ inline const Material* getMaterial(void) const { return this->material; }; /** \returns the inherit-speed-factor */ inline float getInheritSpeed(void) const { return this->inheritSpeed; }; /** \returns the lifespan of the particles */ inline float getLifeSpan(void) const { return this->lifeSpan; }; /** \returns the starting-radius of the particles */ inline float getStartRadius(void) const { return this->startRadius; }; /** \returns the end-radius of the particles */ inline float getEndRadius(void) const { return this->endRadius; }; /** \returns the conserve-factor of the particles */ inline float getConserve(void) const { return this->conserve; }; /** \returns the initial mass of the particles */ inline float getMass(void) const { return this->initialMass; }; virtual void applyField(Field* field, float dt); void tick(float dt); void draw(void) const; void debug(void); private: char* name; // the Name of the Particle System float conserve; //!< How much energy gets conserved to the next Tick. float lifeSpan; //!< Initial lifetime of a Particle. float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) float startRadius; //!< The beginning Radius of the Particle float endRadius; //!< The end Radius of the Particle float randomStartRadius; //!< The Random start Radius (begin + rand*randomValue) float randomEndRadius; //!< Random end value float initialMass; //!< The initial Mass of the Particle float randomInitialMass; //!< The random initial Mass of the Particle float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter GLfloat startColor[4]; //!< Color of the Particle at the beginning GLfloat midColor[4]; //!< Color of the Particle at the middle of its lifeSpan GLfloat endColor[4]; //!< Color of the Particle at the end of its lifeSpan // particles int maxCount; //!< The maximum count of Particles. int count; //!< The current count of Particles. PARTICLE_TYPE particleType;//!< A type for all the Particles Material* material; //!< A Material for all the Particles. Particle* particles; //!< A list of particles of this System. Particle* deadList; //!< A list of dead Particles in the System. GLuint* glID; //!< A List of different gl-List-ID's GLuint dialectCount; //!< How many different types of particles are there in the Particle System void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); }; #endif /* _PARTICLE_SYSTEM_H */