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 "physics_interface.h" |
---|
11 | |
---|
12 | #include "glincl.h" |
---|
13 | #include "vector.h" |
---|
14 | |
---|
15 | #include "quick_animation.h" |
---|
16 | |
---|
17 | #define PARTICLE_DOT_MASK 0x000001 |
---|
18 | #define PARTICLE_SPARK_MASK 0x000010 |
---|
19 | #define PARTICLE_SPRITE_MASK 0x000100 |
---|
20 | #define PARTICLE_MODEL_MASK 0x001000 |
---|
21 | #define PARTICLE_WORDL_ENTITY_MASK 0x010000 |
---|
22 | #define PARTICLE_MULTI_MASK 0x100000 |
---|
23 | |
---|
24 | //! An enumerator for the different types of particles. |
---|
25 | typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, |
---|
26 | PARTICLE_SPARK = PARTICLE_SPARK_MASK, |
---|
27 | PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, |
---|
28 | PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, |
---|
29 | PARTICLE_MODEL = PARTICLE_MODEL_MASK, |
---|
30 | PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK}; |
---|
31 | |
---|
32 | #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< a default count of particles in the system. |
---|
33 | #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. |
---|
34 | |
---|
35 | // FORWARD DEFINITION |
---|
36 | class Material; |
---|
37 | class ParticleEmitter; |
---|
38 | class Field; |
---|
39 | |
---|
40 | //! A struct for one Particle |
---|
41 | typedef struct Particle |
---|
42 | { |
---|
43 | float lifeTime; //!< The time this particle has to live. |
---|
44 | float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) |
---|
45 | |
---|
46 | Vector position; //!< The current position of this particle. |
---|
47 | Vector velocity; //!< The current velocity of this particle. |
---|
48 | Vector extForce; //!< The external Force that influences this Particle. |
---|
49 | Quaternion rotation; //!< The current rotation of this particle. |
---|
50 | float mass; //!< The mass of this particle. |
---|
51 | float massRand; |
---|
52 | float radius; //!< The current size of this particle. |
---|
53 | float radiusRand; |
---|
54 | |
---|
55 | GLfloat color [4]; //!< A Color for the particles. |
---|
56 | |
---|
57 | PARTICLE_TYPE type; |
---|
58 | |
---|
59 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
60 | }; |
---|
61 | |
---|
62 | //! A class to handle ParticleSystems |
---|
63 | class ParticleSystem : public PhysicsInterface { |
---|
64 | friend class ParticleEmitter; |
---|
65 | |
---|
66 | public: |
---|
67 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, |
---|
68 | PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
69 | virtual ~ParticleSystem(); |
---|
70 | |
---|
71 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
72 | void setMaterial(Material* material); |
---|
73 | void setInheritSpeed(float value); |
---|
74 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
75 | void setConserve(float conserve); |
---|
76 | |
---|
77 | /* Per-Particle-Attributes */ |
---|
78 | void setRadius(float lifeCycleTime, float radius, float randRadius = 0.0); |
---|
79 | void setMass(float lifeCycleTime, float mass, float randMass = 0.0); |
---|
80 | void setColor(float lifeCycleTime, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); |
---|
81 | |
---|
82 | /** \returns the Type of the particles */ |
---|
83 | inline PARTICLE_TYPE getType(void) const { return this->particleType; }; |
---|
84 | /** \returns the Material that lies on this particles */ |
---|
85 | inline const Material* getMaterial(void) const { return this->material; }; |
---|
86 | /** \returns the inherit-speed-factor */ |
---|
87 | inline float getInheritSpeed(void) const { return this->inheritSpeed; }; |
---|
88 | /** \returns the lifespan of the particles */ |
---|
89 | inline float getLifeSpan(void) const { return this->lifeSpan; }; |
---|
90 | /** \returns the starting-radius of the particles */ |
---|
91 | inline float getStartRadius(void) { return this->radiusAnim.getValue(0.0); }; |
---|
92 | /** \returns the end-radius of the particles */ |
---|
93 | inline float getEndRadius(void) { return this->radiusAnim.getValue(1.0); }; |
---|
94 | /** \returns the conserve-factor of the particles */ |
---|
95 | inline float getConserve(void) const { return this->conserve; }; |
---|
96 | /** \returns the initial mass of the particles */ |
---|
97 | inline float getMass(void) const { return this->initialMass; }; |
---|
98 | |
---|
99 | virtual void applyField(Field* field); |
---|
100 | virtual void tickPhys(float dt) {}; |
---|
101 | |
---|
102 | void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); |
---|
103 | |
---|
104 | void tick(float dt); |
---|
105 | void draw(void) const; |
---|
106 | |
---|
107 | void debug(void); |
---|
108 | |
---|
109 | private: |
---|
110 | char* name; // the Name of the Particle System |
---|
111 | |
---|
112 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
113 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
114 | float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) |
---|
115 | float initialMass; //!< The initial Mass of the Particle |
---|
116 | float randomInitialMass; //!< The random initial Mass of the Particle |
---|
117 | float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter |
---|
118 | |
---|
119 | // particles |
---|
120 | int maxCount; //!< The maximum count of Particles. |
---|
121 | int count; //!< The current count of Particles. |
---|
122 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
123 | Material* material; //!< A Material for all the Particles. |
---|
124 | Particle* particles; //!< A list of particles of this System. |
---|
125 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
126 | |
---|
127 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
128 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
129 | |
---|
130 | // per particle attributes |
---|
131 | QuickAnimation radiusAnim; |
---|
132 | QuickAnimation randRadiusAnim; |
---|
133 | QuickAnimation massAnim; |
---|
134 | QuickAnimation randMassAnim; |
---|
135 | QuickAnimation colorAnim[4]; |
---|
136 | }; |
---|
137 | |
---|
138 | #endif /* _PARTICLE_SYSTEM_H */ |
---|