[3245] | 1 | /*! |
---|
[3925] | 2 | \file particle_system.h |
---|
[3329] | 3 | |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[3925] | 6 | #ifndef _PARTICLE_SYSTEM_H |
---|
| 7 | #define _PARTICLE_SYSTEM_H |
---|
[1853] | 8 | |
---|
[3543] | 9 | #include "base_object.h" |
---|
[3925] | 10 | #include "vector.h" |
---|
[3930] | 11 | |
---|
| 12 | //! An enumerator for the different types of particles. |
---|
| 13 | typedef enum PARTICLE_TYPE {PARTICLE_DOT, |
---|
| 14 | PARTICLE_SPRITE, |
---|
[3931] | 15 | PARTICLE_MULTI_SPRITE, |
---|
[3930] | 16 | PARTICLE_OBJECT, |
---|
[3931] | 17 | PARTICLE_MULTI_OBJECT, |
---|
[3930] | 18 | PARTICLE_PRIMITIVE}; |
---|
| 19 | |
---|
[3942] | 20 | #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< a default count of particles in the system. |
---|
| 21 | #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. |
---|
[3930] | 22 | |
---|
[3925] | 23 | // FORWARD DEFINITION |
---|
[3926] | 24 | class Material; |
---|
[3930] | 25 | class ParticleEmitter; |
---|
[3543] | 26 | |
---|
[3926] | 27 | |
---|
[3925] | 28 | //! A struct for one Particle |
---|
| 29 | typedef struct Particle |
---|
| 30 | { |
---|
[3930] | 31 | float timeToLive; //!< The time this particle lives from NOW on. |
---|
| 32 | Vector position; //!< The current position of this particle. |
---|
| 33 | Vector velocity; //!< The current velocity of this particle. |
---|
| 34 | Quaternion rotation; //!< The current rotation of this particle. |
---|
[3931] | 35 | float mass; //!< The mass of this particle. |
---|
[3932] | 36 | float radius; //!< The current size of this particle. |
---|
[3936] | 37 | float radiusIt; //!< The difference of the Size per second. |
---|
[3930] | 38 | |
---|
[3931] | 39 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
[3925] | 40 | }; |
---|
[3543] | 41 | |
---|
[3925] | 42 | //! A class to handle particle Systems |
---|
| 43 | class ParticleSystem : public BaseObject { |
---|
[3932] | 44 | friend class ParticleEmitter; |
---|
[2036] | 45 | |
---|
[1904] | 46 | public: |
---|
[3934] | 47 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
[3925] | 48 | virtual ~ParticleSystem(); |
---|
[1853] | 49 | |
---|
[3942] | 50 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
[3930] | 51 | void setMaterial(Material* material); |
---|
[3938] | 52 | void setInheritSpeed(float value); |
---|
[3931] | 53 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
[3942] | 54 | void setRadius(float startRadius, float endRadius, float randomStartRadius = 0.0, float randomEndRadius = 0.0); |
---|
[3932] | 55 | void setConserve(float conserve); |
---|
| 56 | void setMass(float mass, float randomMass); |
---|
[3245] | 57 | |
---|
[3931] | 58 | void tick(float dt); |
---|
[3932] | 59 | void draw(void); |
---|
[3931] | 60 | |
---|
[3245] | 61 | private: |
---|
[3931] | 62 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
| 63 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
| 64 | float randomLifeSpan; |
---|
| 65 | float startRadius; |
---|
| 66 | float endRadius; |
---|
[3942] | 67 | float randomStartRadius; |
---|
| 68 | float randomEndRadius; |
---|
[3932] | 69 | float initialMass; |
---|
| 70 | float randomInitialMass; |
---|
[3938] | 71 | float inheritSpeed; |
---|
| 72 | |
---|
[3931] | 73 | // particles |
---|
[3934] | 74 | int maxCount; //!< The maximum count of Particles. |
---|
| 75 | int count; //!< The current count of Particles. |
---|
[3931] | 76 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
| 77 | Material* material; //!< A Material for all the Particles. |
---|
[3930] | 78 | Particle* particles; //!< A list of particles of this System. |
---|
[3932] | 79 | |
---|
[3942] | 80 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
| 81 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
[3932] | 82 | |
---|
| 83 | void addParticle(Vector position, Vector velocity, unsigned int data = 0); |
---|
| 84 | |
---|
[1853] | 85 | }; |
---|
| 86 | |
---|
[3925] | 87 | #endif /* _PARTICLE_SYSTEM_H */ |
---|