Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 16, 2006, 7:30:56 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the most evil for (int i=0; i <'=' …) bug ever…

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

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/particle_system.cc

    r7221 r7300  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
     16#define DEBUG_SPECIAL_MODULE 5 //DEBUG_MODULE_GRAPHICS
    1717
    1818#include "particle_system.h"
     
    4040ParticleSystem::ParticleSystem (unsigned int maxCount)
    4141{
    42   this->init();
    43 
    44   this->setMaxCount(maxCount);
    45 }
    46 
    47 /**
    48  *  standard deconstructor
    49 */
    50 ParticleSystem::~ParticleSystem()
    51 {
    52   // deleting all the living Particles
    53   while (this->particles)
    54   {
    55     Particle* tmpDelPart = this->particles;
    56     this->particles = this->particles->next;
    57     delete tmpDelPart;
    58   }
    59 
    60   // deleting all the dead particles
    61   while (this->deadList)
    62   {
    63     Particle* tmpDelPart = this->deadList;
    64     this->deadList = this->deadList->next;
    65     delete tmpDelPart;
    66   }
    67 
    68   while(!this->emitters.empty())
    69   {
    70     this->removeEmitter(this->emitters.front());
    71   }
    72 
    73 }
    74 
    75 /**
    76  * @brief initializes the ParticleSystem with default values
    77  */
    78 void ParticleSystem::init()
    79 {
    8042  this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem");
    8143
     
    8446  this->particles = NULL;
    8547  this->deadList = NULL;
    86   this->setConserve(1);
    87   this->setLifeSpan(1);
     48  this->conserve = 1.0;
     49  this->lifeSpan = 1.0; this->randomLifeSpan = 0.0;
    8850
    8951  this->toList(OM_ENVIRON);
     52
     53  this->maxCount = maxCount;
     54}
     55
     56/**
     57 *  standard deconstructor
     58*/
     59ParticleSystem::~ParticleSystem()
     60{
     61  // deleting all the living Particles
     62  while (this->particles)
     63  {
     64    Particle* tmpDelPart = this->particles;
     65    this->particles = this->particles->next;
     66    delete tmpDelPart;
     67  }
     68
     69  // deleting all the dead particles
     70  while (this->deadList)
     71  {
     72    Particle* tmpDelPart = this->deadList;
     73    this->deadList = this->deadList->next;
     74    delete tmpDelPart;
     75  }
     76
     77  while(!this->emitters.empty())
     78  {
     79    this->removeEmitter(this->emitters.front());
     80  }
     81
    9082}
    9183
     
    127119
    128120  LoadParam(root, "precache", this, ParticleSystem, precache)
    129       .describe("Precaches the ParticleSystem for %1 seconds, %2 times per Second")
    130       .defaultValues(1.0, 25.0);
     121  .describe("Precaches the ParticleSystem for %1 seconds, %2 times per Second")
     122  .defaultValues(1.0, 25.0);
    131123}
    132124
     
    160152
    161153/**
    162 * @param maxCount the maximum count of particles that can be emitted
    163  */
    164 void ParticleSystem::setMaxCount(int maxCount)
     154 * @param maxCount the maximum count of particles that can be emitted
     155 */
     156void ParticleSystem::setMaxCount(unsigned int maxCount)
    165157{
    166158  this->maxCount = maxCount;
     159  PRINTF(4)("MAXCOUNT of %s::%s is %d\n", this->getClassName(), this->getName(),maxCount);
    167160}
    168161
    169162// setting properties
    170163/**
    171  *  Sets the lifespan of newly created particles
     164 * @brief Sets the lifespan of newly created particles
     165 * @param lifeSpan the LifeSpan of each particle in the System
     166 * @param randomLifeSpan the Deviation from lifeSpan (random Value).
    172167*/
    173168void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan)
     
    175170  this->lifeSpan = lifeSpan;
    176171  this->randomLifeSpan = randomLifeSpan;
    177 }
    178 
    179 /**
    180  *  sets the conserve Factor of newly created particles
    181 */
     172  PRINTF(4)("LifeTime of %s::%s is %f\n", this->getClassName(), this->getName(), lifeSpan);
     173}
     174
     175/**
     176 * @brief sets the conserve Factor of newly created particles
     177 * @param conserve sets the conserve factor of each particle.
     178 * Conserve is the ammount of energy a particle takes from the last Frame into the next.
     179 * A Value of 1 means, that all energy is conserved, a Value of 0 means infinit friction.
     180 */
    182181void ParticleSystem::setConserve(float conserve)
    183182{
     
    188187  else
    189188    this->conserve = conserve;
     189
     190  PRINTF(4)("Conserve of %s::%s is %f\n", this->getClassName(), this->getName(),conserve);
    190191}
    191192
     
    194195/////////////////////////////
    195196/**
    196  * sets a key in the radius-animation on a per-particle basis
     197 * @brief sets a key in the radius-animation on a per-particle basis
    197198 * @param lifeCycleTime the time (partilceLifeTime/particleAge) [0-1]
    198199 * @param radius the radius at this position
     
    203204  this->radiusAnim.changeEntry(lifeCycleTime, radius);
    204205  this->randRadiusAnim.changeEntry(lifeCycleTime, randRadius);
    205 }
    206 
    207 /**
    208  *  sets a key in the mass-animation on a per-particle basis
     206
     207  PRINTF(4)("Radius of %s::%s at timeSlice %f is %f with a Random of %f\n",
     208    this->getClassName(), this->getName(),lifeCycleTime, radius, randRadius);
     209}
     210
     211/**
     212 * @brief sets a key in the mass-animation on a per-particle basis
    209213 * @param lifeCycleTime the time (partilceLifeTime/particleAge) [0-1]
    210214 * @param mass the mass at this position
     
    218222
    219223/**
    220  * sets a key in the color-animation on a per-particle basis
     224 * @brief sets a key in the color-animation on a per-particle basis
    221225 * @param lifeCycleTime: the time (partilceLifeTime/particleAge) [0-1]
    222226 * @param red: red
     
    231235  this->colorAnim[2].changeEntry(lifeCycleTime, blue);
    232236  this->colorAnim[3].changeEntry(lifeCycleTime, alpha);
     237
     238  PRINTF(4)("Color of %s::%s on timeslice %f is r:%f g:%f b:%f a:%f\n",
     239    this->getClassName(), this->getName(), lifeCycleTime, red, green, blue, alpha);
    233240}
    234241
     
    267274void ParticleSystem::precache(unsigned int seconds, unsigned int ticksPerSecond)
    268275{
    269 
    270276  std::list<ParticleEmitter*>::iterator emitter;
    271277  for (emitter = this->emitters.begin(); emitter != this->emitters.end(); emitter++)
     
    280286
    281287/**
    282  * ticks the system.
     288 * @brief ticks the system.
    283289 * @param dt the time to tick all the Particles of the System
    284290
     
    357363  * @param field the Field to apply.
    358364 */
    359 void ParticleSystem::applyField(Field* field)
     365void ParticleSystem::applyField(const Field* field)
    360366{
    361367  Particle* tickPart = particles;
     
    376382}
    377383
    378 
    379 /**
    380  *  draws all the Particles of this System
    381 
    382    The Cases in this Function all do the same:
    383    Drawing all the particles with the appropriate Type.
    384    This is just the fastest Way to do this, but will most likely be changed in the future.
    385  */
    386 // void ParticleSystem::draw() const
    387 // {
    388 //   glPushAttrib(GL_ENABLE_BIT);
    389 //
    390 //   Particle* drawPart = particles;
    391 //
    392 //   switch (this->particleType)
    393 //   {
    394 //
    395 //     case PARTICLE_MODEL:
    396 //       {
    397 //       }
    398 //       break;
    399 //
    400 //     case PARTICLE_DOT:
    401 //       glDisable(GL_LIGHTING);
    402 //       glBegin(GL_POINTS);
    403 //       while (likely(drawPart != NULL))
    404 //       {
    405 //         glColor4fv(drawPart->color);
    406 //
    407 //         glLineWidth(drawPart->radius);
    408 //
    409 //         glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    410 //         drawPart = drawPart->next;
    411 //       }
    412 //       glEnd();
    413 //       break;
    414 //   }
    415 //   glPopAttrib();
    416 // }
    417 
    418 /**
    419  *  adds a new Particle to the System
     384/**
     385 * @brief adds a new Particle to the System
    420386 * @param position the initial position, where the particle gets emitted.
    421387 * @param velocity the initial velocity of the particle.
     
    477443  }
    478444  else
    479     PRINTF(5)("maximum count of particles reached not adding any more\n");
     445    PRINTF(4)("maximum count of particles reached not adding any more\n");
    480446}
    481447
     
    485451void ParticleSystem::debug() const
    486452{
    487   PRINT(0)("  ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, ((this->maxCount!=0)?100*this->count/this->maxCount:0));
    488   if (deadList)
     453  PRINT(0)("  ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n",
     454           this->count,
     455           this->emitters.size(),
     456           this->maxCount,
     457           ((this->maxCount!=0)?100*this->count/this->maxCount:0));
     458  if (this->deadList)
    489459  {
    490460    PRINT(0)("  - ParticleDeadList is used: ");
  • trunk/src/lib/particles/particle_system.h

    r7027 r7300  
    6060  virtual ~ParticleSystem();
    6161
    62   void init();
    6362  virtual void loadParams(const TiXmlElement* root);
    6463  void loadEmitters(const TiXmlElement* root);
     
    6665  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
    6766  void setConserve(float conserve);
    68   void setMaxCount(int maxCount);
     67  void setMaxCount(unsigned int maxCount);
    6968
    7069  /* Per-Particle-Attributes */
     
    9493  void removeEmitter(ParticleEmitter* emitter);
    9594
    96   virtual void applyField(Field* field);
     95  virtual void applyField(const Field* field);
    9796  /** @brief this is an empty function, because the Physics are implemented in tick @param dt: useless here */
    9897  virtual void tickPhys(float dt) {};
     
    114113  float             randomInitialMass;   //!< The random initial Mass of the Particle
    115114
    116   int               maxCount;            //!< The maximum count of Particles.
    117   int               count;               //!< The current count of Particles.
     115  unsigned int      maxCount;            //!< The maximum count of Particles.
     116  unsigned int      count;               //!< The current count of Particles.
    118117  Particle*         particles;           //!< A list of particles of this System.
    119118  Particle*         deadList;            //!< A list of dead Particles in the System.
Note: See TracChangeset for help on using the changeset viewer.