Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 24, 2005, 11:32:48 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/particleEngine: timing is ok now when emitting small numbers/sec

Location:
orxonox/branches/particleEngine/src/lib/graphics/particles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.cc

    r3944 r3950  
    120120void ParticleEmitter::tick(float dt, ParticleSystem* system)
    121121{
    122   // saving the time
    123   float count = (dt+this->saveTime) * this->emissionRate;
    124   this->saveTime = modff(count, &count);
    125   this->saveTime /= this->emissionRate;
    126 
    127 
    128   for (int i = 0; i <= count; i++)
    129     // emmits from EMITTER_DOT,
    130     {
    131       Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2);
    132       randDir.normalize();
    133       randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir)).apply(this->direction);
    134       randDir = *randDir.getNormalized() + (this->getVelocity() * system->inheritSpeed);
    135 
    136       system->addParticle(this->getAbsCoor(), randDir* velocity);
    137     }
     122  if (likely(dt > 0.0 && this->emissionRate > 0.0))
     123  {
     124    // saving the time
     125    float count = (dt+this->saveTime) * this->emissionRate;
     126    this->saveTime = modff(count, &count);
     127    this->saveTime /= this->emissionRate;
     128    PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime);
     129   
     130    for (int i = 0; i < count; i++)
     131      // emmits from EMITTER_DOT,
     132      {
     133        Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2);
     134        randDir.normalize();
     135        randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir)).apply(this->direction);
     136        randDir = *randDir.getNormalized() + (this->getVelocity() * system->inheritSpeed);
     137       
     138        system->addParticle(this->getAbsCoor(), randDir* velocity);
     139      }
     140  }
    138141}
    139142
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.h

    r3944 r3950  
    2222
    2323 public:
    24   ParticleEmitter(const Vector& direction, float angle = .5, float emissionRate = 1.0, 
     24  ParticleEmitter(const Vector& direction, float angle = .5, float emissionRate = 1.0,
    2525                  float velocity = 1.0);
    2626  virtual ~ParticleEmitter(void);
Note: See TracChangeset for help on using the changeset viewer.