Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 24, 2005, 3:35:03 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: more momentum implementation in particles

File:
1 edited

Legend:

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

    r4639 r4690  
    113113
    114114
    115 /* these are Animation interfaces: so you can change spec values as you want */
    116115
    117116/**
     
    212211
    213212/**
    214    \brief sets the velocity of all particles emitted
     213   \brief sets the initial velocity of all particles emitted
    215214   \param velocity The starting velocity of the emitted particles
    216215   \param randomVelocity A random starting velocity, the +- randomness of this option
     
    223222  this->velocity = velocity;
    224223  this->randomVelocity = randomVelocity;
     224}
     225
     226/**
     227   \brief sets the initial Momentum of all particles emitted
     228   \param momentum the new Momentum (just a float for being not too complicated).
     229   \param randomMomentum variation from the given value.
     230 */
     231void ParticleEmitter::setEmissionMomentum(float momentum, float randomMomentum)
     232{
     233  this->momentum = momentum;
     234  this->momentumRandom = randomMomentum;
    225235}
    226236
     
    233243   you may want to use the animation class
    234244*/
    235 
    236245void ParticleEmitter::tick(float dt, ParticleSystem* system)
    237246{
     
    244253
    245254    if (likely(count > 0))
     255    {
     256      Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
     257      for (int i = 0; i < count; i++)
     258          // emmits from EMITTER_DOT,
    246259      {
    247         Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
    248         for (int i = 0; i < count; i++)
    249           // emmits from EMITTER_DOT,
    250           {
    251             Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
    252             randDir.normalize();
    253             randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);
    254             Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
     260        Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
     261        randDir.normalize();
     262        randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);
     263        Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
    255264
    256265            // this should spread the Particles evenly. if the Emitter is moved around quickly
    257             Vector equalSpread = this->getVelocity() * rand()/RAND_MAX * dt;
    258             Vector extension; // the Vector for different fields.
    259 
    260             if (this->type & 2)
    261               {
    262                 extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5));
    263                 extension = this->getAbsDir().apply(extension);
    264               }
    265             else if (this->type & 8)
    266               {
    267                 extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize;
    268               }
    269 
    270             system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV);
    271 
    272           }
     266        Vector equalSpread = this->getVelocity() * rand()/RAND_MAX * dt;
     267        Vector extension; // the Vector for different fields.
     268
     269        if (this->type & 2)
     270        {
     271          extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5));
     272          extension = this->getAbsDir().apply(extension);
     273        }
     274        else if (this->type & 8)
     275        {
     276          extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize;
     277        }
     278
     279
     280        // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
     281        randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
     282        randDir.normalize();
     283        Quaternion orient = Quaternion(M_PI, randDir);
     284        Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
     285
     286        system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV, orient, moment);
     287
    273288      }
     289    }
    274290  }
    275291}
Note: See TracChangeset for help on using the changeset viewer.