Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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