Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: inheritSpeed now property of particle_emitter. system not friend emitter anymore

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