Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3932 in orxonox.OLD for orxonox/branches/particleEngine


Ignore:
Timestamp:
Apr 23, 2005, 12:42:09 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/particleEngine: the first particles are being drawn :)

Location:
orxonox/branches/particleEngine/src
Files:
8 edited

Legend:

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

    r3931 r3932  
    1818#include "particle_emitter.h"
    1919
     20#include "particle_system.h"
     21
    2022using namespace std;
    2123
     
    3234   this->emissionRate = emissionRate;
    3335   this->velocity = velocity;
     36
     37   this->saveTime = 0.0;
    3438}
    3539
     
    104108*/
    105109
     110void ParticleEmitter::tick(float dt, ParticleSystem* system)
     111{
     112  // saving the time
     113  float countF = (dt+this->saveTime) / emissionRate;
     114  int count = (int)round(countF);
     115  this->saveTime = countF - (float)count;
     116
     117  for (int i = 0; i <= count; i++)
     118    // emmits from EMITTER_DOT,
     119    system->addParticle(this->getAbsCoor(), direction * velocity );
     120}
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.h

    r3931 r3932  
    2929  void start();
    3030  void stop();
     31  void tick(float dt, ParticleSystem* system);
    3132
    3233  /* controlling the behavour: these can be used as Animation interfaces */
     
    4142  float emissionRate;   //!< amount of particles per seconds emitted by emiter
    4243  float velocity;       //!< the contant speed a particle gets if been emitted
     44
     45  float saveTime;       //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big).
    4346};
    4447
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_engine.cc

    r3931 r3932  
    3333
    3434   this->systemList = new tList<ParticleSystem>;
     35
     36   this->connectionList = new tList<ParticleConnection>;
    3537}
    3638
     
    5860  delete this->systemList;
    5961
     62  delete this->connectionList;
    6063
    6164  ParticleEngine::singletonRef = NULL;
    6265}
     66
     67void ParticleEngine::addSystem(ParticleSystem* system)
     68{
     69  this->systemList->add(system);
     70}
     71
     72
     73/**
     74   \brief
     75
     76   \todo header, check for double connections
     77*/
     78void ParticleEngine::addConnection(ParticleEmitter* emitter, ParticleSystem* system)
     79{
     80  ParticleConnection* tmpCon = new ParticleConnection;
     81  tmpCon->emitter = emitter;
     82  tmpCon->system = system;
     83
     84  this->connectionList->add(tmpCon);
     85}
     86
    6387
    6488/**
     
    6892void ParticleEngine::tick(float dt)
    6993{
     94  // add new Particles to each System they are connected to.
     95  tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();
     96  ParticleConnection* tmpConnection = tmpConIt->nextElement();
     97  while(tmpConnection)
     98    {
     99      tmpConnection->emitter->tick(dt, tmpConnection->system);
     100      tmpConnection = tmpConIt->nextElement();
     101    }
     102  delete tmpConIt;
     103 
     104
     105  // ticks all the ParticleSystems
    70106  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
    71107  ParticleSystem* tmpSys = tmpIt->nextElement();
     
    78114
    79115}
     116
     117
     118void ParticleEngine::draw(void)
     119{
     120  tIterator<ParticleSystem>* tmpIt = systemList->getIterator();
     121  ParticleSystem* tmpSys = tmpIt->nextElement();
     122  while(tmpSys)
     123    {
     124      tmpSys->draw();
     125      tmpSys = tmpIt->nextElement();
     126    }
     127  delete tmpIt;
     128
     129}
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_engine.h

    r3931 r3932  
    2828
    2929  void tick(float dt);
     30  void draw(void);
    3031
    3132  void addSystem(ParticleSystem* system);
    3233  void addEmitter(ParticleEmitter* emitter);
    33   void addConection(ParticleEmitter* emitter, ParticleSystem* system);
     34  void addConnection(ParticleEmitter* emitter, ParticleSystem* system);
    3435
    3536  bool removeSystem(ParticleSystem* system);
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.cc

    r3931 r3932  
    2020#include "particle_emitter.h"
    2121#include "particle_engine.h"
     22#include "compiler.h"
    2223
    2324using namespace std;
     
    3637
    3738   this->particleType = type;
     39   this->particles = NULL;
     40   this->conserve = 1.0;
     41   this->setLifeSpan(5.0);
     42
     43   ParticleEngine::getInstance()->addSystem(this);
    3844}
    3945
     
    4349
    4450*/
    45 ParticleSystem::~ParticleSystem ()
     51ParticleSystem::~ParticleSystem()
    4652{
    4753  // delete what has to be deleted here
    4854}
    4955
     56// setting properties
     57void ParticleSystem::setMaterial(Material* material)
     58{
     59 
     60}
     61
     62void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan)
     63{
     64
     65}
     66
     67void ParticleSystem::setRadius(float startRadius, float endRadius, float randomRadius)
     68{
     69
     70}
     71
     72void ParticleSystem::setConserve(float conserve)
     73{
     74  this->conserve = conserve;
     75}
     76
     77
    5078
    5179void ParticleSystem::tick(float dt)
    5280{
     81  Particle* tmpPart = particles;
     82  while (likely(tmpPart != NULL))
     83    {
     84      tmpPart->position = tmpPart->position + tmpPart->velocity;
     85
     86      // many more to come
     87
     88      tmpPart = tmpPart->next;
     89    }
     90}
     91
     92void ParticleSystem::draw(void)
     93{
     94  Particle* tmpPart = particles;
     95  if (likely(tmpPart != NULL))
     96    {
     97      glBegin(GL_POINTS);
     98      while (likely(tmpPart != NULL))
     99        {
     100          // draw in DOT mode
     101          glVertex3f(tmpPart->position.x, tmpPart->position.y, tmpPart->position.z);
     102         
     103         
     104          tmpPart = tmpPart->next;
     105        }
     106      glEnd();
     107    }
     108}
     109
     110
     111void ParticleSystem::addParticle(Vector position, Vector velocity, unsigned int data)
     112{
     113  // if it is the first Particle
     114  if (unlikely(particles == NULL))
     115    {
     116      this->particles = new Particle;
     117      this->particles->next = NULL;
     118    }
     119  // filling the List from the beginning
     120  else
     121    {
     122      Particle* tmpPart = new Particle;
     123      tmpPart->next = this->particles;
     124      this->particles = tmpPart;
     125    }
    53126 
     127  particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan;
     128  particles->position = position;
     129  particles->velocity = velocity;
     130  //  particle->rotation = ; //! \todo rotation is once again something to be done.
     131  particles->mass = this->initialMass + (random()/RAND_MAX)* this->randomInitialMass;
     132  particles->radius = this->startRadius + (random()/RAND_MAX)*this->randomRadius;
     133}
    54134
    55 }
  • orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.h

    r3931 r3932  
    3434  Quaternion rotation;        //!< The current rotation of this particle.
    3535  float mass;                 //!< The mass of this particle.
    36   float radius;               //!< The size of this particle.
    37 
     36  float radius;               //!< The current size of this particle.
    3837
    3938  Particle* next;             //!< pointer to the next particle in the List. (NULL if no preceding one)
     
    4241//! A class to handle particle Systems
    4342class ParticleSystem : public BaseObject {
     43  friend class ParticleEmitter;
    4444
    4545 public:
     
    5050  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
    5151  void setRadius(float startRadius, float endRadius, float randomRadius = 0.0);
     52  void setConserve(float conserve);
     53  void setMass(float mass, float randomMass);
    5254
    5355  void tick(float dt);
     56  void draw(void);
    5457
    5558 private:
     
    6063  float endRadius;
    6164  float randomRadius;
     65  float initialMass;
     66  float randomInitialMass;
    6267 
    6368  // particles
     
    6671  Material* material;        //!< A Material for all the Particles.
    6772  Particle* particles;       //!< A list of particles of this System.
     73
     74
     75  void addParticle(Vector position, Vector velocity, unsigned int data = 0);
     76 
    6877};
    6978
  • orxonox/branches/particleEngine/src/story_entities/world.cc

    r3870 r3932  
    4040#include "animation_player.h"
    4141
     42#include "particle_engine.h"
     43#include "particle_system.h"
     44#include "particle_emitter.h"
     45
    4246#include "command_node.h"
    4347#include "glmenu_imagescreen.h"
     
    162166  AnimationPlayer::getInstance()->debug();
    163167  delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence.
     168
     169  delete ParticleEngine::getInstance();
     170
    164171  //delete garbagecollecor
    165172  //delete animator
     
    185192  this->entities = new tList<WorldEntity>();
    186193  AnimationPlayer::getInstance(); // initializes the animationPlayer
     194
     195  ParticleEngine::getInstance();
    187196}
    188197
     
    367376            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    368377            this->glmis->step();
     378           
     379            testEmitter = new ParticleEmitter(Vector(1,0,0));
     380            testSystem = new ParticleSystem();
     381
     382            ParticleEngine::getInstance()->addConnection(testEmitter, testSystem);
     383
    369384            break;
    370385          }
     
    745760
    746761  TextEngine::getInstance()->draw();
     762
     763  ParticleEngine::getInstance()->draw();
     764
    747765  lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
    748766}
     
    931949
    932950      AnimationPlayer::getInstance()->tick(seconds);
     951
     952      ParticleEngine::getInstance()->tick(seconds);
    933953    }
    934954  this->lastFrame = currentFrame;
  • orxonox/branches/particleEngine/src/story_entities/world.h

    r3851 r3932  
    2525class GarbageCollector;
    2626class Text;
     27
     28class ParticleEmitter;
     29class ParticleSystem;
    2730
    2831//! The game world Interface
     
    109112  Terrain* terrain;                   //!< The Terrain of the World.
    110113
     114  ParticleSystem* testSystem;
     115  ParticleEmitter* testEmitter;
     116
    111117  GLuint objectList;                  //!< temporary: \todo this will be ereased soon
    112118  tList<WorldEntity>* entities;       //!< A template List of all entities. Every moving thing should be included here, and world automatically updates them.
Note: See TracChangeset for help on using the changeset viewer.