Changeset 3932 in orxonox.OLD for orxonox/branches/particleEngine
- Timestamp:
- Apr 23, 2005, 12:42:09 AM (20 years ago)
- Location:
- orxonox/branches/particleEngine/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.cc
r3931 r3932 18 18 #include "particle_emitter.h" 19 19 20 #include "particle_system.h" 21 20 22 using namespace std; 21 23 … … 32 34 this->emissionRate = emissionRate; 33 35 this->velocity = velocity; 36 37 this->saveTime = 0.0; 34 38 } 35 39 … … 104 108 */ 105 109 110 void 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 29 29 void start(); 30 30 void stop(); 31 void tick(float dt, ParticleSystem* system); 31 32 32 33 /* controlling the behavour: these can be used as Animation interfaces */ … … 41 42 float emissionRate; //!< amount of particles per seconds emitted by emiter 42 43 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). 43 46 }; 44 47 -
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_engine.cc
r3931 r3932 33 33 34 34 this->systemList = new tList<ParticleSystem>; 35 36 this->connectionList = new tList<ParticleConnection>; 35 37 } 36 38 … … 58 60 delete this->systemList; 59 61 62 delete this->connectionList; 60 63 61 64 ParticleEngine::singletonRef = NULL; 62 65 } 66 67 void 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 */ 78 void 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 63 87 64 88 /** … … 68 92 void ParticleEngine::tick(float dt) 69 93 { 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 70 106 tIterator<ParticleSystem>* tmpIt = systemList->getIterator(); 71 107 ParticleSystem* tmpSys = tmpIt->nextElement(); … … 78 114 79 115 } 116 117 118 void 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 28 28 29 29 void tick(float dt); 30 void draw(void); 30 31 31 32 void addSystem(ParticleSystem* system); 32 33 void addEmitter(ParticleEmitter* emitter); 33 void addCon ection(ParticleEmitter* emitter, ParticleSystem* system);34 void addConnection(ParticleEmitter* emitter, ParticleSystem* system); 34 35 35 36 bool removeSystem(ParticleSystem* system); -
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.cc
r3931 r3932 20 20 #include "particle_emitter.h" 21 21 #include "particle_engine.h" 22 #include "compiler.h" 22 23 23 24 using namespace std; … … 36 37 37 38 this->particleType = type; 39 this->particles = NULL; 40 this->conserve = 1.0; 41 this->setLifeSpan(5.0); 42 43 ParticleEngine::getInstance()->addSystem(this); 38 44 } 39 45 … … 43 49 44 50 */ 45 ParticleSystem::~ParticleSystem 51 ParticleSystem::~ParticleSystem() 46 52 { 47 53 // delete what has to be deleted here 48 54 } 49 55 56 // setting properties 57 void ParticleSystem::setMaterial(Material* material) 58 { 59 60 } 61 62 void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan) 63 { 64 65 } 66 67 void ParticleSystem::setRadius(float startRadius, float endRadius, float randomRadius) 68 { 69 70 } 71 72 void ParticleSystem::setConserve(float conserve) 73 { 74 this->conserve = conserve; 75 } 76 77 50 78 51 79 void ParticleSystem::tick(float dt) 52 80 { 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 92 void 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 111 void 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 } 53 126 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 } 54 134 55 } -
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.h
r3931 r3932 34 34 Quaternion rotation; //!< The current rotation of this particle. 35 35 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. 38 37 39 38 Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) … … 42 41 //! A class to handle particle Systems 43 42 class ParticleSystem : public BaseObject { 43 friend class ParticleEmitter; 44 44 45 45 public: … … 50 50 void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); 51 51 void setRadius(float startRadius, float endRadius, float randomRadius = 0.0); 52 void setConserve(float conserve); 53 void setMass(float mass, float randomMass); 52 54 53 55 void tick(float dt); 56 void draw(void); 54 57 55 58 private: … … 60 63 float endRadius; 61 64 float randomRadius; 65 float initialMass; 66 float randomInitialMass; 62 67 63 68 // particles … … 66 71 Material* material; //!< A Material for all the Particles. 67 72 Particle* particles; //!< A list of particles of this System. 73 74 75 void addParticle(Vector position, Vector velocity, unsigned int data = 0); 76 68 77 }; 69 78 -
orxonox/branches/particleEngine/src/story_entities/world.cc
r3870 r3932 40 40 #include "animation_player.h" 41 41 42 #include "particle_engine.h" 43 #include "particle_system.h" 44 #include "particle_emitter.h" 45 42 46 #include "command_node.h" 43 47 #include "glmenu_imagescreen.h" … … 162 166 AnimationPlayer::getInstance()->debug(); 163 167 delete AnimationPlayer::getInstance(); // this should be at the end of the unloading sequence. 168 169 delete ParticleEngine::getInstance(); 170 164 171 //delete garbagecollecor 165 172 //delete animator … … 185 192 this->entities = new tList<WorldEntity>(); 186 193 AnimationPlayer::getInstance(); // initializes the animationPlayer 194 195 ParticleEngine::getInstance(); 187 196 } 188 197 … … 367 376 trackManager->condition(2, LEFTRIGHT, this->localPlayer); 368 377 this->glmis->step(); 378 379 testEmitter = new ParticleEmitter(Vector(1,0,0)); 380 testSystem = new ParticleSystem(); 381 382 ParticleEngine::getInstance()->addConnection(testEmitter, testSystem); 383 369 384 break; 370 385 } … … 745 760 746 761 TextEngine::getInstance()->draw(); 762 763 ParticleEngine::getInstance()->draw(); 764 747 765 lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes // 748 766 } … … 931 949 932 950 AnimationPlayer::getInstance()->tick(seconds); 951 952 ParticleEngine::getInstance()->tick(seconds); 933 953 } 934 954 this->lastFrame = currentFrame; -
orxonox/branches/particleEngine/src/story_entities/world.h
r3851 r3932 25 25 class GarbageCollector; 26 26 class Text; 27 28 class ParticleEmitter; 29 class ParticleSystem; 27 30 28 31 //! The game world Interface … … 109 112 Terrain* terrain; //!< The Terrain of the World. 110 113 114 ParticleSystem* testSystem; 115 ParticleEmitter* testEmitter; 116 111 117 GLuint objectList; //!< temporary: \todo this will be ereased soon 112 118 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.