Changeset 8088 in orxonox.OLD for branches/bsp_model/src
- Timestamp:
- Jun 1, 2006, 5:19:14 PM (18 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/Makefile.am
r8087 r8088 19 19 \ 20 20 bsp_manager.cc \ 21 bsp_file.cc 21 bsp_file.cc \ 22 bsp_tree_node.cc \ 23 bsp_tree_leaf.cc 22 24 23 25 … … 45 47 \ 46 48 bsp_manager.h \ 47 bsp_file.h 49 bsp_file.h \ 50 bsp_tree_node.h \ 51 bsp_tree_leaf.h -
branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
r8087 r8088 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch 13 13 14 14 Inspired by: 15 15 Rendering Q3 Maps by Morgan McGuire http://graphics.cs.brown.edu/games/quake/quake3.html … … 18 18 */ 19 19 20 20 21 #include "bsp_file.h" 21 22 #include "bsp_tree_node.h" 22 23 #include <fstream> 24 #include "file.h" 23 25 #include <sys/stat.h> 24 26 #include <string.h> … … 233 235 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 234 236 this->load_textures(); 235 237 236 238 // Load the lightMaps 237 239 this->glLightMapTextures = new GLuint[this->numLightMaps]; 238 240 for(int i = 0; i < this->numLightMaps; i++) 239 241 this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); 240 242 241 243 //Create white texture for if no lightmap specified 242 244 glGenTextures(1, &this->whiteLightMap); 243 245 glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); 244 246 //Create texture 245 247 this->whiteTexture[0]=255; 246 248 this->whiteTexture[1]=255; 247 249 this->whiteTexture[2]=255; 248 250 249 251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 250 252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); … … 255 257 256 258 257 259 258 260 /* control the mipmap levels */ 259 261 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); … … 271 273 (const GLvoid *)&(this->whiteTexture)); 272 274 273 gluBuild2DMipmaps( 275 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, 274 276 GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); 275 276 277 278 277 279 278 280 // Get the number of patches … … 294 296 295 297 PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches); 296 298 297 299 this->swapAllBspCoordinates(); 298 300 299 301 // Do tesselation for all Faces of type 2 300 302 for( int i = 0; i < this->numFaces; i++) { … … 310 312 return -1; 311 313 } 312 313 314 315 314 316 315 317 } … … 343 345 float z1 =(((plane *) this->planes) [planeIndex]).z; 344 346 thisNode->leafIndex = 0; 345 thisNode->d 347 thisNode->d = (((plane *) this->planes) [planeIndex]).d; 346 348 347 349 thisNode->plane = Vector(x1,y1,z1); … … 389 391 char ext [100]; 390 392 struct stat results; 391 392 393 394 393 395 this->Materials = new AMat[this->numTextures]; 394 396 for(int i = 0 ; i < this->numTextures; i++) { 395 397 PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]); 396 397 398 399 398 400 strcpy(fileName, &this->textures[8+ 72*i]); 399 401 if(strlen(fileName) == 0) 400 402 { 401 // 403 // Default Material 402 404 this->Materials[i].mat = new Material(); 403 405 this->Materials[i].mat->setDiffuse(0.1,0.1,1.0); … … 412 414 this->Materials[i].animated = false; 413 415 continue; 414 } 415 416 } 417 416 418 // Check for mov 417 419 strcpy(fileName, &this->textures[8+ 72*i]); … … 421 423 absFileName = ResourceManager::getFullName(fileName); 422 424 423 if( ResourceManager::isFile(absFileName)) {425 if(File(absFileName).exists()) { 424 426 PRINTF(0)("BSP FILE: gefunden . \n"); 425 427 this->Materials[i] = this->loadAVI(fileName); 426 428 continue; 427 429 } 428 430 429 431 // Check for avi 430 432 strcpy(fileName, &this->textures[8+ 72*i]); … … 434 436 absFileName = ResourceManager::getFullName(fileName); 435 437 436 if( ResourceManager::isFile(absFileName)) {438 if(File(absFileName).exists()) { 437 439 PRINTF(0)("BSP FILE: gefunden . \n"); 438 440 this->Materials[i] = this->loadAVI(fileName); 439 441 continue; 440 442 } 441 443 442 444 // Check for mpg 443 445 strcpy(fileName, &this->textures[8+ 72*i]); … … 447 449 absFileName = ResourceManager::getFullName(fileName); 448 450 449 if( ResourceManager::isFile(absFileName)) {451 if(File(absFileName).exists()) { 450 452 PRINTF(0)("BSP FILE: gefunden . \n"); 451 453 this->Materials[i] = this->loadAVI(fileName); 452 454 continue; 453 455 } 454 456 455 457 // Check for tga 456 458 strcpy(fileName, &this->textures[8+ 72*i]); … … 460 462 absFileName = ResourceManager::getFullName(fileName); 461 463 462 if( ResourceManager::isFile(absFileName)) {464 if(File(absFileName).exists()) { 463 465 PRINTF(0)("BSP FILE: gefunden . \n"); 464 466 this->Materials[i] = this->loadMat(fileName); … … 471 473 absFileName = ResourceManager::getFullName(fileName); 472 474 473 if( ResourceManager::isFile(absFileName)/*stat( absFileName.c_str() , &results) == 0*/) {475 if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { 474 476 PRINTF(0)("BSP FILE: gefunden . \n"); 475 477 this->Materials[i] = this->loadMat(fileName); … … 481 483 strncat (fileName, ext, strlen(fileName)); 482 484 absFileName = ResourceManager::getFullName(fileName); 483 if( ResourceManager::isFile(absFileName)) {485 if(File(absFileName).exists()) { 484 486 PRINTF(0)("BSP FILE: gefunden . \n"); 485 487 this->Materials[i] =this->loadMat(fileName); … … 493 495 strncat (fileName, ext, strlen(fileName)); 494 496 absFileName = ResourceManager::getFullName(fileName); 495 if( ResourceManager::isFile(absFileName)) {497 if(File(absFileName).exists()) { 496 498 PRINTF(0)("BSP FILE: gefunden . \n"); 497 499 this->Materials[i] =this->loadMat(fileName); … … 499 501 } 500 502 501 503 502 504 503 505 // Check for bmp … … 507 509 absFileName = ResourceManager::getFullName(fileName); 508 510 509 if( ResourceManager::isFile(absFileName)) {511 if(File(absFileName).exists()) { 510 512 PRINTF(0)("BSP FILE: gefunden . \n"); 511 513 this->Materials[i] =this->loadMat(fileName); … … 519 521 absFileName = ResourceManager::getFullName(fileName); 520 522 521 if( ResourceManager::isFile(absFileName)) {523 if(File(absFileName).exists()) { 522 524 PRINTF(0)("BSP FILE: gefunden . \n"); 523 525 this->Materials[i] = this->loadMat(fileName); 524 526 continue; 525 527 } 526 527 528 // 528 529 530 // Default Material 529 531 this->Materials[i].mat = new Material(); 530 532 this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); … … 538 540 this->Materials[i].alpha = true; 539 541 this->Materials[i].animated = false; 540 542 541 543 } 542 544 } … … 551 553 if(this->testSurf != NULL) { 552 554 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; 553 else 555 else tmpAMat.alpha = false; 554 556 } else tmpAMat.alpha = false; 555 557 … … 558 560 tmp->setAmbient(1.0,1.0,1.0 ); 559 561 tmp->setSpecular(1.0,1.0,1.0); 560 // 561 // 562 // tmp->setShininess(.5); 563 // tmp->setTransparency(0.0); 562 564 563 565 tmp->setDiffuseMap(mat); … … 580 582 //tmp->setAmbient(1.0,1.0,1.0 ); 581 583 //tmp->setSpecular(1.0,1.0,1.0); 582 // 583 // 584 // tmp->setShininess(.5);tmpAMat 585 // tmp->setTransparency(0.0); 584 586 585 587 //tmp->setDiffuseMap(mat); … … 608 610 sc*=scale; 609 611 if(false) 610 ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75; 612 ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75; 611 613 else 612 614 ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc ; 613 615 } 614 616 615 617 glGenTextures(1, &lightMap); 616 618 glBindTexture(GL_TEXTURE_2D, lightMap); … … 638 640 (const GLvoid *)&lightMapTexture); 639 641 640 642 641 643 // build the MipMaps automaticaly 642 644 errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D, … … 648 650 (const GLvoid *)&lightMapTexture 649 651 ); 650 652 651 653 652 654 … … 658 660 /** 659 661 * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface. 660 * @param iface integer index of face 662 * @param iface integer index of face 661 663 * @todo cleanup this function, let the user choose the level of tesselation 662 664 */ 663 664 665 666 665 667 void BspFile::tesselate(int iface) 666 668 { … … 791 793 792 794 793 //Vertice[u*(tesselation+1)+v]= 795 //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); 794 796 Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px); 795 797 Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px); … … 826 828 // Debug Model 827 829 //*********************************************************************************************************************** 828 830 829 831 this->VertexArrayModels[this->patchOffset] = new VertexArrayModel(); 830 832 VertexArrayModel* tmp = this->VertexArrayModels[this->patchOffset]; … … 989 991 void BspFile::swapAllBspCoordinates() 990 992 { 991 993 992 994 for(int i = 0; i < this->numVertex ; ++i) 993 995 { … … 995 997 this->swapCoords(&((BspVertex *)this->vertice)[i].normal[0]); 996 998 997 999 998 1000 } 999 1001 1000 1002 for(int i = 0; i < this->numLeafs ; ++i) 1001 1003 { 1002 1004 this->swapCoords(this->leaves[i].mins); 1003 1005 this->swapCoords(this->leaves[i].maxs); 1004 1006 1005 1007 } 1006 1008 1007 1009 for(int i = 0; i < this->numPlanes; ++i) 1008 1010 { … … 1014 1016 } 1015 1017 1016 1018 1017 1019 for(int i = 0; i < this->numFaces; ++i) 1018 1020 { 1019 1021 this->swapCoords(this->faces[i].normal); 1020 1022 } 1021 1023 1022 1024 } 1023 1025 … … 1036 1038 array[0] = scale * array[1] ; 1037 1039 array[1] = scale * array[2]; 1038 array[2] = scale * sto ; 1040 array[2] = scale * sto ; 1039 1041 } 1040 1042 1041 1043 } 1042 1044 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r8087 r8088 901 901 902 902 // Return the normal here: Normal's stored in this->collPlane; 903 if(collision) worldEntity->collidesWithGround(out,out1,out2);903 // if(collision) worldEntity->collidesWithGround(out,out1,out2); 904 904 905 905 }
Note: See TracChangeset
for help on using the changeset viewer.