[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 | |
---|
[4017] | 12 | #define PARTICLE_DOT_MASK 0x000001 |
---|
| 13 | #define PARTICLE_SPARK_MASK 0x000010 |
---|
| 14 | #define PARTICLE_SPRITE_MASK 0x000100 |
---|
| 15 | #define PARTICLE_MODEL_MASK 0x001000 |
---|
| 16 | #define PARTICLE_WORDL_ENTITY_MASK 0x010000 |
---|
| 17 | #define PARTICLE_MULTI_MASK 0x100000 |
---|
[3956] | 18 | |
---|
[3930] | 19 | //! An enumerator for the different types of particles. |
---|
[3956] | 20 | typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, |
---|
[4017] | 21 | PARTICLE_SPARK = PARTICLE_SPARK_MASK, |
---|
[3956] | 22 | PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, |
---|
| 23 | PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, |
---|
| 24 | PARTICLE_MODEL = PARTICLE_MODEL_MASK, |
---|
| 25 | PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK}; |
---|
[3930] | 26 | |
---|
[3942] | 27 | #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< a default count of particles in the system. |
---|
| 28 | #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. |
---|
[3930] | 29 | |
---|
[3925] | 30 | // FORWARD DEFINITION |
---|
[3926] | 31 | class Material; |
---|
[3930] | 32 | class ParticleEmitter; |
---|
[3543] | 33 | |
---|
[3926] | 34 | |
---|
[3925] | 35 | //! A struct for one Particle |
---|
| 36 | typedef struct Particle |
---|
| 37 | { |
---|
[3930] | 38 | float timeToLive; //!< The time this particle lives from NOW on. |
---|
| 39 | Vector position; //!< The current position of this particle. |
---|
| 40 | Vector velocity; //!< The current velocity of this particle. |
---|
| 41 | Quaternion rotation; //!< The current rotation of this particle. |
---|
[3931] | 42 | float mass; //!< The mass of this particle. |
---|
[3932] | 43 | float radius; //!< The current size of this particle. |
---|
[3936] | 44 | float radiusIt; //!< The difference of the Size per second. |
---|
[3930] | 45 | |
---|
[4017] | 46 | PARTICLE_TYPE type; |
---|
| 47 | |
---|
[3931] | 48 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
[3925] | 49 | }; |
---|
[3543] | 50 | |
---|
[3925] | 51 | //! A class to handle particle Systems |
---|
| 52 | class ParticleSystem : public BaseObject { |
---|
[3932] | 53 | friend class ParticleEmitter; |
---|
[2036] | 54 | |
---|
[1904] | 55 | public: |
---|
[4128] | 56 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, |
---|
| 57 | PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
[3925] | 58 | virtual ~ParticleSystem(); |
---|
[3944] | 59 | void setName(const char* name); |
---|
| 60 | const char* getName(void) const; |
---|
[1853] | 61 | |
---|
[3942] | 62 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
[3930] | 63 | void setMaterial(Material* material); |
---|
[3938] | 64 | void setInheritSpeed(float value); |
---|
[3931] | 65 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
[4128] | 66 | void setRadius(float startRadius, float endRadius, |
---|
| 67 | float randomStartRadius = 0.0, float randomEndRadius = 0.0); |
---|
[3932] | 68 | void setConserve(float conserve); |
---|
| 69 | void setMass(float mass, float randomMass); |
---|
[3245] | 70 | |
---|
[3931] | 71 | void tick(float dt); |
---|
[3932] | 72 | void draw(void); |
---|
[3931] | 73 | |
---|
[3944] | 74 | void debug(void); |
---|
| 75 | |
---|
[3245] | 76 | private: |
---|
[3944] | 77 | char* name; // the Name of the Particle System |
---|
| 78 | |
---|
[3931] | 79 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
| 80 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
| 81 | float randomLifeSpan; |
---|
| 82 | float startRadius; |
---|
| 83 | float endRadius; |
---|
[3942] | 84 | float randomStartRadius; |
---|
| 85 | float randomEndRadius; |
---|
[3932] | 86 | float initialMass; |
---|
| 87 | float randomInitialMass; |
---|
[3938] | 88 | float inheritSpeed; |
---|
| 89 | |
---|
[3931] | 90 | // particles |
---|
[3934] | 91 | int maxCount; //!< The maximum count of Particles. |
---|
| 92 | int count; //!< The current count of Particles. |
---|
[3931] | 93 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
| 94 | Material* material; //!< A Material for all the Particles. |
---|
[3930] | 95 | Particle* particles; //!< A list of particles of this System. |
---|
[4123] | 96 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
[3932] | 97 | |
---|
[3942] | 98 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
| 99 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
[3932] | 100 | |
---|
[3951] | 101 | void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); |
---|
[3932] | 102 | |
---|
[1853] | 103 | }; |
---|
| 104 | |
---|
[3925] | 105 | #endif /* _PARTICLE_SYSTEM_H */ |
---|