1 | /*! |
---|
2 | * @file particle_system.h |
---|
3 | |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _PARTICLE_SYSTEM_H |
---|
7 | #define _PARTICLE_SYSTEM_H |
---|
8 | |
---|
9 | #include "world_entity.h" |
---|
10 | #include "physics_interface.h" |
---|
11 | |
---|
12 | #include "glincl.h" |
---|
13 | #include "vector.h" |
---|
14 | |
---|
15 | #include "quick_animation.h" |
---|
16 | |
---|
17 | // Forward Declaration |
---|
18 | class TiXmlElement; |
---|
19 | |
---|
20 | #define PARTICLE_DOT_MASK 0x000001 //!< A Mask if the Particles should be displayed as DOTs |
---|
21 | #define PARTICLE_SPARK_MASK 0x000010 //!< A Mask if the Particles should be displayed as SPARKs |
---|
22 | #define PARTICLE_SPRITE_MASK 0x000100 //!< A Mask if the Particles should be displayed as SPRITESs |
---|
23 | #define PARTICLE_MODEL_MASK 0x001000 //!< A Mask if the Particles should be displayed as MODELSs |
---|
24 | #define PARTICLE_WORDL_ENTITY_MASK 0x010000 //!< A Mask if the Particles should be displayed as WORLD_ENTITIEs |
---|
25 | #define PARTICLE_MULTI_MASK 0x100000 //!< A Mask if they are Multi-partilces |
---|
26 | |
---|
27 | //! An enumerator for the different types of particles. |
---|
28 | typedef enum PARTICLE_TYPE |
---|
29 | { |
---|
30 | PARTICLE_DOT = PARTICLE_DOT_MASK, |
---|
31 | PARTICLE_SPARK = PARTICLE_SPARK_MASK, |
---|
32 | PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, |
---|
33 | PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, |
---|
34 | PARTICLE_MODEL = PARTICLE_MODEL_MASK, |
---|
35 | PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK |
---|
36 | }; |
---|
37 | |
---|
38 | #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< A default count of particles in the system. |
---|
39 | #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. |
---|
40 | |
---|
41 | // FORWARD DECLARATION |
---|
42 | class Material; |
---|
43 | class ParticleEmitter; |
---|
44 | class Field; |
---|
45 | |
---|
46 | //! A struct for one Particle |
---|
47 | typedef struct Particle |
---|
48 | { |
---|
49 | float lifeTime; //!< The time this particle has to live. |
---|
50 | float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) |
---|
51 | |
---|
52 | Vector position; //!< The current position of this particle. |
---|
53 | Vector velocity; //!< The current velocity of this Particle. |
---|
54 | Vector extForce; //!< The external Force that influences this Particle. |
---|
55 | Quaternion orientation; //!< The current orientation of this Particle. |
---|
56 | Quaternion momentum; //!< The current angular momentum (spin) of this Particle. |
---|
57 | float mass; //!< The mass of this Particle. |
---|
58 | float massRand; //!< A random mass |
---|
59 | float radius; //!< The current size of this Particle. |
---|
60 | float radiusRand; //!< a random Radius |
---|
61 | GLfloat color [4]; //!< A Color for the particles. |
---|
62 | |
---|
63 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
64 | }; |
---|
65 | |
---|
66 | //! A class to handle ParticleSystems |
---|
67 | class ParticleSystem : public WorldEntity, public PhysicsInterface { |
---|
68 | |
---|
69 | public: |
---|
70 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, |
---|
71 | PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
72 | ParticleSystem(const TiXmlElement* root); |
---|
73 | virtual ~ParticleSystem(); |
---|
74 | |
---|
75 | void init(); |
---|
76 | void loadParams(const TiXmlElement* root); |
---|
77 | |
---|
78 | void setType(const char* particleType); |
---|
79 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
80 | void setMaterial(Material* material); |
---|
81 | void setMaterialTexture(const char* textureFile); |
---|
82 | void setModel(const char* modelName = NULL); |
---|
83 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
84 | void setConserve(float conserve); |
---|
85 | void setMaxCount(int maxCount); |
---|
86 | |
---|
87 | /* Per-Particle-Attributes */ |
---|
88 | void setRadius(float lifeCycleTime, float radius, float randRadius = 0.0); |
---|
89 | void setMass(float lifeCycleTime, float mass, float randMass = 0.0); |
---|
90 | void setColor(float lifeCycleTime, float red, float green, float blue, float alpha); |
---|
91 | |
---|
92 | /** @returns the Type of the particles */ |
---|
93 | inline PARTICLE_TYPE getType() const { return this->particleType; }; |
---|
94 | /** @returns the Material that lies on this particles */ |
---|
95 | inline const Material* getMaterial() const { return this->material; }; |
---|
96 | /** @returns the lifespan of the particles */ |
---|
97 | inline float getLifeSpan() const { return this->lifeSpan; }; |
---|
98 | /** @returns the starting-radius of the particles */ |
---|
99 | inline float getStartRadius() { return this->radiusAnim.getValue(0.0); }; |
---|
100 | /** @returns the end-radius of the particles */ |
---|
101 | inline float getEndRadius() { return this->radiusAnim.getValue(1.0); }; |
---|
102 | /** @returns the conserve-factor of the particles */ |
---|
103 | inline float getConserve() const { return this->conserve; }; |
---|
104 | /** @returns the initial mass of the particles */ |
---|
105 | inline float getMass() const { return this->initialMass; }; |
---|
106 | |
---|
107 | virtual unsigned int getFaceCount() const; |
---|
108 | |
---|
109 | |
---|
110 | virtual void applyField(Field* field); |
---|
111 | /** \brief this is an empty function, because the Physics are implemented in tick @param dt: useless here */ |
---|
112 | virtual void tickPhys(float dt) {}; |
---|
113 | |
---|
114 | void addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data = 0); |
---|
115 | |
---|
116 | virtual void tick(float dt); |
---|
117 | virtual void draw() const; |
---|
118 | |
---|
119 | void debug() const; |
---|
120 | |
---|
121 | private: |
---|
122 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
123 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
124 | float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) |
---|
125 | float initialMass; //!< The initial Mass of the Particle |
---|
126 | float randomInitialMass; //!< The random initial Mass of the Particle |
---|
127 | |
---|
128 | int maxCount; //!< The maximum count of Particles. |
---|
129 | int count; //!< The current count of Particles. |
---|
130 | PARTICLE_TYPE particleType; //!< A type for all the Particles |
---|
131 | Material* material; //!< A Material for all the Particles. |
---|
132 | Particle* particles; //!< A list of particles of this System. |
---|
133 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
134 | |
---|
135 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
136 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
137 | |
---|
138 | // per particle attributes |
---|
139 | QuickAnimation radiusAnim; //!< Animation of the radius |
---|
140 | QuickAnimation randRadiusAnim; //!< Animation of the random Value of the radius |
---|
141 | QuickAnimation massAnim; //!< Animation of the mass |
---|
142 | QuickAnimation randMassAnim; //!< Animation of the random Mass |
---|
143 | QuickAnimation colorAnim[4]; //!< Animation of the 4 colors (r,g,b,a) |
---|
144 | }; |
---|
145 | |
---|
146 | #endif /* _PARTICLE_SYSTEM_H */ |
---|