Changeset 6625 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jan 20, 2006, 1:29:52 AM (19 years ago)
- Location:
- trunk/src/lib/particles
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/particle_emitter.cc
r6623 r6625 124 124 else if (this->system != NULL) 125 125 this->system->removeEmitter(this); 126 this->system = system;127 126 } 128 127 -
trunk/src/lib/particles/particle_system.cc
r6623 r6625 51 51 ParticleSystem::~ParticleSystem() 52 52 { 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 53 // deleting all the living Particles 54 while (this->particles) 55 { 56 Particle* tmpDelPart = this->particles; 57 this->particles = this->particles->next; 58 delete tmpDelPart; 59 } 60 61 // deleting all the dead particles 62 while (this->deadList) 63 { 64 Particle* tmpDelPart = this->deadList; 65 this->deadList = this->deadList->next; 66 delete tmpDelPart; 67 } 68 69 while(!this->emitters.empty()) 70 { 71 this->removeEmitter(this->emitters.front()); 72 } 73 73 74 74 } … … 102 102 103 103 LoadParam(root, "max-count", this, ParticleSystem, setMaxCount) 104 104 .describe("the maximal count of Particles, that can be emitted into this system"); 105 105 106 106 LoadParam(root, "life-span", this, ParticleSystem, setLifeSpan) 107 107 .describe("sets the life-span of the Particles."); 108 108 109 109 LoadParam(root, "conserve", this, ParticleSystem, setConserve) 110 110 .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)"); 111 111 112 112 LoadParamXML(root, "emitters", this, ParticleSystem, loadEmitters); … … 115 115 { 116 116 element->ToText(); 117 // PER-PARTICLE-ATTRIBUTES:117 // PER-PARTICLE-ATTRIBUTES: 118 118 LoadParam_CYCLE(element, "radius", this, ParticleSystem, setRadius) 119 119 .describe("The Radius of each particle over time (TimeIndex [0-1], radius at TimeIndex, randomRadius at TimeIndex)"); 120 120 121 121 LoadParam_CYCLE(element, "mass", this, ParticleSystem, setMass) 122 122 .describe("The Mass of each particle over time (TimeIndex: [0-1], mass at TimeIndex, randomMass at TimeIndex)"); 123 123 124 124 LoadParam_CYCLE(element, "color", this, ParticleSystem, setColor) 125 125 .describe("The Color of each particle over time (TimeIndex: [0-1], red: [0-1], green: [0-1], blue: [0-1], alpha: [0-1])"); 126 126 } 127 127 LOAD_PARAM_END_CYCLE(element); … … 229 229 if (emitter->getSystem() != NULL) 230 230 emitter->getSystem()->removeEmitter(emitter); 231 emitter->system = this; 231 232 this->emitters.push_back(emitter); 232 233 } … … 235 236 void ParticleSystem::removeEmitter(ParticleEmitter* emitter) 236 237 { 237 std::list<ParticleEmitter*>::iterator it = std::find(this->emitters.begin(), this->emitters.end(), emitter); 238 assert (emitter != NULL); 239 emitter->system = NULL; 240 this->emitters.remove(emitter); 241 /* std::list<ParticleEmitter*>::iterator it = std::find(this->emitters.begin(), this->emitters.end(), emitter); 238 242 if (it != this->emitters.end()) 239 this->emitters.erase(it); 243 this->emitters.erase(it);*/ 240 244 } 241 245 … … 251 255 Particle* prevPart = NULL; 252 256 while (likely(tickPart != NULL)) 257 { 258 // applying force to the System. 259 if (likely (tickPart->mass > 0.0)) 260 tickPart->velocity += tickPart->extForce / tickPart->mass * dt; 261 // rendering new position. 262 tickPart->position += tickPart->velocity * dt; 263 tickPart->orientation += tickPart->momentum *dt; 264 265 tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle) 266 + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand; 267 268 tickPart->mass = massAnim.getValue(tickPart->lifeCycle) 269 + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand; 270 271 tickPart->extForce = Vector(0,0,0); 272 273 // applying Color 274 tickPart->color[0] = this->colorAnim[0].getValue(tickPart->lifeCycle); 275 tickPart->color[1] = this->colorAnim[1].getValue(tickPart->lifeCycle); 276 tickPart->color[2] = this->colorAnim[2].getValue(tickPart->lifeCycle); 277 tickPart->color[3] = this->colorAnim[3].getValue(tickPart->lifeCycle); 278 279 // many more to come 280 281 if (this->conserve < 1.0) 253 282 { 254 // applying force to the System. 255 if (likely (tickPart->mass > 0.0)) 256 tickPart->velocity += tickPart->extForce / tickPart->mass * dt; 257 // rendering new position. 258 tickPart->position += tickPart->velocity * dt; 259 tickPart->orientation += tickPart->momentum *dt; 260 261 tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle) 262 + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand; 263 264 tickPart->mass = massAnim.getValue(tickPart->lifeCycle) 265 + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand; 266 267 tickPart->extForce = Vector(0,0,0); 268 269 // applying Color 270 tickPart->color[0] = this->colorAnim[0].getValue(tickPart->lifeCycle); 271 tickPart->color[1] = this->colorAnim[1].getValue(tickPart->lifeCycle); 272 tickPart->color[2] = this->colorAnim[2].getValue(tickPart->lifeCycle); 273 tickPart->color[3] = this->colorAnim[3].getValue(tickPart->lifeCycle); 274 275 // many more to come 276 277 if (this->conserve < 1.0) 283 tickPart->velocity *= this->conserve; 284 tickPart->momentum *= this->conserve; 285 } 286 // find out if we have to delete tickPart 287 if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0)) 288 { 289 // remove the particle from the list 290 if (likely(prevPart != NULL)) 278 291 { 279 tickPart->velocity *= this->conserve; 280 tickPart->momentum *= this->conserve; 292 prevPart->next = tickPart->next; 293 tickPart->next = this->deadList; 294 this->deadList = tickPart; 295 tickPart = prevPart->next; 281 296 } 282 // find out if we have to delete tickPart283 if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0))284 {285 // remove the particle from the list286 if (likely(prevPart != NULL))287 {288 prevPart->next = tickPart->next;289 tickPart->next = this->deadList;290 this->deadList = tickPart;291 tickPart = prevPart->next;292 }293 else294 {295 prevPart = NULL;296 this->particles = tickPart->next;297 tickPart->next = this->deadList;298 this->deadList = tickPart;299 tickPart = this->particles;300 }301 --this->count;302 }303 297 else 304 { 305 prevPart = tickPart; 306 tickPart = tickPart->next; 307 } 298 { 299 prevPart = NULL; 300 this->particles = tickPart->next; 301 tickPart->next = this->deadList; 302 this->deadList = tickPart; 303 tickPart = this->particles; 304 } 305 --this->count; 308 306 } 309 310 std::list<ParticleEmitter*>::iterator emitter; 311 for (emitter = this->emitters.begin(); emitter != this->emitters.end(); emitter++) 312 (*emitter)->tick(dt); 307 else 308 { 309 prevPart = tickPart; 310 tickPart = tickPart->next; 311 } 312 } 313 314 std::list<ParticleEmitter*>::iterator emitter; 315 for (emitter = this->emitters.begin(); emitter != this->emitters.end(); emitter++) 316 (*emitter)->tick(dt); 313 317 } 314 318 … … 321 325 Particle* tickPart = particles; 322 326 while (tickPart) 323 324 325 326 327 { 328 tickPart->extForce += field->calcForce(tickPart->position); 329 tickPart = tickPart->next; 330 } 327 331 } 328 332 … … 427 431 { 428 432 if (this->count <= this->maxCount) 433 { 434 // if it is the first Particle 435 if (unlikely(particles == NULL)) 429 436 { 430 // if it is the first Particle 431 if (unlikely(particles == NULL)) 432 { 433 if (likely(deadList != NULL)) 434 { 435 this->particles = this->deadList; 436 deadList = deadList->next; 437 } 438 else 439 { 440 PRINTF(5)("Generating new Particle\n"); 441 this->particles = new Particle; 442 } 443 this->particles->next = NULL; 444 } 445 // filling the List from the beginning 437 if (likely(deadList != NULL)) 438 { 439 this->particles = this->deadList; 440 deadList = deadList->next; 441 } 446 442 else 447 { 448 Particle* tmpPart; 449 if (likely(deadList != NULL)) 450 { 451 tmpPart = this->deadList; 452 deadList = deadList->next; 453 } 454 else 455 { 456 PRINTF(5)("Generating new Particle\n"); 457 tmpPart = new Particle; 458 } 459 tmpPart->next = this->particles; 460 this->particles = tmpPart; 461 } 462 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 463 particles->lifeCycle = 0.0; 464 particles->position = position; 465 particles->velocity = velocity; 466 467 particles->orientation = orientation; 468 particles->momentum = momentum; 469 470 // particle->rotation = ; //! @todo rotation is once again something to be done. 471 particles->massRand = 2*(float)rand()/RAND_MAX -1; 472 particles->radiusRand = 2* (float)rand()/RAND_MAX -1; 473 particles->mass = this->massAnim.getValue(0.0) + this->randMassAnim.getValue(0.0)*particles->massRand; 474 particles->radius = this->radiusAnim.getValue(0.0) + this->randRadiusAnim.getValue(0.0)*particles->radiusRand; 475 476 ++this->count; 443 { 444 PRINTF(5)("Generating new Particle\n"); 445 this->particles = new Particle; 446 } 447 this->particles->next = NULL; 477 448 } 449 // filling the List from the beginning 450 else 451 { 452 Particle* tmpPart; 453 if (likely(deadList != NULL)) 454 { 455 tmpPart = this->deadList; 456 deadList = deadList->next; 457 } 458 else 459 { 460 PRINTF(5)("Generating new Particle\n"); 461 tmpPart = new Particle; 462 } 463 tmpPart->next = this->particles; 464 this->particles = tmpPart; 465 } 466 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 467 particles->lifeCycle = 0.0; 468 particles->position = position; 469 particles->velocity = velocity; 470 471 particles->orientation = orientation; 472 particles->momentum = momentum; 473 474 // particle->rotation = ; //! @todo rotation is once again something to be done. 475 particles->massRand = 2*(float)rand()/RAND_MAX -1; 476 particles->radiusRand = 2* (float)rand()/RAND_MAX -1; 477 particles->mass = this->massAnim.getValue(0.0) + this->randMassAnim.getValue(0.0)*particles->massRand; 478 particles->radius = this->radiusAnim.getValue(0.0) + this->randRadiusAnim.getValue(0.0)*particles->radiusRand; 479 480 ++this->count; 481 } 478 482 else 479 483 PRINTF(5)("maximum count of particles reached not adding any more\n"); … … 487 491 PRINT(0)(" ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount); 488 492 if (deadList) 489 490 491 492 493 494 495 496 } 493 { 494 PRINT(0)(" - ParticleDeadList is used: "); 495 int i = 1; 496 Particle* tmpPart = this->deadList; 497 while (tmpPart = tmpPart->next) ++i; 498 PRINT(0)("count: %d\n", i); 499 } 500 }
Note: See TracChangeset
for help on using the changeset viewer.