Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3934 in orxonox.OLD


Ignore:
Timestamp:
Apr 23, 2005, 2:27:17 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/particleEngine: particles get deleted after theit life is over

Location:
orxonox/branches/particleEngine/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/particleEngine/src/defs/debug.h

    r3875 r3934  
    7272#define DEBUG_MODULE_FONT               1
    7373#define DEBUG_MODULE_ANIM               1
     74#define DEBUG_MODULE_PARTICLE           4
    7475
    7576#define DEBUG_MODULE_NULL_PARENT        0
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.cc

    r3933 r3934  
    112112{
    113113  // saving the time
    114   float countF = (dt+this->saveTime) * this->emissionRate;
    115   int count = (int)round(countF);
    116   this->saveTime = countF - (float)count;
    117 
    118   printf( "%d::%f::emmit %f\n", count, countF, emissionRate);
     114  float count = (dt+this->saveTime) * this->emissionRate;
     115  this->saveTime = modff(count, &count);
     116  this->saveTime /= this->emissionRate;
    119117
    120118  for (int i = 0; i <= count; i++)
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.cc

    r3932 r3934  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PARTICLE
    1717
    1818#include "particle_system.h"
     
    3232   \todo this constructor is not jet implemented - do it
    3333*/
    34 ParticleSystem::ParticleSystem (unsigned int count, PARTICLE_TYPE type)
     34ParticleSystem::ParticleSystem (unsigned int maxCount, PARTICLE_TYPE type)
    3535{
    3636   this->setClassName ("ParticleSystem");
    3737
     38   this->maxCount = maxCount;
     39   this->count = 0;
    3840   this->particleType = type;
    3941   this->particles = NULL;
    4042   this->conserve = 1.0;
    41    this->setLifeSpan(5.0);
     43   this->setLifeSpan(.1);
    4244
    4345   ParticleEngine::getInstance()->addSystem(this);
     
    6264void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan)
    6365{
    64 
     66  this->lifeSpan = lifeSpan;
     67  this->randomLifeSpan = randomLifeSpan;
    6568}
    6669
     
    7982void ParticleSystem::tick(float dt)
    8083{
    81   Particle* tmpPart = particles;
    82   while (likely(tmpPart != NULL))
     84  Particle* tickPart = particles;  // the particle to Tick
     85  Particle* prevPart = NULL;       //
     86  while (likely(tickPart != NULL))
    8387    {
    84       tmpPart->position = tmpPart->position + tmpPart->velocity;
     88         
     89      tickPart->position = tickPart->position + tickPart->velocity;
     90      // many more to come
     91     
    8592
    86       // many more to come
    8793
    88       tmpPart = tmpPart->next;
     94
     95
     96
     97      // find out if we have to delete tickPart
     98      if ((tickPart->timeToLive -= dt) <= 0)
     99        {
     100          // remove the particle from the list
     101          if (likely(prevPart != NULL))
     102            {
     103              prevPart->next = tickPart->next;
     104              delete tickPart;
     105              tickPart = prevPart->next;
     106            }
     107          else
     108            {
     109              prevPart = NULL;
     110              this->particles = tickPart->next;
     111              delete tickPart;
     112              tickPart = this->particles;
     113            }
     114          --this->count;
     115          printf("deleted particle: count %d\n", count);
     116        }
     117      else
     118        {     
     119          prevPart = tickPart;
     120          tickPart = tickPart->next;
     121        }
    89122    }
    90123}
     
    92125void ParticleSystem::draw(void)
    93126{
    94   Particle* tmpPart = particles;
    95   if (likely(tmpPart != NULL))
     127  Particle* drawPart = particles;
     128  if (likely(drawPart != NULL))
    96129    {
    97       glBegin(GL_POINTS);
    98       while (likely(tmpPart != NULL))
     130      glBegin(GL_TRIANGLES);
     131      while (likely(drawPart != NULL))
    99132        {
    100133          // draw in DOT mode
    101           glVertex3f(tmpPart->position.x, tmpPart->position.y, tmpPart->position.z);
     134          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    102135         
    103136         
    104           tmpPart = tmpPart->next;
     137          drawPart = drawPart->next;
    105138        }
    106139      glEnd();
     
    111144void ParticleSystem::addParticle(Vector position, Vector velocity, unsigned int data)
    112145{
    113   // if it is the first Particle
    114   if (unlikely(particles == NULL))
     146  if (this->count <= this->maxCount)
    115147    {
    116       this->particles = new Particle;
    117       this->particles->next = NULL;
     148      // if it is the first Particle
     149      if (unlikely(particles == NULL))
     150        {
     151          this->particles = new Particle;
     152          this->particles->next = NULL;
     153        }
     154      // filling the List from the beginning
     155      else
     156        {
     157          Particle* tmpPart = new Particle;
     158          tmpPart->next = this->particles;
     159          this->particles = tmpPart;
     160        }
     161     
     162      particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan;
     163      particles->position = position;
     164      particles->velocity = velocity;
     165      //  particle->rotation = ; //! \todo rotation is once again something to be done.
     166      particles->mass = this->initialMass + (random()/RAND_MAX)* this->randomInitialMass;
     167      particles->radius = this->startRadius + (random()/RAND_MAX)*this->randomRadius;
     168
     169      ++this->count;
    118170    }
    119   // filling the List from the beginning
    120171  else
    121     {
    122       Particle* tmpPart = new Particle;
    123       tmpPart->next = this->particles;
    124       this->particles = tmpPart;
    125     }
    126  
    127   particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan;
    128   particles->position = position;
    129   particles->velocity = velocity;
    130   //  particle->rotation = ; //! \todo rotation is once again something to be done.
    131   particles->mass = this->initialMass + (random()/RAND_MAX)* this->randomInitialMass;
    132   particles->radius = this->startRadius + (random()/RAND_MAX)*this->randomRadius;
     172    PRINTF(4)("maximum count of particles reached not adding any more\n");
    133173}
    134174
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.h

    r3932 r3934  
    4444
    4545 public:
    46   ParticleSystem(unsigned int particleCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
     46  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
    4747  virtual ~ParticleSystem();
    4848
     
    6767 
    6868  // particles
    69   int maxCount;              //!< the count of Particles for this ParticleSystem.
     69  int maxCount;              //!< The maximum count of Particles.
     70  int count;                 //!< The current count of Particles.
    7071  PARTICLE_TYPE particleType;//!< A type for all the Particles
    7172  Material* material;        //!< A Material for all the Particles.
  • orxonox/branches/particleEngine/src/orxonox.cc

    r3790 r3934  
    3636
    3737#include <string.h>
    38 int verbose = 3;
     38int verbose = 4;
    3939
    4040using namespace std;
  • orxonox/branches/particleEngine/src/story_entities/world.cc

    r3933 r3934  
    377377            this->glmis->step();
    378378           
    379             testEmitter = new ParticleEmitter(Vector(1,0,0), 20.0, 10000.0, .1);
     379            testEmitter = new ParticleEmitter(Vector(1,0,0), 0.0, 124.0, .1);
    380380            testEmitter->setParent(localPlayer);
    381             testSystem = new ParticleSystem();
     381            testSystem = new ParticleSystem(100000);
    382382
    383383            ParticleEngine::getInstance()->addConnection(testEmitter, testSystem);
Note: See TracChangeset for help on using the changeset viewer.