Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6623 in orxonox.OLD for trunk/src/lib/particles


Ignore:
Timestamp:
Jan 20, 2006, 12:54:20 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: particle Systems and Emitters are loaded and cleaned up nicely

Location:
trunk/src/lib/particles
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/Makefile.am

    r6621 r6623  
    99                        particle_system.cc \
    1010                        sprite_particles.cc \
     11                        spark_particles.cc \
     12                        \
    1113                        quick_animation.cc
    1214
     
    1719                        particle_system.h \
    1820                        sprite_particles.h \
     21                        spark_particles.h \
     22                        \
    1923                        quick_animation.h
  • trunk/src/lib/particles/particle_emitter.cc

    r6620 r6623  
    6464ParticleEmitter::~ParticleEmitter ()
    6565{
    66 }
    67 
    68 /**
    69   \brief initializes default values of a ParitcleEmitter
     66  this->setSystem(NULL);
     67}
     68
     69/**
     70  @brief initializes default values of a ParitcleEmitter
    7071*/
    7172void ParticleEmitter::init()
  • trunk/src/lib/particles/particle_system.cc

    r6621 r6623  
    4444
    4545  this->setMaxCount(maxCount);
    46 }
    47 
    48 /**
    49  * @brief creates a Particle System out of a XML-element
    50  * @param root: the XML-element to load from
    51  */
    52 ParticleSystem::ParticleSystem(const TiXmlElement* root)
    53 {
    54   this->init();
    55 
    56   this->loadParams(root);
    5746}
    5847
     
    7867     }
    7968
    80    if (this->material)
    81      delete this->material;
     69     while(!this->emitters.empty())
     70     {
     71       this->removeEmitter(this->emitters.front());
     72     }
     73
    8274}
    8375
     
    8981  this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem");
    9082
    91   this->material = NULL;
    9283  this->setMaxCount(PARTICLE_DEFAULT_MAX_COUNT);
    9384  this->count = 0;
     
    9687  this->setConserve(1);
    9788  this->setLifeSpan(1);
    98   this->glID = NULL;
    9989
    10090  this->toList(OM_ENVIRON);
     
    120110      .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)");
    121111
    122   LoadParam(root, "texture", this, ParticleSystem, setMaterialTexture);
    123   LoadParamXML(root, "emitter", this, ParticleSystem, addEmitterXML);
     112  LoadParamXML(root, "emitters", this, ParticleSystem, loadEmitters);
    124113
    125114  LOAD_PARAM_START_CYCLE(root, element);
     
    140129
    141130/**
     131 * @brief loads the Emitters from An XML-Root
     132 * @param root the XML-Element to load all emitters from
     133 */
     134void ParticleSystem::loadEmitters(const TiXmlElement* root)
     135{
     136  LOAD_PARAM_START_CYCLE(root, element);
     137  {
     138    BaseObject* emitter = Factory::fabricate(element);
     139    if (emitter->isA(CL_PARTICLE_EMITTER))
     140      this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter));
     141    else
     142    {
     143      PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n",
     144                emitter->getClassName(), this->getClassName(), this->getName());
     145      delete emitter;
     146    }
     147  }
     148  LOAD_PARAM_END_CYCLE(element);
     149}
     150
     151/**
    142152* @param maxCount the maximum count of particles that can be emitted
    143153 */
     
    148158
    149159// setting properties
    150 /**
    151  *  sets the material to an external material
    152  * @param material: the material to set this material to.
    153 
    154    !! important if the extern material gets deleted it MUST be unregistered here or segfault !!
    155 */
    156 void ParticleSystem::setMaterial(Material* material)
    157 {
    158   this->material = material;
    159 }
    160 
    161 void ParticleSystem::setMaterialTexture(const char* textureFile)
    162 {
    163   if (this->material != NULL)
    164     this->material->setDiffuseMap(textureFile);
    165 }
    166 
    167160/**
    168161 *  Sets the lifespan of newly created particles
     
    237230    emitter->getSystem()->removeEmitter(emitter);
    238231  this->emitters.push_back(emitter);
    239 }
    240 
    241 void ParticleSystem::addEmitterXML(const TiXmlElement* emitterRoot)
    242 {
    243   ParticleEmitter* emitter = new ParticleEmitter(emitterRoot);
    244   this->addEmitter(emitter);
    245232}
    246233
  • trunk/src/lib/particles/particle_system.h

    r6621 r6623  
    5858 public:
    5959  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);
    60   ParticleSystem(const TiXmlElement* root);
    6160  virtual ~ParticleSystem();
    6261
    6362  void init();
    6463  virtual void loadParams(const TiXmlElement* root);
     64  void loadEmitters(const TiXmlElement* root);
    6565
    66   void setMaterial(Material* material);
    67   void setMaterialTexture(const char* textureFile);
    68   void setModel(const char* modelName = NULL);
    6966  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
    7067  void setConserve(float conserve);
     
    7673  void setColor(float lifeCycleTime, float red, float green, float blue, float alpha);
    7774
    78   /** @returns the Material that lies on this particles */
    79   inline const Material* getMaterial() const { return this->material; };
    8075  /** @returns the lifespan of the particles */
    8176  inline float getLifeSpan() const { return this->lifeSpan; };
     
    9287
    9388  void addEmitter(ParticleEmitter* emitter);
    94   void addEmitterXML(const TiXmlElement* emitterRoot);
    9589  void removeEmitter(ParticleEmitter* emitter);
    9690
     
    115109  int               maxCount;            //!< The maximum count of Particles.
    116110  int               count;               //!< The current count of Particles.
    117   Material*         material;            //!< A Material for all the Particles.
    118111  Particle*         particles;           //!< A list of particles of this System.
    119112  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
    123113
    124114  std::list<ParticleEmitter*> emitters;  //!< The Emitters that do emit into this System.
  • trunk/src/lib/particles/spark_particles.cc

    r6622 r6623  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    18 #include "sprite_particles.h"
     18#include "spark_particles.h"
    1919
    2020#include "load_param.h"
     
    2828
    2929
    30 CREATE_FACTORY(SpriteParticles, CL_SPRITE_PARTICLES);
    31 
    32 SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture)
    33     ->defaultValues(1, "maps/evil-flower.png");
     30CREATE_FACTORY(SparkParticles, CL_SPARK_PARTICLES);
    3431
    3532using namespace std;
     
    3835 *  standard constructor
    3936 * @param maxCount the Count of particles in the System
    40  * @param type The Type of the SpriteParticles
     37 * @param type The Type of the SparkParticles
    4138*/
    42 SpriteParticles::SpriteParticles (unsigned int maxCount)
    43   : ParticleSystem(maxCount)
     39SparkParticles::SparkParticles (unsigned int maxCount)
     40    : ParticleSystem(maxCount)
    4441{
    4542  this->init();
     
    5047 * @param root: the XML-element to load from
    5148 */
    52 SpriteParticles::SpriteParticles(const TiXmlElement* root)
     49SparkParticles::SparkParticles(const TiXmlElement* root)
    5350{
    5451  this->init();
    5552
    56   this->loadParams(root);
     53  if (root != NULL)
     54    this->loadParams(root);
    5755}
    5856
     
    6058 *  standard deconstructor
    6159*/
    62 SpriteParticles::~SpriteParticles()
     60SparkParticles::~SparkParticles()
    6361{
    6462  // deleting all the living Particles
     
    8078
    8179/**
    82  * @brief initializes the SpriteParticles with default values
     80 * @brief initializes the SparkParticles with default values
    8381*/
    84 void SpriteParticles::init()
     82void SparkParticles::init()
    8583{
    86   this->setClassID(CL_SPRITE_PARTICLES, "SpriteParticles");
     84  this->setClassID(CL_SPARK_PARTICLES, "SparkParticles");
    8785
    8886  this->material = NULL;
     
    9492 * @param root the XML-element to load from.
    9593 */
    96 void SpriteParticles::loadParams(const TiXmlElement* root)
     94void SparkParticles::loadParams(const TiXmlElement* root)
    9795{
    98   SpriteParticles::loadParams(root);
    99 
    100   LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);
    101 }
    102 
    103 // setting properties
    104 /**
    105  * @brief sets the material to an external material
    106  * @param material: the material to set this material to.
    107  *
    108  * !! important if the extern material gets deleted it MUST be unregistered here or segfault !!
    109 */
    110 void SpriteParticles::setMaterial(Material* material)
    111 {
    112   this->material = *material;
    113 }
    114 
    115 void SpriteParticles::setMaterialTexture(const char* textureFile)
    116 {
    117   this->material.setDiffuseMap(textureFile);
     96  ParticleSystem::loadParams(root);
    11897}
    11998
     
    125104 * This is just the fastest Way to do this, but will most likely be changed in the future.
    126105 */
    127 void SpriteParticles::draw() const
     106void SparkParticles::draw() const
    128107{
    129108  glPushAttrib(GL_ENABLE_BIT);
     
    131110  Particle* drawPart = particles;
    132111
    133   glDisable(GL_LIGHTING);
    134   glMatrixMode(GL_MODELVIEW);
    135112  glDepthMask(GL_FALSE);
    136113
    137   material.select();
    138   glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
     114  glDisable(GL_LIGHTING);
     115  glEnable(GL_LINE_SMOOTH);
     116  glEnable(GL_BLEND);
    139117
    140   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    141 
    142 
     118  glBegin(GL_LINES);
    143119  while (likely(drawPart != NULL))
    144120  {
    145121    glColor4fv(drawPart->color);
    146     //! @todo implement a faster code for the look-at Camera algorithm.
    147 
    148     const PNode* camera = State::getCamera();  //!< @todo MUST be different
    149     Vector cameraPos = camera->getAbsCoor();
    150     Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
    151     Vector view = cameraTargetPos - cameraPos;
    152     Vector up = Vector(0, 1, 0);
    153     up = camera->getAbsDir().apply(up);
    154     Vector h = up.cross(view);
    155     Vector v = h.cross(view);
    156     h.normalize();
    157     v.normalize();
    158     v *= .5 * drawPart->radius;
    159     h *= .5 * drawPart->radius;
    160 
    161     glBegin(GL_TRIANGLE_STRIP);
    162     glTexCoord2i(1, 1);
    163     glVertex3f(drawPart->position.x - h.x - v.x,
    164                drawPart->position.y - h.y - v.y,
    165                drawPart->position.z - h.z - v.z);
    166     glTexCoord2i(0, 1);
    167     glVertex3f(drawPart->position.x - h.x + v.x,
    168                drawPart->position.y - h.y + v.y,
    169                drawPart->position.z - h.z + v.z);
    170     glTexCoord2i(1, 0);
    171     glVertex3f(drawPart->position.x + h.x - v.x,
    172                drawPart->position.y + h.y - v.y,
    173                drawPart->position.z + h.z - v.z);
    174     glTexCoord2i(0, 0);
    175     glVertex3f(drawPart->position.x + h.x + v.x,
    176                drawPart->position.y + h.y + v.y,
    177                drawPart->position.z + h.z + v.z);
    178 
    179     glEnd();
    180 
     122    glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     123    glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius,
     124               drawPart->position.y - drawPart->velocity.y * drawPart->radius,
     125               drawPart->position.z - drawPart->velocity.z * drawPart->radius);
    181126    drawPart = drawPart->next;
    182127  }
     128  glEnd();
     129
    183130  glDepthMask(GL_TRUE);
    184131  glPopAttrib();
  • trunk/src/lib/particles/spark_particles.h

    r6622 r6623  
    11/*!
    2  * @file particle_system.h
     2 * @file spark_particles.h
    33
    44*/
    55
    6 #ifndef _SPRITE_PARTICLE_SYSTEM_H
    7 #define _SPRITE_PARTICLE_SYSTEM_H
     6#ifndef _SPARK_PARTICLE_SYSTEM_H
     7#define _SPARK_PARTICLE_SYSTEM_H
    88
    99#include "particle_system.h"
     
    1111
    1212//! A class to handle ParticleSystems
    13 class SpriteParticles : public ParticleSystem
     13class SparkParticles : public ParticleSystem
    1414{
    1515
    1616public:
    17   SpriteParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);
    18   SpriteParticles(const TiXmlElement* root);
    19   virtual ~SpriteParticles();
     17  SparkParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);
     18  SparkParticles(const TiXmlElement* root);
     19  virtual ~SparkParticles();
    2020
    2121  virtual void loadParams(const TiXmlElement* root);
    2222
    23   void setMaterial(Material* material);
    24   void setMaterialTexture(const char* textureFile);
    25 
    26   /** @returns the Material that lies on this particles */
    27   inline const Material* getMaterial() const { return &this->material; };
    28 
    2923  virtual void draw() const;
    30 
    31   void debug() const;
    3224
    3325private:
     
    3830};
    3931
    40 #endif /* _SPRITE_PARTICLE_SYSTEM_H */
     32#endif /* _SPARK_PARTICLE_SYSTEM_H */
  • trunk/src/lib/particles/sprite_particles.cc

    r6621 r6623  
    5353{
    5454  this->init();
    55 
    56   this->loadParams(root);
     55  if (root != NULL)
     56    this->loadParams(root);
    5757}
    5858
     
    9696void SpriteParticles::loadParams(const TiXmlElement* root)
    9797{
    98   SpriteParticles::loadParams(root);
     98  ParticleSystem::loadParams(root);
    9999
    100100  LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);
  • trunk/src/lib/particles/sprite_particles.h

    r6621 r6623  
    11/*!
    2  * @file particle_system.h
     2 * @file sprite_particles.h
    33
    44*/
     
    2929  virtual void draw() const;
    3030
    31   void debug() const;
    32 
    3331private:
    3432  void init();
Note: See TracChangeset for help on using the changeset viewer.