Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: useless stuff :)

File size: 6.5 KB
RevLine 
[4597]1/*!
[5039]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
[4602]17// Forward Declaration
18class TiXmlElement;
19
[4478]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
[3956]26
[3930]27//! An enumerator for the different types of particles.
[4597]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};
[3930]37
[4478]38#define PARTICLE_DEFAULT_MAX_COUNT    200               //!< A default count of particles in the system.
[3942]39#define PARTICLE_DEFAULT_TYPE         PARTICLE_SPRITE   //!< A default type of the system.
[3930]40
[3925]41// FORWARD DEFINITION
[3926]42class Material;
[3930]43class ParticleEmitter;
[4338]44class Field;
[3543]45
[3925]46//! A struct for one Particle
47typedef struct Particle
48{
[4493]49  float         lifeTime;            //!< The time this particle has to live.
50  float         lifeCycle;           //!< The fraction of time passed. (in percentage of its lifeTime)
[4338]51
[4493]52  Vector        position;            //!< The current position of this particle.
[4687]53  Vector        velocity;            //!< The current velocity of this Particle.
[4493]54  Vector        extForce;            //!< The external Force that influences this Particle.
[4687]55  Quaternion    orientation;         //!< The current orientation of this Particle.
56  Quaternion    momentum;            //!< The current angular momentum (spin) of this Particle.
57  float         mass;                //!< The mass of this Particle.
[4493]58  float         massRand;            //!< A random mass
[4687]59  float         radius;              //!< The current size of this Particle.
[4493]60  float         radiusRand;          //!< a random Radius
61  GLfloat       color [4];           //!< A Color for the particles.
[3930]62
[4493]63  Particle*     next;                //!< pointer to the next particle in the List. (NULL if no preceding one)
[3925]64};
[3543]65
[4394]66//! A class to handle ParticleSystems
[4493]67class ParticleSystem : public WorldEntity, public PhysicsInterface {
[4597]68
[1904]69 public:
[4176]70  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT,
[4597]71                 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
[4602]72  ParticleSystem(const TiXmlElement* root);
[3925]73  virtual ~ParticleSystem();
[1853]74
[4746]75  void init();
[4602]76  void loadParams(const TiXmlElement* root);
77
[4725]78  void setType(const char* particleType);
[3942]79  void setType(PARTICLE_TYPE particleType, int count = 0);
[3930]80  void setMaterial(Material* material);
[4663]81  void setModel(const char* modelName = NULL);
[3931]82  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
[3932]83  void setConserve(float conserve);
[4727]84  void setMaxCount(int maxCount);
[3245]85
[4430]86  /* Per-Particle-Attributes */
87  void setRadius(float lifeCycleTime, float radius, float randRadius = 0.0);
88  void setMass(float lifeCycleTime, float mass, float randMass = 0.0);
[4725]89  void setColor(float lifeCycleTime, float red, float green, float blue, float alpha);
[4338]90
[4836]91  /** @returns the Type of the particles */
[4746]92  inline PARTICLE_TYPE getType() const { return this->particleType; };
[4836]93  /** @returns the Material that lies on this particles */
[4746]94  inline const Material* getMaterial() const { return this->material; };
[4836]95  /** @returns the lifespan of the particles */
[4746]96  inline float getLifeSpan() const { return this->lifeSpan; };
[4836]97  /** @returns the starting-radius of the particles */
[4746]98  inline float getStartRadius() { return this->radiusAnim.getValue(0.0); };
[4836]99  /** @returns the end-radius of the particles */
[4746]100  inline float getEndRadius() { return this->radiusAnim.getValue(1.0); };
[4836]101  /** @returns the conserve-factor of the particles */
[4746]102  inline float getConserve() const { return this->conserve; };
[4836]103  /** @returns the initial mass of the particles */
[4746]104  inline float getMass() const { return this->initialMass; };
[4338]105
[4746]106  virtual unsigned int getFaceCount() const;
[4677]107
108
[4395]109  virtual void applyField(Field* field);
[4836]110  /** \brief this is an empty function, because the Physics are implemented in tick @param dt: useless here */
[4396]111  virtual void tickPhys(float dt) {};
[4338]112
[4690]113  void addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data = 0);
[4394]114
[4493]115  virtual void tick(float dt);
[4746]116  virtual void draw() const;
[3931]117
[4746]118  void debug() const;
[3944]119
[3245]120 private:
[4478]121  float             conserve;            //!< How much energy gets conserved to the next Tick.
122  float             lifeSpan;            //!< Initial lifetime of a Particle.
123  float             randomLifeSpan;      //!< A random value for the Lifespan (around the initial lifetime)
124  float             initialMass;         //!< The initial Mass of the Particle
125  float             randomInitialMass;   //!< The random initial Mass of the Particle
[3938]126
[4478]127  int               maxCount;            //!< The maximum count of Particles.
128  int               count;               //!< The current count of Particles.
129  PARTICLE_TYPE     particleType;        //!< A type for all the Particles
130  Material*         material;            //!< A Material for all the Particles.
131  Particle*         particles;           //!< A list of particles of this System.
132  Particle*         deadList;            //!< A list of dead Particles in the System.
[3932]133
[4478]134  GLuint*           glID;                //!< A List of different gl-List-ID's
[4597]135  GLuint            dialectCount;        //!< How many different types of particles are there in the Particle System
[4421]136
[4431]137  // per particle attributes
[4493]138  QuickAnimation    radiusAnim;          //!< Animation of the radius
139  QuickAnimation    randRadiusAnim;      //!< Animation of the random Value of the radius
140  QuickAnimation    massAnim;            //!< Animation of the mass
141  QuickAnimation    randMassAnim;        //!< Animation of the random Mass
142  QuickAnimation    colorAnim[4];        //!< Animation of the 4 colors (r,g,b,a)
[1853]143};
144
[3925]145#endif /* _PARTICLE_SYSTEM_H */
Note: See TracBrowser for help on using the repository browser.