/*! \file particle_system.h */ #ifndef _PARTICLE_SYSTEM_H #define _PARTICLE_SYSTEM_H #include "base_object.h" #include "vector.h" //! An enumerator for the different types of particles. typedef enum PARTICLE_TYPE {PARTICLE_DOT, PARTICLE_SPRITE, PARTICLE_MULTI_SPRITE, PARTICLE_OBJECT, PARTICLE_MULTI_OBJECT, PARTICLE_PRIMITIVE}; #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; //! A struct for one Particle typedef struct Particle { float timeToLive; //!< The time this particle lives from NOW on. Vector position; //!< The current position of this particle. Vector velocity; //!< The current velocity of 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. Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) }; //! A class to handle particle Systems class ParticleSystem : public BaseObject { friend class ParticleEmitter; public: ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); virtual ~ParticleSystem(); void setMaterial(Material* material); void setInheritSpeed(float value); void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); void setRadius(float startRadius, float endRadius, float randomRadius = 0.0); void setConserve(float conserve); void setMass(float mass, float randomMass); void tick(float dt); void draw(void); private: float conserve; //!< How much energy gets conserved to the next Tick. float lifeSpan; //!< Initial lifetime of a Particle. float randomLifeSpan; float startRadius; float endRadius; float randomRadius; float initialMass; float randomInitialMass; float inheritSpeed; // 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. void addParticle(Vector position, Vector velocity, unsigned int data = 0); }; #endif /* _PARTICLE_SYSTEM_H */