Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

File:
1 edited

Legend:

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

    r4515 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    4141{
    4242  this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem");
     43
    4344  this->material = NULL;
    4445  this->maxCount = maxCount;
     
    125126/**
    126127   \brief Sets the lifespan of newly created particles
    127 */   
     128*/
    128129void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan)
    129130{
     
    197198{
    198199  Particle* tickPart = particles;  // the particle to Tick
    199   Particle* prevPart = NULL;       // 
     200  Particle* prevPart = NULL;       //
    200201  while (likely(tickPart != NULL))
    201202    {
    202203      // applying force to the System.
    203204      if (likely (tickPart->mass > 0.0))
    204         tickPart->velocity += tickPart->extForce / tickPart->mass * dt;
     205        tickPart->velocity += tickPart->extForce / tickPart->mass * dt;
    205206
    206207      // rendering new position.
    207208      tickPart->position = tickPart->position + tickPart->velocity * dt;
    208209      tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle)
    209         + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand;
     210        + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand;
    210211
    211212      tickPart->mass = massAnim.getValue(tickPart->lifeCycle)
    212         + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand;
    213      
     213        + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand;
     214
    214215      tickPart->extForce = Vector(0,0,0);
    215216
     
    223224
    224225      if (this->conserve < 1.0)
    225         tickPart->velocity = tickPart->velocity * this->conserve;
     226        tickPart->velocity = tickPart->velocity * this->conserve;
    226227      // find out if we have to delete tickPart
    227228      if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0))
    228         {
    229           // remove the particle from the list
    230           if (likely(prevPart != NULL))
    231             {
    232               prevPart->next = tickPart->next;
    233               tickPart->next = this->deadList;
    234               this->deadList = tickPart;
    235               tickPart = prevPart->next;
    236             }
    237           else
    238             {
    239               prevPart = NULL;
    240               this->particles = tickPart->next;
    241               tickPart->next = this->deadList;
    242               this->deadList = tickPart;
    243               tickPart = this->particles;
    244             }
    245           --this->count;
    246         }
     229        {
     230          // remove the particle from the list
     231          if (likely(prevPart != NULL))
     232            {
     233              prevPart->next = tickPart->next;
     234              tickPart->next = this->deadList;
     235              this->deadList = tickPart;
     236              tickPart = prevPart->next;
     237            }
     238          else
     239            {
     240              prevPart = NULL;
     241              this->particles = tickPart->next;
     242              tickPart->next = this->deadList;
     243              this->deadList = tickPart;
     244              tickPart = this->particles;
     245            }
     246          --this->count;
     247        }
    247248      else
    248         {     
    249           prevPart = tickPart;
    250           tickPart = tickPart->next;
    251         }
    252     }
    253 }
    254 
    255 /** 
     249        {
     250          prevPart = tickPart;
     251          tickPart = tickPart->next;
     252        }
     253    }
     254}
     255
     256/**
    256257    \brief applies some force to a Particle.
    257258    \param field the Field to apply.
     
    281282
    282283  Particle* drawPart = particles;
    283      
     284
    284285  switch (this->particleType)
    285286    {
     
    289290      glDepthMask(GL_FALSE);
    290291
    291       material->select(); 
     292      material->select();
    292293      //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    293      
     294
    294295
    295296      while (likely(drawPart != NULL))
    296         {
    297           glColor4fv(drawPart->color);
    298           //! \todo implement a faster code for the look-at Camera algorithm.
    299 
    300           const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
    301           Vector cameraPos = camera->getAbsCoor();
    302           Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
    303           Vector view = cameraTargetPos - cameraPos;
    304           Vector up = Vector(0, 1, 0);
    305           up = camera->getAbsDir().apply(up);
    306           Vector h = up.cross(view);
    307           Vector v = h.cross(view);
    308           h.normalize();
    309           v.normalize();
    310           v *= .5 * drawPart->radius;
    311           h *= .5 * drawPart->radius;
    312 
    313           glBegin(GL_TRIANGLE_STRIP);
    314           glTexCoord2i(1, 1);
    315           glVertex3f(drawPart->position.x - h.x - v.x,
    316                      drawPart->position.y - h.y - v.y,
    317                      drawPart->position.z - h.z - v.z);
    318           glTexCoord2i(0, 1);
    319           glVertex3f(drawPart->position.x - h.x + v.x,
    320                      drawPart->position.y - h.y + v.y,
    321                      drawPart->position.z - h.z + v.z);
    322           glTexCoord2i(1, 0);
    323           glVertex3f(drawPart->position.x + h.x - v.x,
    324                      drawPart->position.y + h.y - v.y,
    325                      drawPart->position.z + h.z - v.z);
    326           glTexCoord2i(0, 0);
    327           glVertex3f(drawPart->position.x + h.x + v.x,
    328                      drawPart->position.y + h.y + v.y,
    329                      drawPart->position.z + h.z + v.z);
    330 
    331           glEnd();
    332  
    333           drawPart = drawPart->next;
    334         }
     297        {
     298          glColor4fv(drawPart->color);
     299          //! \todo implement a faster code for the look-at Camera algorithm.
     300
     301          const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
     302          Vector cameraPos = camera->getAbsCoor();
     303          Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
     304          Vector view = cameraTargetPos - cameraPos;
     305          Vector up = Vector(0, 1, 0);
     306          up = camera->getAbsDir().apply(up);
     307          Vector h = up.cross(view);
     308          Vector v = h.cross(view);
     309          h.normalize();
     310          v.normalize();
     311          v *= .5 * drawPart->radius;
     312          h *= .5 * drawPart->radius;
     313
     314          glBegin(GL_TRIANGLE_STRIP);
     315          glTexCoord2i(1, 1);
     316          glVertex3f(drawPart->position.x - h.x - v.x,
     317                     drawPart->position.y - h.y - v.y,
     318                     drawPart->position.z - h.z - v.z);
     319          glTexCoord2i(0, 1);
     320          glVertex3f(drawPart->position.x - h.x + v.x,
     321                     drawPart->position.y - h.y + v.y,
     322                     drawPart->position.z - h.z + v.z);
     323          glTexCoord2i(1, 0);
     324          glVertex3f(drawPart->position.x + h.x - v.x,
     325                     drawPart->position.y + h.y - v.y,
     326                     drawPart->position.z + h.z - v.z);
     327          glTexCoord2i(0, 0);
     328          glVertex3f(drawPart->position.x + h.x + v.x,
     329                     drawPart->position.y + h.y + v.y,
     330                     drawPart->position.z + h.z + v.z);
     331
     332          glEnd();
     333
     334          drawPart = drawPart->next;
     335        }
    335336      glDepthMask(GL_TRUE);
    336337      break;
     
    340341      glBegin(GL_LINES);
    341342      while (likely(drawPart != NULL))
    342         {
    343           glColor4fv(drawPart->color);
    344           glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    345           glVertex3f(drawPart->position.x - drawPart->velocity.x,
    346                      drawPart->position.y - drawPart->velocity.y,
    347                      drawPart->position.z - drawPart->velocity.z);
    348           drawPart = drawPart->next;
    349         }
     343        {
     344          glColor4fv(drawPart->color);
     345          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     346          glVertex3f(drawPart->position.x - drawPart->velocity.x,
     347                     drawPart->position.y - drawPart->velocity.y,
     348                     drawPart->position.z - drawPart->velocity.z);
     349          drawPart = drawPart->next;
     350        }
    350351      glEnd();
    351352      break;
    352      
     353
    353354    case PARTICLE_DOT:
    354355      glBegin(GL_POINTS);
    355356      while (likely(drawPart != NULL))
    356         {
    357           glColor4fv(drawPart->color);
    358 
    359           glLineWidth(drawPart->radius);
    360 
    361           glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    362           drawPart = drawPart->next;
    363         }
     357        {
     358          glColor4fv(drawPart->color);
     359
     360          glLineWidth(drawPart->radius);
     361
     362          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     363          drawPart = drawPart->next;
     364        }
    364365      glEnd();
    365366      break;
     
    380381      // if it is the first Particle
    381382      if (unlikely(particles == NULL))
    382         {
    383           if (likely(deadList != NULL))
    384             {
    385               this->particles = this->deadList;
    386               deadList = deadList->next;
    387             }
    388           else
    389             {
    390               PRINTF(5)("Generating new Particle\n");
    391               this->particles = new Particle;
    392             }
    393           this->particles->next = NULL;
    394         }
     383        {
     384          if (likely(deadList != NULL))
     385            {
     386              this->particles = this->deadList;
     387              deadList = deadList->next;
     388            }
     389          else
     390            {
     391              PRINTF(5)("Generating new Particle\n");
     392              this->particles = new Particle;
     393            }
     394          this->particles->next = NULL;
     395        }
    395396      // filling the List from the beginning
    396397      else
    397         {
    398           Particle* tmpPart;
    399           if (likely(deadList != NULL))
    400             {
    401               tmpPart = this->deadList;
    402               deadList = deadList->next;
    403             }
    404           else
    405             {
    406               PRINTF(5)("Generating new Particle\n");
    407               tmpPart = new Particle;
    408             }
    409           tmpPart->next = this->particles;
    410           this->particles = tmpPart;
    411         }
    412      
     398        {
     399          Particle* tmpPart;
     400          if (likely(deadList != NULL))
     401            {
     402              tmpPart = this->deadList;
     403              deadList = deadList->next;
     404            }
     405          else
     406            {
     407              PRINTF(5)("Generating new Particle\n");
     408              tmpPart = new Particle;
     409            }
     410          tmpPart->next = this->particles;
     411          this->particles = tmpPart;
     412        }
     413
    413414      particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
    414415      particles->lifeCycle = 0.0;
Note: See TracChangeset for help on using the changeset viewer.