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, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
57 | virtual ~ParticleSystem(); |
---|
58 | void setName(const char* name); |
---|
59 | const char* getName(void) const; |
---|
60 | |
---|
61 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
62 | void setMaterial(Material* material); |
---|
63 | void setInheritSpeed(float value); |
---|
64 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
65 | void setRadius(float startRadius, float endRadius, float randomStartRadius = 0.0, float randomEndRadius = 0.0); |
---|
66 | void setConserve(float conserve); |
---|
67 | void setMass(float mass, float randomMass); |
---|
68 | |
---|
69 | void tick(float dt); |
---|
70 | void draw(void); |
---|
71 | |
---|
72 | void debug(void); |
---|
73 | |
---|
74 | private: |
---|
75 | char* name; // the Name of the Particle System |
---|
76 | |
---|
77 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
78 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
79 | float randomLifeSpan; |
---|
80 | float startRadius; |
---|
81 | float endRadius; |
---|
82 | float randomStartRadius; |
---|
83 | float randomEndRadius; |
---|
84 | float initialMass; |
---|
85 | float randomInitialMass; |
---|
86 | float inheritSpeed; |
---|
87 | |
---|
88 | // particles |
---|
89 | int maxCount; //!< The maximum count of Particles. |
---|
90 | int count; //!< The current count of Particles. |
---|
91 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
92 | Material* material; //!< A Material for all the Particles. |
---|
93 | Particle* particles; //!< A list of particles of this System. |
---|
94 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
95 | |
---|
96 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
97 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
98 | |
---|
99 | void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); |
---|
100 | |
---|
101 | }; |
---|
102 | |
---|
103 | #endif /* _PARTICLE_SYSTEM_H */ |
---|