Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/particles/particle_system.h @ 9869

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 5.8 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"
[6612]14#include <list>
[9656]15#include "color.h"
[3930]16
[4421]17#include "quick_animation.h"
18
[4602]19// Forward Declaration
20class TiXmlElement;
21
[4478]22#define PARTICLE_DOT_MASK              0x000001     //!< A Mask if the Particles should be displayed as DOTs
23#define PARTICLE_SPARK_MASK            0x000010     //!< A Mask if the Particles should be displayed as SPARKs
24#define PARTICLE_SPRITE_MASK           0x000100     //!< A Mask if the Particles should be displayed as SPRITESs
25#define PARTICLE_MODEL_MASK            0x001000     //!< A Mask if the Particles should be displayed as MODELSs
26#define PARTICLE_WORDL_ENTITY_MASK     0x010000     //!< A Mask if the Particles should be displayed as WORLD_ENTITIEs
27#define PARTICLE_MULTI_MASK            0x100000     //!< A Mask if they are Multi-partilces
[3956]28
[4478]29#define PARTICLE_DEFAULT_MAX_COUNT    200               //!< A default count of particles in the system.
[3930]30
[5405]31// FORWARD DECLARATION
[3926]32class Material;
[3930]33class ParticleEmitter;
[4338]34class Field;
[3543]35
[3925]36//! A struct for one Particle
37typedef struct Particle
38{
[4493]39  float         lifeTime;            //!< The time this particle has to live.
40  float         lifeCycle;           //!< The fraction of time passed. (in percentage of its lifeTime)
[4338]41
[4493]42  Vector        position;            //!< The current position of this particle.
[4687]43  Vector        velocity;            //!< The current velocity of this Particle.
[4493]44  Vector        extForce;            //!< The external Force that influences this Particle.
[4687]45  Quaternion    orientation;         //!< The current orientation of this Particle.
46  Quaternion    momentum;            //!< The current angular momentum (spin) of this Particle.
47  float         mass;                //!< The mass of this Particle.
[4493]48  float         massRand;            //!< A random mass
[4687]49  float         radius;              //!< The current size of this Particle.
[4493]50  float         radiusRand;          //!< a random Radius
51  GLfloat       color [4];           //!< A Color for the particles.
[3930]52
[4493]53  Particle*     next;                //!< pointer to the next particle in the List. (NULL if no preceding one)
[3925]54};
[3543]55
[4394]56//! A class to handle ParticleSystems
[4493]57class ParticleSystem : public WorldEntity, public PhysicsInterface {
[9715]58  ObjectListDeclaration(ParticleSystem);
[4597]59
[1904]60 public:
[6621]61  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);
[3925]62  virtual ~ParticleSystem();
[1853]63
[6512]64  virtual void loadParams(const TiXmlElement* root);
[6623]65  void loadEmitters(const TiXmlElement* root);
[4602]66
[3931]67  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
[3932]68  void setConserve(float conserve);
[7300]69  void setMaxCount(unsigned int maxCount);
[3245]70
[4430]71  /* Per-Particle-Attributes */
72  void setRadius(float lifeCycleTime, float radius, float randRadius = 0.0);
73  void setMass(float lifeCycleTime, float mass, float randMass = 0.0);
[4725]74  void setColor(float lifeCycleTime, float red, float green, float blue, float alpha);
[9656]75  void setColor(float lifeCycleTime, const Color& color);
[4338]76
[4836]77  /** @returns the lifespan of the particles */
[4746]78  inline float getLifeSpan() const { return this->lifeSpan; };
[4836]79  /** @returns the starting-radius of the particles */
[4746]80  inline float getStartRadius() { return this->radiusAnim.getValue(0.0); };
[4836]81  /** @returns the end-radius of the particles */
[4746]82  inline float getEndRadius() { return this->radiusAnim.getValue(1.0); };
[4836]83  /** @returns the conserve-factor of the particles */
[4746]84  inline float getConserve() const { return this->conserve; };
[4836]85  /** @returns the initial mass of the particles */
[4746]86  inline float getMass() const { return this->initialMass; };
[4338]87
[7027]88  /** @returns the count of particles in this System */
89  inline unsigned int getCount() const { return this->count; };
90  /** @returns the maximum count of particles that can be contained by this System */
91  inline unsigned int getMaxCount() const { return this->maxCount; };
92
[4746]93  virtual unsigned int getFaceCount() const;
[4677]94
[6612]95  void addEmitter(ParticleEmitter* emitter);
96  void removeEmitter(ParticleEmitter* emitter);
[4677]97
[7300]98  virtual void applyField(const Field* field);
[6621]99  /** @brief this is an empty function, because the Physics are implemented in tick @param dt: useless here */
[4396]100  virtual void tickPhys(float dt) {};
[4338]101
[4690]102  void addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data = 0);
[4394]103
[6629]104  void precache(unsigned int seconds, unsigned int ticksPerSecond = 25);
105
[4493]106  virtual void tick(float dt);
[6621]107  virtual void draw() const = 0;
[3931]108
[4746]109  void debug() const;
[3944]110
[6621]111 protected:
[4478]112  float             conserve;            //!< How much energy gets conserved to the next Tick.
113  float             lifeSpan;            //!< Initial lifetime of a Particle.
114  float             randomLifeSpan;      //!< A random value for the Lifespan (around the initial lifetime)
115  float             initialMass;         //!< The initial Mass of the Particle
116  float             randomInitialMass;   //!< The random initial Mass of the Particle
[3938]117
[7300]118  unsigned int      maxCount;            //!< The maximum count of Particles.
119  unsigned int      count;               //!< The current count of Particles.
[4478]120  Particle*         particles;           //!< A list of particles of this System.
121  Particle*         deadList;            //!< A list of dead Particles in the System.
[3932]122
[6612]123  std::list<ParticleEmitter*> emitters;  //!< The Emitters that do emit into this System.
124
[4431]125  // per particle attributes
[4493]126  QuickAnimation    radiusAnim;          //!< Animation of the radius
127  QuickAnimation    randRadiusAnim;      //!< Animation of the random Value of the radius
128  QuickAnimation    massAnim;            //!< Animation of the mass
129  QuickAnimation    randMassAnim;        //!< Animation of the random Mass
130  QuickAnimation    colorAnim[4];        //!< Animation of the 4 colors (r,g,b,a)
[1853]131};
132
[3925]133#endif /* _PARTICLE_SYSTEM_H */
Note: See TracBrowser for help on using the repository browser.