1 | /*! |
---|
2 | \file particle_system.h |
---|
3 | |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _PARTICLE_SYSTEM_H |
---|
7 | #define _PARTICLE_SYSTEM_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "vector.h" |
---|
11 | |
---|
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 |
---|
18 | |
---|
19 | //! An enumerator for the different types of particles. |
---|
20 | typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, |
---|
21 | PARTICLE_SPARK = PARTICLE_SPARK_MASK, |
---|
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}; |
---|
26 | |
---|
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. |
---|
29 | |
---|
30 | // FORWARD DEFINITION |
---|
31 | class Material; |
---|
32 | class ParticleEmitter; |
---|
33 | |
---|
34 | |
---|
35 | //! A struct for one Particle |
---|
36 | typedef struct Particle |
---|
37 | { |
---|
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. |
---|
42 | float mass; //!< The mass of this particle. |
---|
43 | float radius; //!< The current size of this particle. |
---|
44 | float radiusIt; //!< The difference of the Size per second. |
---|
45 | |
---|
46 | PARTICLE_TYPE type; |
---|
47 | |
---|
48 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
49 | }; |
---|
50 | |
---|
51 | //! A class to handle particle Systems |
---|
52 | class ParticleSystem : public BaseObject { |
---|
53 | friend class ParticleEmitter; |
---|
54 | |
---|
55 | public: |
---|
56 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, |
---|
57 | PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
58 | virtual ~ParticleSystem(); |
---|
59 | void setName(const char* name); |
---|
60 | const char* getName(void) const; |
---|
61 | |
---|
62 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
63 | void setMaterial(Material* material); |
---|
64 | void setInheritSpeed(float value); |
---|
65 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
66 | void setRadius(float startRadius, float endRadius, |
---|
67 | float randomStartRadius = 0.0, float randomEndRadius = 0.0); |
---|
68 | void setConserve(float conserve); |
---|
69 | void setMass(float mass, float randomMass); |
---|
70 | |
---|
71 | void tick(float dt); |
---|
72 | void draw(float dt); |
---|
73 | |
---|
74 | void debug(void); |
---|
75 | |
---|
76 | private: |
---|
77 | char* name; // the Name of the Particle System |
---|
78 | |
---|
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; |
---|
84 | float randomStartRadius; |
---|
85 | float randomEndRadius; |
---|
86 | float initialMass; |
---|
87 | float randomInitialMass; |
---|
88 | float inheritSpeed; |
---|
89 | |
---|
90 | // particles |
---|
91 | int maxCount; //!< The maximum count of Particles. |
---|
92 | int count; //!< The current count of Particles. |
---|
93 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
94 | Material* material; //!< A Material for all the Particles. |
---|
95 | Particle* particles; //!< A list of particles of this System. |
---|
96 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
97 | |
---|
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 |
---|
100 | |
---|
101 | void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); |
---|
102 | |
---|
103 | }; |
---|
104 | |
---|
105 | #endif /* _PARTICLE_SYSTEM_H */ |
---|