Changeset 6621 in orxonox.OLD for trunk/src/lib/particles/particle_system.cc
- Timestamp:
- Jan 19, 2006, 11:46:28 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/particle_system.cc
r6620 r6621 32 32 #include <algorithm> 33 33 34 35 CREATE_FACTORY(ParticleSystem, CL_PARTICLE_SYSTEM);36 SHELL_COMMAND(texture, ParticleSystem, setMaterialTexture)37 ->defaultValues(1, "maps/evil-flower.png");38 39 34 using namespace std; 40 35 … … 44 39 * @param type The Type of the ParticleSystem 45 40 */ 46 ParticleSystem::ParticleSystem (unsigned int maxCount , PARTICLE_TYPE type)41 ParticleSystem::ParticleSystem (unsigned int maxCount) 47 42 { 48 43 this->init(); 49 44 50 45 this->setMaxCount(maxCount); 51 this->setType(type, 1);52 46 } 53 47 … … 103 97 this->setLifeSpan(1); 104 98 this->glID = NULL; 105 this->setType(PARTICLE_DEFAULT_TYPE, 1);106 99 107 100 this->toList(OM_ENVIRON); … … 126 119 LoadParam(root, "conserve", this, ParticleSystem, setConserve) 127 120 .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)"); 128 129 LoadParam(root, "type", this, ParticleSystem, setType)130 .describe("sets the type of the Particles, (dot, spark, sprite or model)");131 121 132 122 LoadParam(root, "texture", this, ParticleSystem, setMaterialTexture); … … 155 145 { 156 146 this->maxCount = maxCount; 157 }158 159 160 /**161 * @param particleType the type of particles in this System162 * @param count how many particles (in PARTICLE_MULTI-mode)163 @todo this will be different164 */165 void ParticleSystem::setType(const char* particleType)166 {167 if (!strcmp(particleType, "dot"))168 this->setType(PARTICLE_DOT);169 else if(!strcmp(particleType, "spark"))170 this->setType(PARTICLE_SPARK);171 else if(!strcmp(particleType, "model"))172 this->setType(PARTICLE_MODEL);173 else // if (strcmp(particleType, "SPRITE"))174 this->setType(PARTICLE_SPRITE);175 }176 177 /**178 * @param particleType the type of particles in this System179 * @param count how many particles (in PARTICLE_MULTI-mode)180 @todo this MUST be different181 */182 void ParticleSystem::setType(PARTICLE_TYPE particleType, int count)183 {184 this->particleType = particleType;185 this->dialectCount = count;186 // if (glID != NULL)187 // delete glID;188 189 // glID = new GLuint[count];190 // for (int i = 0; i< count; i++)191 // glID[i] = 0;192 193 // glID[0] = glGenLists(count);194 if (this->material)195 delete this->material;196 this->material = NULL;197 198 switch (this->particleType)199 {200 case PARTICLE_SPRITE:201 this->material = new Material("transperencyMap");202 this->material->setDiffuseMap("maps/radialTransparency.png");203 // material->setTransparency(.5);204 break;205 }206 147 } 207 148 … … 405 346 unsigned int ParticleSystem::getFaceCount() const 406 347 { 407 switch (this->particleType) 408 { 409 case PARTICLE_SPRITE: 410 return this->count; 411 break; 412 case PARTICLE_MODEL: 413 if (this->getModel(0)) 414 return this->count * this->getModel()->getTriangleCount(); 415 break; 416 } 348 return this->count; 417 349 } 418 350 … … 425 357 This is just the fastest Way to do this, but will most likely be changed in the future. 426 358 */ 427 void ParticleSystem::draw() const 428 { 429 glPushAttrib(GL_ENABLE_BIT); 430 431 Particle* drawPart = particles; 432 433 switch (this->particleType) 434 { 435 default: 436 case PARTICLE_SPRITE: 437 glDisable(GL_LIGHTING); 438 glMatrixMode(GL_MODELVIEW); 439 glDepthMask(GL_FALSE); 440 441 material->select(); 442 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 443 444 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 445 446 447 while (likely(drawPart != NULL)) 448 { 449 glColor4fv(drawPart->color); 450 //! @todo implement a faster code for the look-at Camera algorithm. 451 452 const PNode* camera = State::getCamera(); //!< @todo MUST be different 453 Vector cameraPos = camera->getAbsCoor(); 454 Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor(); 455 Vector view = cameraTargetPos - cameraPos; 456 Vector up = Vector(0, 1, 0); 457 up = camera->getAbsDir().apply(up); 458 Vector h = up.cross(view); 459 Vector v = h.cross(view); 460 h.normalize(); 461 v.normalize(); 462 v *= .5 * drawPart->radius; 463 h *= .5 * drawPart->radius; 464 465 glBegin(GL_TRIANGLE_STRIP); 466 glTexCoord2i(1, 1); 467 glVertex3f(drawPart->position.x - h.x - v.x, 468 drawPart->position.y - h.y - v.y, 469 drawPart->position.z - h.z - v.z); 470 glTexCoord2i(0, 1); 471 glVertex3f(drawPart->position.x - h.x + v.x, 472 drawPart->position.y - h.y + v.y, 473 drawPart->position.z - h.z + v.z); 474 glTexCoord2i(1, 0); 475 glVertex3f(drawPart->position.x + h.x - v.x, 476 drawPart->position.y + h.y - v.y, 477 drawPart->position.z + h.z - v.z); 478 glTexCoord2i(0, 0); 479 glVertex3f(drawPart->position.x + h.x + v.x, 480 drawPart->position.y + h.y + v.y, 481 drawPart->position.z + h.z + v.z); 482 483 glEnd(); 484 485 drawPart = drawPart->next; 486 } 487 glDepthMask(GL_TRUE); 488 break; 489 490 case PARTICLE_SPARK: 491 glDisable(GL_LIGHTING); 492 glDepthMask(GL_FALSE); 493 //glEnable(GL_LINE_SMOOTH); 494 glEnable(GL_BLEND); 495 496 glBegin(GL_LINES); 497 while (likely(drawPart != NULL)) 498 { 499 glColor4fv(drawPart->color); 500 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 501 glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius, 502 drawPart->position.y - drawPart->velocity.y * drawPart->radius, 503 drawPart->position.z - drawPart->velocity.z * drawPart->radius); 504 drawPart = drawPart->next; 505 } 506 glEnd(); 507 break; 508 509 case PARTICLE_MODEL: 510 { 511 GLfloat matrix[4][4]; 512 513 if (likely(this->getModel() != NULL)) 514 while (likely(drawPart != NULL)) 515 { 516 glPushMatrix(); 517 glMatrixMode(GL_MODELVIEW); 518 /* move */ 519 glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); 520 /* scale */ 521 glScalef(drawPart->radius, drawPart->radius, drawPart->radius); 522 /* rotate */ 523 drawPart->orientation.matrix (matrix); 524 glMultMatrixf((float*)matrix); 525 526 this->getModel()->draw(); 527 528 glPopMatrix(); 529 drawPart = drawPart->next; 530 } 531 else 532 PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getName()); 533 } 534 break; 535 536 case PARTICLE_DOT: 537 glDisable(GL_LIGHTING); 538 glBegin(GL_POINTS); 539 while (likely(drawPart != NULL)) 540 { 541 glColor4fv(drawPart->color); 542 543 glLineWidth(drawPart->radius); 544 545 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 546 drawPart = drawPart->next; 547 } 548 glEnd(); 549 break; 550 } 551 glPopAttrib(); 552 } 359 // void ParticleSystem::draw() const 360 // { 361 // glPushAttrib(GL_ENABLE_BIT); 362 // 363 // Particle* drawPart = particles; 364 // 365 // switch (this->particleType) 366 // { 367 // case PARTICLE_SPARK: 368 // glDisable(GL_LIGHTING); 369 // glDepthMask(GL_FALSE); 370 // //glEnable(GL_LINE_SMOOTH); 371 // glEnable(GL_BLEND); 372 // 373 // glBegin(GL_LINES); 374 // while (likely(drawPart != NULL)) 375 // { 376 // glColor4fv(drawPart->color); 377 // glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 378 // glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius, 379 // drawPart->position.y - drawPart->velocity.y * drawPart->radius, 380 // drawPart->position.z - drawPart->velocity.z * drawPart->radius); 381 // drawPart = drawPart->next; 382 // } 383 // glEnd(); 384 // break; 385 // 386 // case PARTICLE_MODEL: 387 // { 388 // GLfloat matrix[4][4]; 389 // 390 // if (likely(this->getModel() != NULL)) 391 // while (likely(drawPart != NULL)) 392 // { 393 // glPushMatrix(); 394 // glMatrixMode(GL_MODELVIEW); 395 // /* move */ 396 // glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); 397 // /* scale */ 398 // glScalef(drawPart->radius, drawPart->radius, drawPart->radius); 399 // /* rotate */ 400 // drawPart->orientation.matrix (matrix); 401 // glMultMatrixf((float*)matrix); 402 // 403 // this->getModel()->draw(); 404 // 405 // glPopMatrix(); 406 // drawPart = drawPart->next; 407 // } 408 // else 409 // PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getName()); 410 // } 411 // break; 412 // 413 // case PARTICLE_DOT: 414 // glDisable(GL_LIGHTING); 415 // glBegin(GL_POINTS); 416 // while (likely(drawPart != NULL)) 417 // { 418 // glColor4fv(drawPart->color); 419 // 420 // glLineWidth(drawPart->radius); 421 // 422 // glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 423 // drawPart = drawPart->next; 424 // } 425 // glEnd(); 426 // break; 427 // } 428 // glPopAttrib(); 429 // } 553 430 554 431 /** … … 621 498 void ParticleSystem::debug() const 622 499 { 623 PRINT(0)(" ParticleSystem %s, type: ", this->getName());624 {625 if (this->particleType == PARTICLE_MODEL)626 PRINT(0)("model");627 else if (this->particleType == PARTICLE_SPRITE)628 PRINT(0)("sprite");629 else if (this->particleType == PARTICLE_DOT)630 PRINT(0)("dot");631 else if (this->particleType == PARTICLE_SPARK)632 PRINT(0)("spark");633 634 PRINT(0)("\n");635 }636 637 500 PRINT(0)(" ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount); 638 501 if (deadList)
Note: See TracChangeset
for help on using the changeset viewer.