Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2005, 11:27:40 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.cc

    r3966 r4217  
    3535{
    3636   this->setClassName ("ParticleSystem");
     37   this->material = NULL;
    3738   this->name = NULL;
    3839   this->maxCount = maxCount;
    3940   this->count = 0;
    40    this->particleType = type;
    4141   this->particles = NULL;
    42    this->setConserve(.8);
    43    this->setLifeSpan(.1);
     42   this->deadList = NULL;
     43   this->setConserve(1);
     44   this->setLifeSpan(1);
    4445   this->setInheritSpeed(0);
    4546   this->glID = NULL;
    4647   this->setRadius(1.0, 1.0, 0.0);
    47    this->setType(PARTICLE_SPRITE, 1);
     48   this->setType(type, 1);
    4849   ParticleEngine::getInstance()->addSystem(this);
    4950}
     
    5354   \brief standard deconstructor
    5455*/
    55 ParticleSystem::~ParticleSystem() 
     56ParticleSystem::~ParticleSystem()
    5657{
    5758  // delete what has to be deleted here
    5859   ParticleEngine::getInstance()->removeSystem(this);
     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   if (this->material)
     78     delete this->material;
    5979}
    6080
     
    199219            {
    200220              prevPart->next = tickPart->next;
    201               delete tickPart;
     221              tickPart->next = this->deadList;
     222              this->deadList = tickPart;
    202223              tickPart = prevPart->next;
    203224            }
     
    206227              prevPart = NULL;
    207228              this->particles = tickPart->next;
    208               delete tickPart;
     229              tickPart->next = this->deadList;
     230              this->deadList = tickPart;
    209231              tickPart = this->particles;
    210232            }
     
    221243/**
    222244   \brief draws all the Particles of this System
    223 */
    224 void ParticleSystem::draw(void)
    225 {
     245   \param the time passed in seconds (since the last draw)
     246*/
     247void ParticleSystem::draw(float dt)
     248{
     249  glPushAttrib(GL_ENABLE_BIT);
    226250  //  material->select();
    227 
    228 
    229   glMatrixMode(GL_MODELVIEW);
    230   //  glDisable(GL_LIGHTING);
    231   material->select();
    232 
    233251  Particle* drawPart = particles;
    234   if (likely(drawPart != NULL))
     252
     253  switch (this->particleType)
    235254    {
    236       glBegin(GL_POINTS);
     255    case PARTICLE_SPRITE:
     256      glMatrixMode(GL_MODELVIEW);
     257      //  glDisable(GL_LIGHTING);
     258      material->select();
     259      glDisable(GL_DEPTH_TEST);
    237260      while (likely(drawPart != NULL))
    238261        {
    239           // draw in DOT mode
    240262          glPushMatrix();
    241263          glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     
    243265          glCallList(*this->glID);
    244266         
    245           //              glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     267          //glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    246268          drawPart = drawPart->next;
    247269          glPopMatrix();
    248270        }
     271      //      glEnd();
     272     
     273      //  glEnable(GL_LIGHTING);
     274     
     275      glEnable(GL_DEPTH_TEST);
     276      break;
     277    default:
     278
     279    case PARTICLE_SPARK:
     280      glEnable(GL_LINE_SMOOTH);
     281      glBegin(GL_LINES);
     282      while (likely(drawPart != NULL))
     283        {
     284          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     285          glVertex3f(drawPart->position.x - drawPart->velocity.x,
     286                     drawPart->position.y - drawPart->velocity.y,
     287                     drawPart->position.z - drawPart->velocity.z);
     288          drawPart = drawPart->next;
     289        }
    249290      glEnd();
     291      break;
     292     
     293    case PARTICLE_DOT:
     294      glBegin(GL_POINTS);
     295      while (likely(drawPart != NULL))
     296        {
     297          glLineWidth(drawPart->radius);
     298
     299          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     300          drawPart = drawPart->next;
     301        }
     302      glEnd();
     303      break;
    250304    }
     305  glPopAttrib();
    251306}
    252307
     
    264319      if (unlikely(particles == NULL))
    265320        {
    266           this->particles = new Particle;
     321          if (likely(deadList != NULL))
     322            {
     323              this->particles = this->deadList;
     324              deadList = deadList->next;
     325            }
     326          else
     327            {
     328              PRINTF(5)("Generating new Particle\n");
     329              this->particles = new Particle;
     330            }
    267331          this->particles->next = NULL;
    268332        }
     
    270334      else
    271335        {
    272           Particle* tmpPart = new Particle;
     336          Particle* tmpPart;
     337          if (likely(deadList != NULL))
     338            {
     339              tmpPart = this->deadList;
     340              deadList = deadList->next;
     341            }
     342          else
     343            {
     344              PRINTF(5)("Generating new Particle\n");
     345              tmpPart = new Particle;
     346            }
    273347          tmpPart->next = this->particles;
    274348          this->particles = tmpPart;
    275349        }
    276350     
    277       particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan;
     351      particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
    278352      particles->position = position;
    279353      particles->velocity = velocity;
    280354
    281355      //  particle->rotation = ; //! \todo rotation is once again something to be done.
    282       particles->mass = this->initialMass + (random()/RAND_MAX -.5)* this->randomInitialMass;
    283       particles->radius = this->startRadius + (random()/RAND_MAX-.5)*this->randomStartRadius;
    284      
    285       particles->radiusIt = (this->endRadius + (random()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
     356      particles->mass = this->initialMass + (rand()/RAND_MAX -.5)* this->randomInitialMass;
     357      particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius;
     358     
     359      particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
    286360
    287361      ++this->count;
    288362    }
    289363  else
    290     PRINTF(4)("maximum count of particles reached not adding any more\n");
     364    PRINTF(5)("maximum count of particles reached not adding any more\n");
    291365}
    292366
     
    298372  PRINT(0)("  ParticleSystem %s\n", this->name);
    299373  PRINT(0)("  ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);
    300 }
     374  if (deadList)
     375    {
     376      PRINT(0)("  - ParticleDeadList is used: ");
     377      int i = 1;
     378      Particle* tmpPart = this->deadList;
     379      while (tmpPart = tmpPart->next) ++i;
     380      PRINT(0)("count: %d\n", i);
     381    }
     382}
Note: See TracChangeset for help on using the changeset viewer.