Changeset 4597 in orxonox.OLD for orxonox/trunk/src/lib/particles/particle_system.cc
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/particles/particle_system.cc
r4515 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 41 41 { 42 42 this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem"); 43 43 44 this->material = NULL; 44 45 this->maxCount = maxCount; … … 125 126 /** 126 127 \brief Sets the lifespan of newly created particles 127 */ 128 */ 128 129 void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan) 129 130 { … … 197 198 { 198 199 Particle* tickPart = particles; // the particle to Tick 199 Particle* prevPart = NULL; // 200 Particle* prevPart = NULL; // 200 201 while (likely(tickPart != NULL)) 201 202 { 202 203 // applying force to the System. 203 204 if (likely (tickPart->mass > 0.0)) 204 205 tickPart->velocity += tickPart->extForce / tickPart->mass * dt; 205 206 206 207 // rendering new position. 207 208 tickPart->position = tickPart->position + tickPart->velocity * dt; 208 209 tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle) 209 210 + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand; 210 211 211 212 tickPart->mass = massAnim.getValue(tickPart->lifeCycle) 212 213 213 + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand; 214 214 215 tickPart->extForce = Vector(0,0,0); 215 216 … … 223 224 224 225 if (this->conserve < 1.0) 225 226 tickPart->velocity = tickPart->velocity * this->conserve; 226 227 // find out if we have to delete tickPart 227 228 if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0)) 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 229 { 230 // remove the particle from the list 231 if (likely(prevPart != NULL)) 232 { 233 prevPart->next = tickPart->next; 234 tickPart->next = this->deadList; 235 this->deadList = tickPart; 236 tickPart = prevPart->next; 237 } 238 else 239 { 240 prevPart = NULL; 241 this->particles = tickPart->next; 242 tickPart->next = this->deadList; 243 this->deadList = tickPart; 244 tickPart = this->particles; 245 } 246 --this->count; 247 } 247 248 else 248 { 249 250 251 252 } 253 } 254 255 /** 249 { 250 prevPart = tickPart; 251 tickPart = tickPart->next; 252 } 253 } 254 } 255 256 /** 256 257 \brief applies some force to a Particle. 257 258 \param field the Field to apply. … … 281 282 282 283 Particle* drawPart = particles; 283 284 284 285 switch (this->particleType) 285 286 { … … 289 290 glDepthMask(GL_FALSE); 290 291 291 material->select(); 292 material->select(); 292 293 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 293 294 294 295 295 296 while (likely(drawPart != NULL)) 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 297 { 298 glColor4fv(drawPart->color); 299 //! \todo implement a faster code for the look-at Camera algorithm. 300 301 const PNode* camera = State::getInstance()->getCamera(); //!< \todo MUST be different 302 Vector cameraPos = camera->getAbsCoor(); 303 Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor(); 304 Vector view = cameraTargetPos - cameraPos; 305 Vector up = Vector(0, 1, 0); 306 up = camera->getAbsDir().apply(up); 307 Vector h = up.cross(view); 308 Vector v = h.cross(view); 309 h.normalize(); 310 v.normalize(); 311 v *= .5 * drawPart->radius; 312 h *= .5 * drawPart->radius; 313 314 glBegin(GL_TRIANGLE_STRIP); 315 glTexCoord2i(1, 1); 316 glVertex3f(drawPart->position.x - h.x - v.x, 317 drawPart->position.y - h.y - v.y, 318 drawPart->position.z - h.z - v.z); 319 glTexCoord2i(0, 1); 320 glVertex3f(drawPart->position.x - h.x + v.x, 321 drawPart->position.y - h.y + v.y, 322 drawPart->position.z - h.z + v.z); 323 glTexCoord2i(1, 0); 324 glVertex3f(drawPart->position.x + h.x - v.x, 325 drawPart->position.y + h.y - v.y, 326 drawPart->position.z + h.z - v.z); 327 glTexCoord2i(0, 0); 328 glVertex3f(drawPart->position.x + h.x + v.x, 329 drawPart->position.y + h.y + v.y, 330 drawPart->position.z + h.z + v.z); 331 332 glEnd(); 333 334 drawPart = drawPart->next; 335 } 335 336 glDepthMask(GL_TRUE); 336 337 break; … … 340 341 glBegin(GL_LINES); 341 342 while (likely(drawPart != NULL)) 342 343 344 345 346 347 348 349 343 { 344 glColor4fv(drawPart->color); 345 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 346 glVertex3f(drawPart->position.x - drawPart->velocity.x, 347 drawPart->position.y - drawPart->velocity.y, 348 drawPart->position.z - drawPart->velocity.z); 349 drawPart = drawPart->next; 350 } 350 351 glEnd(); 351 352 break; 352 353 353 354 case PARTICLE_DOT: 354 355 glBegin(GL_POINTS); 355 356 while (likely(drawPart != NULL)) 356 357 358 359 360 361 362 363 357 { 358 glColor4fv(drawPart->color); 359 360 glLineWidth(drawPart->radius); 361 362 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 363 drawPart = drawPart->next; 364 } 364 365 glEnd(); 365 366 break; … … 380 381 // if it is the first Particle 381 382 if (unlikely(particles == NULL)) 382 383 384 385 386 387 388 389 390 391 392 393 394 383 { 384 if (likely(deadList != NULL)) 385 { 386 this->particles = this->deadList; 387 deadList = deadList->next; 388 } 389 else 390 { 391 PRINTF(5)("Generating new Particle\n"); 392 this->particles = new Particle; 393 } 394 this->particles->next = NULL; 395 } 395 396 // filling the List from the beginning 396 397 else 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 398 { 399 Particle* tmpPart; 400 if (likely(deadList != NULL)) 401 { 402 tmpPart = this->deadList; 403 deadList = deadList->next; 404 } 405 else 406 { 407 PRINTF(5)("Generating new Particle\n"); 408 tmpPart = new Particle; 409 } 410 tmpPart->next = this->particles; 411 this->particles = tmpPart; 412 } 413 413 414 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 414 415 particles->lifeCycle = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.