Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4192 in orxonox.OLD for orxonox/branches/physics


Ignore:
Timestamp:
May 16, 2005, 12:55:19 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/physics: reimplemented the lifeTime function of particles (a little bit slower, but much more efficient)
Color also implemented with the new TimeCode

Location:
orxonox/branches/physics/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/lib/graphics/particles/particle_system.cc

    r4190 r4192  
    5353  this->setRadius(1.0, 1.0, 0.0);
    5454  this->setType(type, 1);
     55  this->setColor(1.0,1.0,1.0,1.0, .5,.5,.5,.5, .0,.0,.0,.0);
    5556  ParticleEngine::getInstance()->addSystem(this);
    5657}
     
    198199}
    199200
     201
     202/**
     203   \brief Tells the ParticleSystem how it should iterate the color over time
     204   \param ....
     205*/
     206void ParticleSystem::setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba,
     207                              GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma,
     208                              GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea)
     209{
     210  this->startColor[0] = br;
     211  this->startColor[1] = bg;
     212  this->startColor[2] = bb;
     213  this->startColor[3] = ba;
     214
     215  this->midColor[0] = mr;
     216  this->midColor[1] = mg;
     217  this->midColor[2] = mb;
     218  this->midColor[3] = ma;
     219
     220  this->endColor[0] = er;
     221  this->endColor[1] = eg;
     222  this->endColor[2] = eb;
     223  this->endColor[3] = ea;
     224}
     225
    200226/**
    201227   \brief ticks the system.
     
    217243      tickPart->extForce = Vector(0,0,0);
    218244
     245      // applying Color
     246      //! \todo better algorithm to do this \todo also implement the midColor
     247      tickPart->color[0] = this->startColor[0] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[0];
     248      tickPart->color[1] = this->startColor[1] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[1];
     249      tickPart->color[2] = this->startColor[2] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[2];
     250      tickPart->color[3] = this->startColor[3] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[3];
     251
    219252      // many more to come
    220253
     
    222255        tickPart->velocity = tickPart->velocity * this->conserve;
    223256      // find out if we have to delete tickPart
    224       if ((tickPart->timeToLive -= dt) <= 0)
     257      if ((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0)
    225258        {
    226259          // remove the particle from the list
     
    267300   \brief draws all the Particles of this System
    268301   \param the time passed in seconds (since the last draw)
     302
     303   The Cases in this Function all do the same:
     304   Drawing all the particles with the appropriate Type.
     305   This is just the fastest Way to do this, but will most likely be changed in the future.
    269306*/
    270307void ParticleSystem::draw(float dt)
    271308{
    272309  glPushAttrib(GL_ENABLE_BIT);
    273   //  material->select();
     310  glDisable(GL_LIGHTING);
     311
    274312  Particle* drawPart = particles;
    275 
     313     
    276314  switch (this->particleType)
    277315    {
     316    default:
    278317    case PARTICLE_SPRITE:
    279       GLdouble projMat[16];
    280       GLfloat drawPartPos[4];
    281       glGetDoublev(GL_PROJECTION_MATRIX, projMat);
    282      
    283318      glMatrixMode(GL_MODELVIEW);
    284319      glDisable(GL_DEPTH_TEST);
    285       glDisable(GL_LIGHTING);
    286            material->select();
     320
     321      material->select();
     322      //      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    287323     
    288324
    289325      while (likely(drawPart != NULL))
    290326        {
     327          glColor4fv(drawPart->color);
    291328          //! \todo implement a faster code for the look-at Camera algorithm.
    292329
    293           Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera();
     330          Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera();  //!< \todo MUST be different
    294331          Vector cameraPos = camera->getAbsCoor();
    295332          Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
     
    326363          drawPart = drawPart->next;
    327364        }
    328       glEnable(GL_LIGHTING);
    329       glEnable(GL_DEPTH_TEST);
    330365
    331366     
    332367      break;
    333     default:
    334368
    335369    case PARTICLE_SPARK:
     
    338372      while (likely(drawPart != NULL))
    339373        {
     374          glColor4fv(drawPart->color);
    340375          glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    341376          glVertex3f(drawPart->position.x - drawPart->velocity.x,
     
    351386      while (likely(drawPart != NULL))
    352387        {
     388          glColor4fv(drawPart->color);
     389
    353390          glLineWidth(drawPart->radius);
    354391
     
    405442        }
    406443     
    407       particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
     444      particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan;
     445      particles->lifeCycle = 0.0;
    408446      particles->position = position;
    409447      particles->velocity = velocity;
     
    413451      particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius;
    414452     
    415       particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;
     453      particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->lifeTime;
    416454
    417455      ++this->count;
  • orxonox/branches/physics/src/lib/graphics/particles/particle_system.h

    r4186 r4192  
    3636typedef struct Particle
    3737{
    38   float timeToLive;           //!< The time this particle lives from NOW on.
     38  float lifeTime;             //!< The time this particle has to live.
     39  float lifeCycle;            //!< The fraction of time passed. (in percentage of its lifeTime)
     40
    3941  Vector position;            //!< The current position of this particle.
    4042  Vector velocity;            //!< The current velocity of this particle.
     
    4446  float radius;               //!< The current size of this particle.
    4547  float radiusIt;             //!< The difference of the Size per second.
     48
     49  GLfloat color [4];          //!< A Color for the particles.
    4650
    4751  PARTICLE_TYPE type;
     
    7074  void setMass(float mass, float randomMass);
    7175
     76  void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba,
     77                GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma,
     78                GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea);
     79
    7280  void applyField(float dt, Field* field);
    7381
     
    8290  float conserve;            //!< How much energy gets conserved to the next Tick.
    8391  float lifeSpan;            //!< Initial lifetime of a Particle.
    84   float randomLifeSpan;
    85   float startRadius;
    86   float endRadius;
    87   float randomStartRadius;
    88   float randomEndRadius;
    89   float initialMass;
    90   float randomInitialMass;
    91   float inheritSpeed;
     92  float randomLifeSpan;      //!< A random value for the Lifespan (around the initial lifetime)
     93  float startRadius;         //!< The beginning Radius of the Particle
     94  float endRadius;           //!< The end Radius of the Particle
     95  float randomStartRadius;   //!< The Random start Radius (begin + rand*randomValue)
     96  float randomEndRadius;     //!< Random end value
     97  float initialMass;         //!< The initial Mass of the Particle
     98  float randomInitialMass;   //!< The random initial Mass of the Particle
     99  float inheritSpeed;        //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter
     100
     101  GLfloat startColor[4];     //!< Color of the Particle at the beginning
     102  GLfloat midColor[4];       //!< Color of the Particle at the middle of its lifeSpan
     103  GLfloat endColor[4];       //!< Color of the Particle at the end of its lifeSpan
    92104
    93105  // particles
  • orxonox/branches/physics/src/story_entities/world.cc

    r4190 r4192  
    492492
    493493
     494  // Creating a Test Particle System
    494495  ParticleSystem* system = new ParticleSystem(100000, PARTICLE_SPRITE);
    495   system->setLifeSpan(3);
    496   system->setConserve(.9);
    497   system->setRadius(2, 0, 2, 0);
    498 
     496  system->setLifeSpan(1);
     497  system->setConserve(.8);
     498  system->setRadius(4, 0, 1, 0);
     499  system->setColor(1,0,0,1, 1,1,0,1, 0,0,0,0);
     500
     501  // Creating a Test Particle Emitter
    499502  ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 400, .5);
    500503  emitter->setParent(this->localPlayer);
    501  
     504  emitter->setRelCoor(Vector(0,-3,0));
     505 
     506  // Add the Flow from the Emitter into the System
     507  particleEngine->addConnection(emitter, system);
     508
     509
     510  // Creating Some Fields
    502511  Field* twirl = new Twirl();
    503512  twirl->setMagnitude(.1);
    504513  Field* gravity = new PointGravity();
    505514  gravity->setMagnitude(.5);
    506     new PhysicsConnection(system, twirl);
    507     //    new PhysicsConnection(system, gravity);
    508     twirl->setParent(this->localCamera->getTarget());
    509     gravity->setParent(this->localCamera->getTarget());
    510     particleEngine->addConnection(emitter, system);
     515  twirl->setParent(this->localCamera->getTarget());
     516  gravity->setParent(this->localCamera->getTarget());
     517
     518  //  new PhysicsConnection(system, twirl);
     519  //    new PhysicsConnection(system, gravity);
     520
    511521}
    512522
Note: See TracChangeset for help on using the changeset viewer.