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