Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4690 in orxonox.OLD for orxonox/trunk/src/lib


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

orxonox/trunk: more momentum implementation in particles

Location:
orxonox/trunk/src/lib/particles
Files:
4 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}
  • orxonox/trunk/src/lib/particles/particle_emitter.h

    r4639 r4690  
    4646  void setSpread(float angle, float randomAngle = 0.0);
    4747  void setEmissionVelocity(float velocity, float randomVelocity = 0.0);
     48  void setEmissionMomentum(float momentum, float randomMomentum = 0.0);
    4849
    4950  /** \returns the type of the emitter */
     
    6162  /** \returns the EmissionVelocity of the emitter */
    6263  inline float getEmissionVelocity(void) const { return this->velocity; };
     64  /** \returns the EmissionMomentum of this emitter */
     65  inline float getEmissionMomentum(void) const { return this->momentum; };
    6366
    6467  void debug(void) const;
    6568
    66 
    6769 private:
    68   EMITTER_TYPE    type;              //!< The type of emitter this is
    69   float           emitterSize;       //!< The size of the emitter (not for EMITTER_DOT)
    70   float           inheritSpeed;      //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter
    71   Vector          direction;         //!< emition direction
     70  EMITTER_TYPE    type;              //!< The type of emitter this is.
     71  float           emitterSize;       //!< The size of the emitter (not for EMITTER_DOT).
     72  float           inheritSpeed;      //!< How much speed the particle inherits from the Emitters speed.
     73  Vector          direction;         //!< emition direction.
    7274  float           angle;             //!< max angle from the direction of the emitter
    7375  float           randomAngle;       //!< random emission angle (angle +- angleRandom is the emitted angle.
     
    7577  float           velocity;          //!< the initial speed of a Particles.
    7678  float           randomVelocity;    //!< the random variation from the initial Speed.
     79  float           momentum;          //!< The Initial spped of the Rotation.
     80  float           momentumRandom;    //!< The random variation of the Momentum.
    7781
    7882  float           saveTime;          //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big).
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4687 r4690  
    485485/**
    486486   \brief adds a new Particle to the System
    487    \param position the position where the particle gets emitted.
    488    \param velocity the Starting velocity of the particle.
     487   \param position the initial position, where the particle gets emitted.
     488   \param velocity the initial velocity of the particle.
     489   \param orientation the initial orientation of the Paritcle.
     490   \param momentum the initial momentum of the Particle (the speed of its rotation).
    489491   \param data some more data given by the emitter
    490492*/
    491 void ParticleSystem::addParticle(const Vector& position, const Vector& velocity, unsigned int data)
     493void ParticleSystem::addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data)
    492494{
    493495  if (this->count <= this->maxCount)
     
    530532      particles->velocity = velocity;
    531533
    532       particles->orientation = Quaternion(.4, velocity.getNormalized());
    533       particles->momentum = Quaternion(.4, velocity.getNormalized());
     534      particles->orientation = orientation;
     535      particles->momentum = momentum;
    534536
    535537      //  particle->rotation = ; //! \todo rotation is once again something to be done.
  • orxonox/trunk/src/lib/particles/particle_system.h

    r4687 r4690  
    109109  virtual void tickPhys(float dt) {};
    110110
    111   void addParticle(const Vector& position, const Vector& velocity, unsigned int data = 0);
     111  void addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data = 0);
    112112
    113113  virtual void tick(float dt);
Note: See TracChangeset for help on using the changeset viewer.