[3245] | 1 | /*! |
---|
[3925] | 2 | \file particle_system.h |
---|
[3329] | 3 | |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[3925] | 6 | #ifndef _PARTICLE_SYSTEM_H |
---|
| 7 | #define _PARTICLE_SYSTEM_H |
---|
[1853] | 8 | |
---|
[3543] | 9 | #include "base_object.h" |
---|
[4377] | 10 | #include "physics_interface.h" |
---|
| 11 | |
---|
[4381] | 12 | #include "glincl.h" |
---|
[3925] | 13 | #include "vector.h" |
---|
[3930] | 14 | |
---|
[4017] | 15 | #define PARTICLE_DOT_MASK 0x000001 |
---|
| 16 | #define PARTICLE_SPARK_MASK 0x000010 |
---|
| 17 | #define PARTICLE_SPRITE_MASK 0x000100 |
---|
| 18 | #define PARTICLE_MODEL_MASK 0x001000 |
---|
| 19 | #define PARTICLE_WORDL_ENTITY_MASK 0x010000 |
---|
| 20 | #define PARTICLE_MULTI_MASK 0x100000 |
---|
[3956] | 21 | |
---|
[3930] | 22 | //! An enumerator for the different types of particles. |
---|
[3956] | 23 | typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, |
---|
[4017] | 24 | PARTICLE_SPARK = PARTICLE_SPARK_MASK, |
---|
[3956] | 25 | PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, |
---|
| 26 | PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, |
---|
| 27 | PARTICLE_MODEL = PARTICLE_MODEL_MASK, |
---|
| 28 | PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK}; |
---|
[3930] | 29 | |
---|
[3942] | 30 | #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< a default count of particles in the system. |
---|
| 31 | #define PARTICLE_DEFAULT_TYPE PARTICLE_SPRITE //!< A default type of the system. |
---|
[3930] | 32 | |
---|
[3925] | 33 | // FORWARD DEFINITION |
---|
[3926] | 34 | class Material; |
---|
[3930] | 35 | class ParticleEmitter; |
---|
[4338] | 36 | class Field; |
---|
[3543] | 37 | |
---|
[3925] | 38 | //! A struct for one Particle |
---|
| 39 | typedef struct Particle |
---|
| 40 | { |
---|
[4338] | 41 | float lifeTime; //!< The time this particle has to live. |
---|
| 42 | float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) |
---|
| 43 | |
---|
[3930] | 44 | Vector position; //!< The current position of this particle. |
---|
| 45 | Vector velocity; //!< The current velocity of this particle. |
---|
[4338] | 46 | Vector extForce; //!< The external Force that influences this Particle. |
---|
[3930] | 47 | Quaternion rotation; //!< The current rotation of this particle. |
---|
[3931] | 48 | float mass; //!< The mass of this particle. |
---|
[3932] | 49 | float radius; //!< The current size of this particle. |
---|
[3936] | 50 | float radiusIt; //!< The difference of the Size per second. |
---|
[3930] | 51 | |
---|
[4338] | 52 | GLfloat color [4]; //!< A Color for the particles. |
---|
| 53 | |
---|
[4017] | 54 | PARTICLE_TYPE type; |
---|
| 55 | |
---|
[3931] | 56 | Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) |
---|
[3925] | 57 | }; |
---|
[3543] | 58 | |
---|
[4394] | 59 | //! A class to handle ParticleSystems |
---|
[4377] | 60 | class ParticleSystem : public PhysicsInterface { |
---|
[4395] | 61 | friend class ParticleEmitter; |
---|
| 62 | |
---|
[1904] | 63 | public: |
---|
[4176] | 64 | ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, |
---|
| 65 | PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); |
---|
[3925] | 66 | virtual ~ParticleSystem(); |
---|
[3944] | 67 | void setName(const char* name); |
---|
| 68 | const char* getName(void) const; |
---|
[1853] | 69 | |
---|
[3942] | 70 | void setType(PARTICLE_TYPE particleType, int count = 0); |
---|
[3930] | 71 | void setMaterial(Material* material); |
---|
[3938] | 72 | void setInheritSpeed(float value); |
---|
[3931] | 73 | void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); |
---|
[4176] | 74 | void setRadius(float startRadius, float endRadius, |
---|
| 75 | float randomStartRadius = 0.0, float randomEndRadius = 0.0); |
---|
[3932] | 76 | void setConserve(float conserve); |
---|
[4378] | 77 | void setMass(float mass, float randomMass = 0.0); |
---|
[3245] | 78 | |
---|
[4338] | 79 | void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, |
---|
| 80 | GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, |
---|
| 81 | GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea); |
---|
| 82 | |
---|
| 83 | /** \returns the Type of the particles */ |
---|
| 84 | inline PARTICLE_TYPE getType(void) const { return this->particleType; }; |
---|
| 85 | /** \returns the Material that lies on this particles */ |
---|
| 86 | inline const Material* getMaterial(void) const { return this->material; }; |
---|
| 87 | /** \returns the inherit-speed-factor */ |
---|
| 88 | inline float getInheritSpeed(void) const { return this->inheritSpeed; }; |
---|
| 89 | /** \returns the lifespan of the particles */ |
---|
| 90 | inline float getLifeSpan(void) const { return this->lifeSpan; }; |
---|
| 91 | /** \returns the starting-radius of the particles */ |
---|
| 92 | inline float getStartRadius(void) const { return this->startRadius; }; |
---|
| 93 | /** \returns the end-radius of the particles */ |
---|
| 94 | inline float getEndRadius(void) const { return this->endRadius; }; |
---|
| 95 | /** \returns the conserve-factor of the particles */ |
---|
| 96 | inline float getConserve(void) const { return this->conserve; }; |
---|
| 97 | /** \returns the initial mass of the particles */ |
---|
| 98 | inline float getMass(void) const { return this->initialMass; }; |
---|
| 99 | |
---|
[4395] | 100 | virtual void applyField(Field* field); |
---|
[4338] | 101 | |
---|
[4394] | 102 | void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0); |
---|
| 103 | |
---|
[3931] | 104 | void tick(float dt); |
---|
[4349] | 105 | void draw(void) const; |
---|
[3931] | 106 | |
---|
[3944] | 107 | void debug(void); |
---|
| 108 | |
---|
[3245] | 109 | private: |
---|
[3944] | 110 | char* name; // the Name of the Particle System |
---|
| 111 | |
---|
[3931] | 112 | float conserve; //!< How much energy gets conserved to the next Tick. |
---|
| 113 | float lifeSpan; //!< Initial lifetime of a Particle. |
---|
[4338] | 114 | float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) |
---|
| 115 | float startRadius; //!< The beginning Radius of the Particle |
---|
| 116 | float endRadius; //!< The end Radius of the Particle |
---|
| 117 | float randomStartRadius; //!< The Random start Radius (begin + rand*randomValue) |
---|
| 118 | float randomEndRadius; //!< Random end value |
---|
| 119 | float initialMass; //!< The initial Mass of the Particle |
---|
| 120 | float randomInitialMass; //!< The random initial Mass of the Particle |
---|
| 121 | float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter |
---|
[3938] | 122 | |
---|
[4338] | 123 | GLfloat startColor[4]; //!< Color of the Particle at the beginning |
---|
| 124 | GLfloat midColor[4]; //!< Color of the Particle at the middle of its lifeSpan |
---|
| 125 | GLfloat endColor[4]; //!< Color of the Particle at the end of its lifeSpan |
---|
| 126 | |
---|
[3931] | 127 | // particles |
---|
[3934] | 128 | int maxCount; //!< The maximum count of Particles. |
---|
| 129 | int count; //!< The current count of Particles. |
---|
[3931] | 130 | PARTICLE_TYPE particleType;//!< A type for all the Particles |
---|
| 131 | Material* material; //!< A Material for all the Particles. |
---|
[3930] | 132 | Particle* particles; //!< A list of particles of this System. |
---|
[4123] | 133 | Particle* deadList; //!< A list of dead Particles in the System. |
---|
[3932] | 134 | |
---|
[3942] | 135 | GLuint* glID; //!< A List of different gl-List-ID's |
---|
[4394] | 136 | GLuint dialectCount; //!< How many different types of particles are there in the Particle System |
---|
[1853] | 137 | }; |
---|
| 138 | |
---|
[3925] | 139 | #endif /* _PARTICLE_SYSTEM_H */ |
---|