Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: possibility to return the count of faces of some Object

File size: 6.4 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// Forward Declaration
18class 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.
28typedef 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 DEFINITION
42class Material;
43class ParticleEmitter;
44class Field;
45
46//! A struct for one Particle
47typedef 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    rotation;            //!< The current rotation of this particle.
56  float         mass;                //!< The mass of this particle.
57  float         massRand;            //!< A random mass
58  float         radius;              //!< The current size of this particle.
59  float         radiusRand;          //!< a random Radius
60  GLfloat       color [4];           //!< A Color for the particles.
61
62  Particle*     next;                //!< pointer to the next particle in the List. (NULL if no preceding one)
63};
64
65//! A class to handle ParticleSystems
66class ParticleSystem : public WorldEntity, public PhysicsInterface {
67
68 public:
69  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT,
70                 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
71  ParticleSystem(const TiXmlElement* root);
72  virtual ~ParticleSystem();
73
74  void init(void);
75  void loadParams(const TiXmlElement* root);
76
77  void setType(PARTICLE_TYPE particleType, int count = 0);
78  void setMaterial(Material* material);
79  void setModel(const char* modelName = NULL);
80  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
81  void setConserve(float conserve);
82
83  /* Per-Particle-Attributes */
84  void setRadius(float lifeCycleTime, float radius, float randRadius = 0.0);
85  void setMass(float lifeCycleTime, float mass, float randMass = 0.0);
86  void setColor(float lifeCycleTime, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
87
88  /** \returns the Type of the particles */
89  inline PARTICLE_TYPE getType(void) const { return this->particleType; };
90  /** \returns the Material that lies on this particles */
91  inline const Material* getMaterial(void) const { return this->material; };
92  /** \returns the lifespan of the particles */
93  inline float getLifeSpan(void) const { return this->lifeSpan; };
94  /** \returns the starting-radius of the particles */
95  inline float getStartRadius(void) { return this->radiusAnim.getValue(0.0); };
96  /** \returns the end-radius of the particles */
97  inline float getEndRadius(void) { return this->radiusAnim.getValue(1.0); };
98  /** \returns the conserve-factor of the particles */
99  inline float getConserve(void) const { return this->conserve; };
100  /** \returns the initial mass of the particles */
101  inline float getMass(void) const { return this->initialMass; };
102
103  unsigned int getFaceCount(void) const;
104
105
106  virtual void applyField(Field* field);
107  /** \brief this is an empty function, because the Physics are implemented in tick \param dt: useless here */
108  virtual void tickPhys(float dt) {};
109
110  void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0);
111
112  virtual void tick(float dt);
113  virtual void draw(void) const;
114
115  void debug(void);
116
117 private:
118  float             conserve;            //!< How much energy gets conserved to the next Tick.
119  float             lifeSpan;            //!< Initial lifetime of a Particle.
120  float             randomLifeSpan;      //!< A random value for the Lifespan (around the initial lifetime)
121  float             initialMass;         //!< The initial Mass of the Particle
122  float             randomInitialMass;   //!< The random initial Mass of the Particle
123
124  int               maxCount;            //!< The maximum count of Particles.
125  int               count;               //!< The current count of Particles.
126  PARTICLE_TYPE     particleType;        //!< A type for all the Particles
127  Material*         material;            //!< A Material for all the Particles.
128  Model*            model;               //!< A Model to be displayed (PARTICLE_MODEL)
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  // per particle attributes
136  QuickAnimation    radiusAnim;          //!< Animation of the radius
137  QuickAnimation    randRadiusAnim;      //!< Animation of the random Value of the radius
138  QuickAnimation    massAnim;            //!< Animation of the mass
139  QuickAnimation    randMassAnim;        //!< Animation of the random Mass
140  QuickAnimation    colorAnim[4];        //!< Animation of the 4 colors (r,g,b,a)
141};
142
143#endif /* _PARTICLE_SYSTEM_H */
Note: See TracBrowser for help on using the repository browser.