Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2005, 11:27:40 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

Location:
orxonox/branches/movie_player/src/lib/graphics/particles
Files:
6 edited

Legend:

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

    r3966 r4217  
    124124    // saving the time
    125125    float count = (dt+this->saveTime) * this->emissionRate;
    126     this->saveTime = modff(count, &count);
    127     this->saveTime /= this->emissionRate;
     126    this->saveTime = modff(count, &count) / this->emissionRate;
    128127    PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime);
    129128   
    130     for (int i = 0; i < count; i++)
    131       // emmits from EMITTER_DOT,
     129    if (likely(count > 0))
    132130      {
    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()*velocity + (this->getVelocity() * system->inheritSpeed);
     131        Vector inheritVelocity = this->getVelocity() * system->inheritSpeed;
     132        for (int i = 0; i < count; i++)
     133          // emmits from EMITTER_DOT,
     134          {
     135            Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
     136            randDir.normalize();
     137            randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);
     138            Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
    137139
    138         system->addParticle(this->getAbsCoor(), randDir);
     140            // this should spread the Particles evenly. if the Emitter is moved around quickly
     141            Vector equalSpread = this->getVelocity() * random()/RAND_MAX * dt;
     142
     143            system->addParticle(this->getAbsCoor() - equalSpread, velocityV);
     144          }
    139145      }
    140146  }
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_emitter.h

    r3966 r4217  
    2222
    2323 public:
    24   ParticleEmitter(const Vector& direction, float angle = .5, float emissionRate = 1.0,
    25                   float velocity = 1.0);
     24  ParticleEmitter(const Vector& direction, float angle = .5,
     25                  float emissionRate = 1.0, float velocity = 1.0);
    2626  virtual ~ParticleEmitter(void);
    2727
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_engine.cc

    r3966 r4217  
    228228void ParticleEngine::tick(float dt)
    229229{
    230   // add new Particles to each System connected to an Emitter.
    231   tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
    232   ParticleConnection* tmpConnection = tmpConIt->nextElement();
    233   while(tmpConnection)
    234     {
    235       tmpConnection->emitter->tick(dt, tmpConnection->system);
    236       tmpConnection = tmpConIt->nextElement();
    237     }
    238   delete tmpConIt;
    239  
    240 
    241230  // ticks all the ParticleSystems
    242231  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
     
    248237    }
    249238  delete tmpIt;
     239
     240  // add new Particles to each System connected to an Emitter.
     241  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
     242  ParticleConnection* tmpConnection = tmpConIt->nextElement();
     243  while(tmpConnection)
     244    {
     245      tmpConnection->emitter->tick(dt, tmpConnection->system);
     246      tmpConnection = tmpConIt->nextElement();
     247    }
     248  delete tmpConIt;
    250249}
    251250
    252251/**
    253252   \brief draws all the systems and their Particles.
    254 */
    255 void ParticleEngine::draw(void)
     253   \param dt the time passed in seconds (since the last Frame)
     254*/
     255void ParticleEngine::draw(float dt)
    256256{
    257257  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
     
    259259  while(tmpSys)
    260260    {
    261       tmpSys->draw();
     261      tmpSys->draw(dt);
    262262      tmpSys = tmpIt->nextElement();
    263263    }
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_engine.h

    r3966 r4217  
    88
    99#include "base_object.h"
     10#include "particle_system.h"
     11#include "particle_emitter.h"
    1012
    1113// FORWARD DEFINITION
     
    2830
    2931  void tick(float dt);
    30   void draw(void);
     32  void draw(float dt);
    3133
    3234  void addSystem(ParticleSystem* system);
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.cc

    r3966 r4217  
    3535{
    3636   this->setClassName ("ParticleSystem");
     37   this->material = NULL;
    3738   this->name = NULL;
    3839   this->maxCount = maxCount;
    3940   this->count = 0;
    40    this->particleType = type;
    4141   this->particles = NULL;
    42    this->setConserve(.8);
    43    this->setLifeSpan(.1);
     42   this->deadList = NULL;
     43   this->setConserve(1);
     44   this->setLifeSpan(1);
    4445   this->setInheritSpeed(0);
    4546   this->glID = NULL;
    4647   this->setRadius(1.0, 1.0, 0.0);
    47    this->setType(PARTICLE_SPRITE, 1);
     48   this->setType(type, 1);
    4849   ParticleEngine::getInstance()->addSystem(this);
    4950}
     
    5354   \brief standard deconstructor
    5455*/
    55 ParticleSystem::~ParticleSystem() 
     56ParticleSystem::~ParticleSystem()
    5657{
    5758  // delete what has to be deleted here
    5859   ParticleEngine::getInstance()->removeSystem(this);
     60
     61   // deleting all the living Particles
     62   while (this->particles)
     63     {
     64       Particle* tmpDelPart = this->particles;
     65       this->particles = this->particles->next;
     66       delete tmpDelPart;
     67     }
     68
     69   // deleting all the dead particles
     70   while (this->deadList)
     71     {
     72       Particle* tmpDelPart = this->deadList;
     73       this->deadList = this->deadList->next;
     74       delete tmpDelPart;
     75     }
     76
     77   if (this->material)
     78     delete this->material;
    5979}
    6080
     
    199219            {
    200220              prevPart->next = tickPart->next;
    201               delete tickPart;
     221              tickPart->next = this->deadList;
     222              this->deadList = tickPart;
    202223              tickPart = prevPart->next;
    203224            }
     
    206227              prevPart = NULL;
    207228              this->particles = tickPart->next;
    208               delete tickPart;
     229              tickPart->next = this->deadList;
     230              this->deadList = tickPart;
    209231              tickPart = this->particles;
    210232            }
     
    221243/**
    222244   \brief draws all the Particles of this System
    223 */
    224 void ParticleSystem::draw(void)
    225 {
     245   \param the time passed in seconds (since the last draw)
     246*/
     247void ParticleSystem::draw(float dt)
     248{
     249  glPushAttrib(GL_ENABLE_BIT);
    226250  //  material->select();
    227 
    228 
    229   glMatrixMode(GL_MODELVIEW);
    230   //  glDisable(GL_LIGHTING);
    231   material->select();
    232 
    233251  Particle* drawPart = particles;
    234   if (likely(drawPart != NULL))
     252
     253  switch (this->particleType)
    235254    {
    236       glBegin(GL_POINTS);
     255    case PARTICLE_SPRITE:
     256      glMatrixMode(GL_MODELVIEW);
     257      //  glDisable(GL_LIGHTING);
     258      material->select();
     259      glDisable(GL_DEPTH_TEST);
    237260      while (likely(drawPart != NULL))
    238261        {
    239           // draw in DOT mode
    240262          glPushMatrix();
    241263          glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     
    243265          glCallList(*this->glID);
    244266         
    245           //              glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     267          //glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    246268          drawPart = drawPart->next;
    247269          glPopMatrix();
    248270        }
     271      //      glEnd();
     272     
     273      //  glEnable(GL_LIGHTING);
     274     
     275      glEnable(GL_DEPTH_TEST);
     276      break;
     277    default:
     278
     279    case PARTICLE_SPARK:
     280      glEnable(GL_LINE_SMOOTH);
     281      glBegin(GL_LINES);
     282      while (likely(drawPart != NULL))
     283        {
     284          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     285          glVertex3f(drawPart->position.x - drawPart->velocity.x,
     286                     drawPart->position.y - drawPart->velocity.y,
     287                     drawPart->position.z - drawPart->velocity.z);
     288          drawPart = drawPart->next;
     289        }
    249290      glEnd();
     291      break;
     292     
     293    case PARTICLE_DOT:
     294      glBegin(GL_POINTS);
     295      while (likely(drawPart != NULL))
     296        {
     297          glLineWidth(drawPart->radius);
     298
     299          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     300          drawPart = drawPart->next;
     301        }
     302      glEnd();
     303      break;
    250304    }
     305  glPopAttrib();
    251306}
    252307
     
    264319      if (unlikely(particles == NULL))
    265320        {
    266           this->particles = new Particle;
     321          if (likely(deadList != NULL))
     322            {
     323              this->particles = this->deadList;
     324              deadList = deadList->next;
     325            }
     326          else
     327            {
     328              PRINTF(5)("Generating new Particle\n");
     329              this->particles = new Particle;
     330            }
    267331          this->particles->next = NULL;
    268332        }
     
    270334      else
    271335        {
    272           Particle* tmpPart = new Particle;
     336          Particle* tmpPart;
     337          if (likely(deadList != NULL))
     338            {
     339              tmpPart = this->deadList;
     340              deadList = deadList->next;
     341            }
     342          else
     343            {
     344              PRINTF(5)("Generating new Particle\n");
     345              tmpPart = new Particle;
     346            }
    273347          tmpPart->next = this->particles;
    274348          this->particles = tmpPart;
    275349        }
    276350     
    277       particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan;
     351      particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
    278352      particles->position = position;
    279353      particles->velocity = velocity;
    280354
    281355      //  particle->rotation = ; //! \todo rotation is once again something to be done.
    282       particles->mass = this->initialMass + (random()/RAND_MAX -.5)* this->randomInitialMass;
    283       particles->radius = this->startRadius + (random()/RAND_MAX-.5)*this->randomStartRadius;
    284      
    285       particles->radiusIt = (this->endRadius + (random()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
     356      particles->mass = this->initialMass + (rand()/RAND_MAX -.5)* this->randomInitialMass;
     357      particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius;
     358     
     359      particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
    286360
    287361      ++this->count;
    288362    }
    289363  else
    290     PRINTF(4)("maximum count of particles reached not adding any more\n");
     364    PRINTF(5)("maximum count of particles reached not adding any more\n");
    291365}
    292366
     
    298372  PRINT(0)("  ParticleSystem %s\n", this->name);
    299373  PRINT(0)("  ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);
    300 }
     374  if (deadList)
     375    {
     376      PRINT(0)("  - ParticleDeadList is used: ");
     377      int i = 1;
     378      Particle* tmpPart = this->deadList;
     379      while (tmpPart = tmpPart->next) ++i;
     380      PRINT(0)("count: %d\n", i);
     381    }
     382}
  • orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.h

    r3966 r4217  
    1010#include "vector.h"
    1111
    12 #define PARTICLE_DOT_MASK           0x00001
    13 #define PARTICLE_SPRITE_MASK        0x00010
    14 #define PARTICLE_MODEL_MASK         0x00100
    15 #define PARTICLE_WORDL_ENTITY_MASK  0x01000
    16 #define PARTICLE_MULTI_MASK         0x10000
     12#define PARTICLE_DOT_MASK           0x000001
     13#define PARTICLE_SPARK_MASK         0x000010
     14#define PARTICLE_SPRITE_MASK        0x000100
     15#define PARTICLE_MODEL_MASK         0x001000
     16#define PARTICLE_WORDL_ENTITY_MASK  0x010000
     17#define PARTICLE_MULTI_MASK         0x100000
    1718
    1819//! An enumerator for the different types of particles.
    1920typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK,
     21                            PARTICLE_SPARK = PARTICLE_SPARK_MASK,
    2022                            PARTICLE_SPRITE = PARTICLE_SPRITE_MASK,
    2123                            PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK,
     
    4244  float radiusIt;             //!< The difference of the Size per second.
    4345
     46  PARTICLE_TYPE type;
     47
    4448  Particle* next;             //!< pointer to the next particle in the List. (NULL if no preceding one)
    4549};
     
    5054
    5155 public:
    52   ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
     56  ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT,
     57                 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);
    5358  virtual ~ParticleSystem();
    5459  void setName(const char* name);
     
    5964  void setInheritSpeed(float value);
    6065  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
    61   void setRadius(float startRadius, float endRadius, float randomStartRadius = 0.0, float randomEndRadius = 0.0);
     66  void setRadius(float startRadius, float endRadius,
     67                 float randomStartRadius = 0.0, float randomEndRadius = 0.0);
    6268  void setConserve(float conserve);
    6369  void setMass(float mass, float randomMass);
    6470
    6571  void tick(float dt);
    66   void draw(void);
     72  void draw(float dt);
    6773
    6874  void debug(void);
     
    8894  Material* material;        //!< A Material for all the Particles.
    8995  Particle* particles;       //!< A list of particles of this System.
     96  Particle* deadList;        //!< A list of dead Particles in the System.
    9097
    9198  GLuint* glID;              //!< A List of different gl-List-ID's
Note: See TracChangeset for help on using the changeset viewer.