Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/particles/particle_system.h @ 4378

Last change on this file since 4378 was 4378, checked in by bensch, 19 years ago

orxonox/trunk: applying force works for particle-systems again

File size: 5.8 KB
Line 
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 "vector.h"
13
14#define PARTICLE_DOT_MASK           0x000001
15#define PARTICLE_SPARK_MASK         0x000010
16#define PARTICLE_SPRITE_MASK        0x000100
17#define PARTICLE_MODEL_MASK         0x001000
18#define PARTICLE_WORDL_ENTITY_MASK  0x010000
19#define PARTICLE_MULTI_MASK         0x100000
20
21//! An enumerator for the different types of particles.
22typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK,
23                            PARTICLE_SPARK = PARTICLE_SPARK_MASK,
24                            PARTICLE_SPRITE = PARTICLE_SPRITE_MASK,
25                            PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK,
26                            PARTICLE_MODEL = PARTICLE_MODEL_MASK,
27                            PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK};
28
29#define PARTICLE_DEFAULT_MAX_COUNT    200               //!< a default count of particles in the system.
30#define PARTICLE_DEFAULT_TYPE         PARTICLE_SPRITE   //!< A default type of the system.
31
32// FORWARD DEFINITION
33class Material;
34class ParticleEmitter;
35class Field;
36
37//! A struct for one Particle
38typedef struct Particle
39{
40  float lifeTime;             //!< The time this particle has to live.
41  float lifeCycle;            //!< The fraction of time passed. (in percentage of its lifeTime)
42
43  Vector position;            //!< The current position of this particle.
44  Vector velocity;            //!< The current velocity of this particle.
45  Vector extForce;            //!< The external Force that influences this Particle.
46  Quaternion rotation;        //!< The current rotation of this particle.
47  float mass;                 //!< The mass of this particle.
48  float radius;               //!< The current size of this particle.
49  float radiusIt;             //!< The difference of the Size per second.
50
51  GLfloat color [4];          //!< A Color for the particles.
52
53  PARTICLE_TYPE type;
54
55  Particle* next;             //!< pointer to the next particle in the List. (NULL if no preceding one)
56};
57
58//! A class to handle particle Systems
59class ParticleSystem : public PhysicsInterface {
60  friend class ParticleEmitter;
61
62 public:
63  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT,
64                 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
65  virtual ~ParticleSystem();
66  void setName(const char* name);
67  const char* getName(void) const;
68
69  void setType(PARTICLE_TYPE particleType, int count = 0);
70  void setMaterial(Material* material);
71  void setInheritSpeed(float value);
72  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
73  void setRadius(float startRadius, float endRadius,
74                 float randomStartRadius = 0.0, float randomEndRadius = 0.0);
75  void setConserve(float conserve);
76  void setMass(float mass, float randomMass = 0.0);
77
78  void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba,
79                GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma,
80                GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea);
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) const { return this->startRadius; };
92  /** \returns the end-radius of the particles */
93  inline float getEndRadius(void) const { return this->endRadius; };
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, float dt);
100
101  void tick(float dt);
102  void draw(void) const;
103
104  void debug(void);
105
106 private:
107  char* name;                // the Name of the Particle System
108
109  float conserve;            //!< How much energy gets conserved to the next Tick.
110  float lifeSpan;            //!< Initial lifetime of a Particle.
111  float randomLifeSpan;      //!< A random value for the Lifespan (around the initial lifetime)
112  float startRadius;         //!< The beginning Radius of the Particle
113  float endRadius;           //!< The end Radius of the Particle
114  float randomStartRadius;   //!< The Random start Radius (begin + rand*randomValue)
115  float randomEndRadius;     //!< Random end value
116  float initialMass;         //!< The initial Mass of the Particle
117  float randomInitialMass;   //!< The random initial Mass of the Particle
118  float inheritSpeed;        //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter
119
120  GLfloat startColor[4];     //!< Color of the Particle at the beginning
121  GLfloat midColor[4];       //!< Color of the Particle at the middle of its lifeSpan
122  GLfloat endColor[4];       //!< Color of the Particle at the end of its lifeSpan
123
124  // particles
125  int maxCount;              //!< The maximum count of Particles.
126  int count;                 //!< The current count of Particles.
127  PARTICLE_TYPE particleType;//!< A type for all the Particles
128  Material* material;        //!< A Material for all the Particles.
129  Particle* particles;       //!< A list of particles of this System.
130  Particle* deadList;        //!< A list of dead Particles in the System.
131
132  GLuint* glID;              //!< A List of different gl-List-ID's
133  GLuint dialectCount;       //!< How many different types of particles are there in the Particle System
134
135  void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0);
136 
137};
138
139#endif /* _PARTICLE_SYSTEM_H */
Note: See TracBrowser for help on using the repository browser.