Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6621 was 6621, checked in by bensch, 18 years ago

orxonox/trunk: particle derivate… still working on this

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