Changeset 3934 in orxonox.OLD for orxonox/branches/particleEngine/src/lib/graphics
- Timestamp:
- Apr 23, 2005, 2:27:17 AM (20 years ago)
- Location:
- orxonox/branches/particleEngine/src/lib/graphics/particles
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.cc
r3933 r3934 112 112 { 113 113 // saving the time 114 float countF = (dt+this->saveTime) * this->emissionRate; 115 int count = (int)round(countF); 116 this->saveTime = countF - (float)count; 117 118 printf( "%d::%f::emmit %f\n", count, countF, emissionRate); 114 float count = (dt+this->saveTime) * this->emissionRate; 115 this->saveTime = modff(count, &count); 116 this->saveTime /= this->emissionRate; 119 117 120 118 for (int i = 0; i <= count; i++) -
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.cc
r3932 r3934 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ WORLD_ENTITY16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PARTICLE 17 17 18 18 #include "particle_system.h" … … 32 32 \todo this constructor is not jet implemented - do it 33 33 */ 34 ParticleSystem::ParticleSystem (unsigned int count, PARTICLE_TYPE type)34 ParticleSystem::ParticleSystem (unsigned int maxCount, PARTICLE_TYPE type) 35 35 { 36 36 this->setClassName ("ParticleSystem"); 37 37 38 this->maxCount = maxCount; 39 this->count = 0; 38 40 this->particleType = type; 39 41 this->particles = NULL; 40 42 this->conserve = 1.0; 41 this->setLifeSpan( 5.0);43 this->setLifeSpan(.1); 42 44 43 45 ParticleEngine::getInstance()->addSystem(this); … … 62 64 void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan) 63 65 { 64 66 this->lifeSpan = lifeSpan; 67 this->randomLifeSpan = randomLifeSpan; 65 68 } 66 69 … … 79 82 void ParticleSystem::tick(float dt) 80 83 { 81 Particle* tmpPart = particles; 82 while (likely(tmpPart != NULL)) 84 Particle* tickPart = particles; // the particle to Tick 85 Particle* prevPart = NULL; // 86 while (likely(tickPart != NULL)) 83 87 { 84 tmpPart->position = tmpPart->position + tmpPart->velocity; 88 89 tickPart->position = tickPart->position + tickPart->velocity; 90 // many more to come 91 85 92 86 // many more to come87 93 88 tmpPart = tmpPart->next; 94 95 96 97 // find out if we have to delete tickPart 98 if ((tickPart->timeToLive -= dt) <= 0) 99 { 100 // remove the particle from the list 101 if (likely(prevPart != NULL)) 102 { 103 prevPart->next = tickPart->next; 104 delete tickPart; 105 tickPart = prevPart->next; 106 } 107 else 108 { 109 prevPart = NULL; 110 this->particles = tickPart->next; 111 delete tickPart; 112 tickPart = this->particles; 113 } 114 --this->count; 115 printf("deleted particle: count %d\n", count); 116 } 117 else 118 { 119 prevPart = tickPart; 120 tickPart = tickPart->next; 121 } 89 122 } 90 123 } … … 92 125 void ParticleSystem::draw(void) 93 126 { 94 Particle* tmpPart = particles;95 if (likely( tmpPart != NULL))127 Particle* drawPart = particles; 128 if (likely(drawPart != NULL)) 96 129 { 97 glBegin(GL_ POINTS);98 while (likely( tmpPart != NULL))130 glBegin(GL_TRIANGLES); 131 while (likely(drawPart != NULL)) 99 132 { 100 133 // draw in DOT mode 101 glVertex3f( tmpPart->position.x, tmpPart->position.y, tmpPart->position.z);134 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 102 135 103 136 104 tmpPart = tmpPart->next;137 drawPart = drawPart->next; 105 138 } 106 139 glEnd(); … … 111 144 void ParticleSystem::addParticle(Vector position, Vector velocity, unsigned int data) 112 145 { 113 // if it is the first Particle 114 if (unlikely(particles == NULL)) 146 if (this->count <= this->maxCount) 115 147 { 116 this->particles = new Particle; 117 this->particles->next = NULL; 148 // if it is the first Particle 149 if (unlikely(particles == NULL)) 150 { 151 this->particles = new Particle; 152 this->particles->next = NULL; 153 } 154 // filling the List from the beginning 155 else 156 { 157 Particle* tmpPart = new Particle; 158 tmpPart->next = this->particles; 159 this->particles = tmpPart; 160 } 161 162 particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan; 163 particles->position = position; 164 particles->velocity = velocity; 165 // particle->rotation = ; //! \todo rotation is once again something to be done. 166 particles->mass = this->initialMass + (random()/RAND_MAX)* this->randomInitialMass; 167 particles->radius = this->startRadius + (random()/RAND_MAX)*this->randomRadius; 168 169 ++this->count; 118 170 } 119 // filling the List from the beginning120 171 else 121 { 122 Particle* tmpPart = new Particle; 123 tmpPart->next = this->particles; 124 this->particles = tmpPart; 125 } 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; 172 PRINTF(4)("maximum count of particles reached not adding any more\n"); 133 173 } 134 174 -
orxonox/branches/particleEngine/src/lib/graphics/particles/particle_system.h
r3932 r3934 44 44 45 45 public: 46 ParticleSystem(unsigned int particleCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE);46 ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); 47 47 virtual ~ParticleSystem(); 48 48 … … 67 67 68 68 // particles 69 int maxCount; //!< the count of Particles for this ParticleSystem. 69 int maxCount; //!< The maximum count of Particles. 70 int count; //!< The current count of Particles. 70 71 PARTICLE_TYPE particleType;//!< A type for all the Particles 71 72 Material* material; //!< A Material for all the Particles.
Note: See TracChangeset
for help on using the changeset viewer.