Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 16, 2005, 12:55:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/physics: reimplemented the lifeTime function of particles (a little bit slower, but much more efficient)
Color also implemented with the new TimeCode

File:
1 edited

Legend:

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

    r4190 r4192  
    5353  this->setRadius(1.0, 1.0, 0.0);
    5454  this->setType(type, 1);
     55  this->setColor(1.0,1.0,1.0,1.0, .5,.5,.5,.5, .0,.0,.0,.0);
    5556  ParticleEngine::getInstance()->addSystem(this);
    5657}
     
    198199}
    199200
     201
     202/**
     203   \brief Tells the ParticleSystem how it should iterate the color over time
     204   \param ....
     205*/
     206void ParticleSystem::setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba,
     207                              GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma,
     208                              GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea)
     209{
     210  this->startColor[0] = br;
     211  this->startColor[1] = bg;
     212  this->startColor[2] = bb;
     213  this->startColor[3] = ba;
     214
     215  this->midColor[0] = mr;
     216  this->midColor[1] = mg;
     217  this->midColor[2] = mb;
     218  this->midColor[3] = ma;
     219
     220  this->endColor[0] = er;
     221  this->endColor[1] = eg;
     222  this->endColor[2] = eb;
     223  this->endColor[3] = ea;
     224}
     225
    200226/**
    201227   \brief ticks the system.
     
    217243      tickPart->extForce = Vector(0,0,0);
    218244
     245      // applying Color
     246      //! \todo better algorithm to do this \todo also implement the midColor
     247      tickPart->color[0] = this->startColor[0] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[0];
     248      tickPart->color[1] = this->startColor[1] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[1];
     249      tickPart->color[2] = this->startColor[2] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[2];
     250      tickPart->color[3] = this->startColor[3] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[3];
     251
    219252      // many more to come
    220253
     
    222255        tickPart->velocity = tickPart->velocity * this->conserve;
    223256      // find out if we have to delete tickPart
    224       if ((tickPart->timeToLive -= dt) <= 0)
     257      if ((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0)
    225258        {
    226259          // remove the particle from the list
     
    267300   \brief draws all the Particles of this System
    268301   \param the time passed in seconds (since the last draw)
     302
     303   The Cases in this Function all do the same:
     304   Drawing all the particles with the appropriate Type.
     305   This is just the fastest Way to do this, but will most likely be changed in the future.
    269306*/
    270307void ParticleSystem::draw(float dt)
    271308{
    272309  glPushAttrib(GL_ENABLE_BIT);
    273   //  material->select();
     310  glDisable(GL_LIGHTING);
     311
    274312  Particle* drawPart = particles;
    275 
     313     
    276314  switch (this->particleType)
    277315    {
     316    default:
    278317    case PARTICLE_SPRITE:
    279       GLdouble projMat[16];
    280       GLfloat drawPartPos[4];
    281       glGetDoublev(GL_PROJECTION_MATRIX, projMat);
    282      
    283318      glMatrixMode(GL_MODELVIEW);
    284319      glDisable(GL_DEPTH_TEST);
    285       glDisable(GL_LIGHTING);
    286            material->select();
     320
     321      material->select();
     322      //      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    287323     
    288324
    289325      while (likely(drawPart != NULL))
    290326        {
     327          glColor4fv(drawPart->color);
    291328          //! \todo implement a faster code for the look-at Camera algorithm.
    292329
    293           Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera();
     330          Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera();  //!< \todo MUST be different
    294331          Vector cameraPos = camera->getAbsCoor();
    295332          Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
     
    326363          drawPart = drawPart->next;
    327364        }
    328       glEnable(GL_LIGHTING);
    329       glEnable(GL_DEPTH_TEST);
    330365
    331366     
    332367      break;
    333     default:
    334368
    335369    case PARTICLE_SPARK:
     
    338372      while (likely(drawPart != NULL))
    339373        {
     374          glColor4fv(drawPart->color);
    340375          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    341376          glVertex3f(drawPart->position.x - drawPart->velocity.x,
     
    351386      while (likely(drawPart != NULL))
    352387        {
     388          glColor4fv(drawPart->color);
     389
    353390          glLineWidth(drawPart->radius);
    354391
     
    405442        }
    406443     
    407       particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
     444      particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
     445      particles->lifeCycle = 0.0;
    408446      particles->position = position;
    409447      particles->velocity = velocity;
     
    413451      particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius;
    414452     
    415       particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
     453      particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->lifeTime;
    416454
    417455      ++this->count;
Note: See TracChangeset for help on using the changeset viewer.