Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3935 in orxonox.OLD for orxonox/branches/particleEngine/src/lib


Ignore:
Timestamp:
Apr 23, 2005, 3:30:45 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/particleEngine: spread works, and many other functions implemented

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

Legend:

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

    r3934 r3935  
    1919
    2020#include "particle_system.h"
     21#include "particle_engine.h"
    2122
    2223using namespace std;
     
    3334   this->setSpread(angle);
    3435   this->setEmissionRate(emissionRate);
    35    this->velocity = velocity;
     36   this->setVelocity(velocity);
    3637
    3738   this->saveTime = 0.0;
     39
     40   ParticleEngine::getInstance()->addEmitter(this);
    3841}
    3942
     
    4548*/
    4649ParticleEmitter::~ParticleEmitter ()
    47 {}
     50{
     51   ParticleEngine::getInstance()->removeEmitter(this);
     52 
     53}
    4854
    4955
     
    8591*/
    8692void ParticleEmitter::setSpread(float angle, float randomAngle)
    87 {}
    88 
    89 
    90 
     93{
     94  this->angle = angle;
     95  this->randomAngle = randomAngle;
     96}
    9197
    9298/**
     
    98104   you may want to use the animation class
    99105*/
    100 void ParticleEmitter::setVelocity(float velocity, float random)
    101 {}
     106void ParticleEmitter::setVelocity(float velocity, float randomVelocity)
     107{
     108  this->velocity = velocity;
     109  this->randomVelocity = randomVelocity;
     110}
    102111
    103112/**
     
    116125  this->saveTime /= this->emissionRate;
    117126
     127
    118128  for (int i = 0; i <= count; i++)
    119129    // emmits from EMITTER_DOT,
    120130    {
    121       Vector randDir = Quaternion(Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2), angle).apply(this->direction);
     131      Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2);
     132      randDir.normalize();
     133      randDir = Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir).apply(this->direction);
    122134      randDir.normalize();
    123135      system->addParticle(this->getAbsCoor(), randDir* velocity);
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.h

    r3932 r3935  
    2222
    2323 public:
    24   ParticleEmitter(const Vector& direction, float angle = 20.0, 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);
     
    3434  void setEmissionRate(float emissionRate);
    3535  void setSpread(float angle, float randomAngle = 0.0);
    36   void setVelocity(float velocity, float random = 0.0);
     36  void setVelocity(float velocity, float randomVelocity = 0.0);
    3737
    3838 private:
    3939  Vector direction;     //!< emition direction
    4040  float angle;          //!< max angle from the direction of the emitter
    41   float angleRandom;    //!< random emission angle (angle +- angleRandom is the emitted angle.
    42   float emissionRate;   //!< amount of particles per seconds emitted by emiter
    43   float velocity;       //!< the contant speed a particle gets if been emitted
     41  float randomAngle;    //!< random emission angle (angle +- angleRandom is the emitted angle.
     42  float emissionRate;   //!< amount of particles per seconds emitted by emitter.
     43  float velocity;       //!< the initial speed of a Particles.
     44  float randomVelocity; //!< the random variation from the initial Speed.
    4445
    4546  float saveTime;       //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big).
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_engine.cc

    r3932 r3935  
    3333
    3434   this->systemList = new tList<ParticleSystem>;
    35 
     35   this->emitterList = new tList<ParticleEmitter>;
    3636   this->connectionList = new tList<ParticleConnection>;
    3737}
     
    7070}
    7171
     72void ParticleEngine::addEmitter(ParticleEmitter* emitter)
     73{
     74  this->emitterList->add(emitter);
     75}
    7276
    7377/**
     
    8387
    8488  this->connectionList->add(tmpCon);
     89}
     90
     91
     92bool ParticleEngine::removeSystem(ParticleSystem* system)
     93{
     94  this->systemList->remove(system);
     95 
     96}
     97
     98bool ParticleEngine::removeEmitter(ParticleEmitter* emitter)
     99{
     100  this->emitterList->remove(emitter);
    85101}
    86102
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.cc

    r3934 r3935  
    4040   this->particleType = type;
    4141   this->particles = NULL;
    42    this->conserve = 1.0;
     42   this->setConserve(.8);
    4343   this->setLifeSpan(.1);
    4444
     
    5454{
    5555  // delete what has to be deleted here
     56   ParticleEngine::getInstance()->removeSystem(this);
    5657}
    5758
     
    5960void ParticleSystem::setMaterial(Material* material)
    6061{
    61  
     62  this->material = material;
    6263}
    6364
     
    7071void ParticleSystem::setRadius(float startRadius, float endRadius, float randomRadius)
    7172{
    72 
     73  this->startRadius = startRadius;
     74  this->endRadius = endRadius;
     75  this->randomRadius = randomRadius;
    7376}
    7477
    7578void ParticleSystem::setConserve(float conserve)
    7679{
    77   this->conserve = conserve;
     80  if (conserve > 1.0)
     81    this->conserve = 1.0;
     82  else if (conserve < 0.0)
     83    this->conserve = 0.0;
     84  else
     85    this->conserve = conserve;
    7886}
    7987
     
    8694  while (likely(tickPart != NULL))
    8795    {
    88          
     96     
    8997      tickPart->position = tickPart->position + tickPart->velocity;
    9098      // many more to come
     
    94102
    95103
    96 
     104      if (this->conserve < 1.0)
     105        tickPart->velocity = tickPart->velocity * this->conserve;
    97106      // find out if we have to delete tickPart
    98107      if ((tickPart->timeToLive -= dt) <= 0)
     
    113122            }
    114123          --this->count;
    115           printf("deleted particle: count %d\n", count);
    116124        }
    117125      else
     
    128136  if (likely(drawPart != NULL))
    129137    {
    130       glBegin(GL_TRIANGLES);
     138      glBegin(GL_POINTS);
    131139      while (likely(drawPart != NULL))
    132140        {
Note: See TracChangeset for help on using the changeset viewer.