Changeset 4217 in orxonox.OLD for orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.cc
- Timestamp:
- May 18, 2005, 11:27:40 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.cc
r3966 r4217 35 35 { 36 36 this->setClassName ("ParticleSystem"); 37 this->material = NULL; 37 38 this->name = NULL; 38 39 this->maxCount = maxCount; 39 40 this->count = 0; 40 this->particleType = type;41 41 this->particles = NULL; 42 this->setConserve(.8); 43 this->setLifeSpan(.1); 42 this->deadList = NULL; 43 this->setConserve(1); 44 this->setLifeSpan(1); 44 45 this->setInheritSpeed(0); 45 46 this->glID = NULL; 46 47 this->setRadius(1.0, 1.0, 0.0); 47 this->setType( PARTICLE_SPRITE, 1);48 this->setType(type, 1); 48 49 ParticleEngine::getInstance()->addSystem(this); 49 50 } … … 53 54 \brief standard deconstructor 54 55 */ 55 ParticleSystem::~ParticleSystem() 56 ParticleSystem::~ParticleSystem() 56 57 { 57 58 // delete what has to be deleted here 58 59 ParticleEngine::getInstance()->removeSystem(this); 60 61 // deleting all the living Particles 62 while (this->particles) 63 { 64 Particle* tmpDelPart = this->particles; 65 this->particles = this->particles->next; 66 delete tmpDelPart; 67 } 68 69 // deleting all the dead particles 70 while (this->deadList) 71 { 72 Particle* tmpDelPart = this->deadList; 73 this->deadList = this->deadList->next; 74 delete tmpDelPart; 75 } 76 77 if (this->material) 78 delete this->material; 59 79 } 60 80 … … 199 219 { 200 220 prevPart->next = tickPart->next; 201 delete tickPart; 221 tickPart->next = this->deadList; 222 this->deadList = tickPart; 202 223 tickPart = prevPart->next; 203 224 } … … 206 227 prevPart = NULL; 207 228 this->particles = tickPart->next; 208 delete tickPart; 229 tickPart->next = this->deadList; 230 this->deadList = tickPart; 209 231 tickPart = this->particles; 210 232 } … … 221 243 /** 222 244 \brief draws all the Particles of this System 223 */ 224 void ParticleSystem::draw(void) 225 { 245 \param the time passed in seconds (since the last draw) 246 */ 247 void ParticleSystem::draw(float dt) 248 { 249 glPushAttrib(GL_ENABLE_BIT); 226 250 // material->select(); 227 228 229 glMatrixMode(GL_MODELVIEW);230 // glDisable(GL_LIGHTING);231 material->select();232 233 251 Particle* drawPart = particles; 234 if (likely(drawPart != NULL)) 252 253 switch (this->particleType) 235 254 { 236 glBegin(GL_POINTS); 255 case PARTICLE_SPRITE: 256 glMatrixMode(GL_MODELVIEW); 257 // glDisable(GL_LIGHTING); 258 material->select(); 259 glDisable(GL_DEPTH_TEST); 237 260 while (likely(drawPart != NULL)) 238 261 { 239 // draw in DOT mode240 262 glPushMatrix(); 241 263 glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); … … 243 265 glCallList(*this->glID); 244 266 245 // 267 //glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 246 268 drawPart = drawPart->next; 247 269 glPopMatrix(); 248 270 } 271 // glEnd(); 272 273 // glEnable(GL_LIGHTING); 274 275 glEnable(GL_DEPTH_TEST); 276 break; 277 default: 278 279 case PARTICLE_SPARK: 280 glEnable(GL_LINE_SMOOTH); 281 glBegin(GL_LINES); 282 while (likely(drawPart != NULL)) 283 { 284 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 285 glVertex3f(drawPart->position.x - drawPart->velocity.x, 286 drawPart->position.y - drawPart->velocity.y, 287 drawPart->position.z - drawPart->velocity.z); 288 drawPart = drawPart->next; 289 } 249 290 glEnd(); 291 break; 292 293 case PARTICLE_DOT: 294 glBegin(GL_POINTS); 295 while (likely(drawPart != NULL)) 296 { 297 glLineWidth(drawPart->radius); 298 299 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 300 drawPart = drawPart->next; 301 } 302 glEnd(); 303 break; 250 304 } 305 glPopAttrib(); 251 306 } 252 307 … … 264 319 if (unlikely(particles == NULL)) 265 320 { 266 this->particles = new Particle; 321 if (likely(deadList != NULL)) 322 { 323 this->particles = this->deadList; 324 deadList = deadList->next; 325 } 326 else 327 { 328 PRINTF(5)("Generating new Particle\n"); 329 this->particles = new Particle; 330 } 267 331 this->particles->next = NULL; 268 332 } … … 270 334 else 271 335 { 272 Particle* tmpPart = new Particle; 336 Particle* tmpPart; 337 if (likely(deadList != NULL)) 338 { 339 tmpPart = this->deadList; 340 deadList = deadList->next; 341 } 342 else 343 { 344 PRINTF(5)("Generating new Particle\n"); 345 tmpPart = new Particle; 346 } 273 347 tmpPart->next = this->particles; 274 348 this->particles = tmpPart; 275 349 } 276 350 277 particles->timeToLive = this->lifeSpan + (float)(rand om()/RAND_MAX)* this->randomLifeSpan;351 particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 278 352 particles->position = position; 279 353 particles->velocity = velocity; 280 354 281 355 // particle->rotation = ; //! \todo rotation is once again something to be done. 282 particles->mass = this->initialMass + (rand om()/RAND_MAX -.5)* this->randomInitialMass;283 particles->radius = this->startRadius + (rand om()/RAND_MAX-.5)*this->randomStartRadius;284 285 particles->radiusIt = (this->endRadius + (rand om()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;356 particles->mass = this->initialMass + (rand()/RAND_MAX -.5)* this->randomInitialMass; 357 particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius; 358 359 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive; 286 360 287 361 ++this->count; 288 362 } 289 363 else 290 PRINTF( 4)("maximum count of particles reached not adding any more\n");364 PRINTF(5)("maximum count of particles reached not adding any more\n"); 291 365 } 292 366 … … 298 372 PRINT(0)(" ParticleSystem %s\n", this->name); 299 373 PRINT(0)(" ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount); 300 } 374 if (deadList) 375 { 376 PRINT(0)(" - ParticleDeadList is used: "); 377 int i = 1; 378 Particle* tmpPart = this->deadList; 379 while (tmpPart = tmpPart->next) ++i; 380 PRINT(0)("count: %d\n", i); 381 } 382 }
Note: See TracChangeset
for help on using the changeset viewer.