Changeset 8490 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Jun 15, 2006, 9:34:48 PM (19 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 2 deleted
- 7 edited
- 20 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/graphics_engine.cc
r8316 r8490 66 66 67 67 this->bDisplayFPS = false; 68 this->bAntialiasing = false; 68 69 this->minFPS = 9999; 69 70 this->maxFPS = 0; … … 283 284 SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0); 284 285 285 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); 286 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); 287 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); 288 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 286 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); //Use at least 5 bits of Red 287 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); //Use at least 5 bits of Green 288 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); //Use at least 5 bits of Blue 289 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); //Use at least 16 bits for the depth buffer 289 290 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //Enable double buffering 291 292 // enable antialiasing? 293 if( this->bAntialiasing) 294 { 295 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,4); 296 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); 297 } 290 298 291 299 glEnable(GL_CULL_FACE); -
trunk/src/lib/graphics/graphics_engine.h
r8316 r8490 46 46 static void setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha = 1.0); 47 47 48 inline void setAntialiasing(bool flag) { this->bAntialiasing = flag; } 49 inline bool getAntialiasing() { return this->bAntialiasing; } 48 50 49 51 /** @returns the x resolution */ … … 109 111 bool shadowsEnabled; //!< If Shadows should be enabled. 110 112 bool particlesEnabled; //!< If particles should be enabled. 113 bool bAntialiasing; //!< true if antialiasing enabled 114 111 115 int particlesValue; //!< How many particles 112 116 int textureQuality; //!< the quality of Textures -
trunk/src/lib/graphics/importer/Makefile.am
r8363 r8490 5 5 6 6 libORXimporter_a_SOURCES = model.cc \ 7 interactive_model.cc \ 8 md_model_structure.cc \ 7 9 vertex_array_model.cc \ 8 10 grid.cc \ … … 10 12 objModel.cc \ 11 13 primitive_model.cc \ 12 md2Model.cc \13 14 height_map.cc \ 14 15 bsp_manager.cc \ … … 22 23 texture_sequence.cc \ 23 24 media_container.cc \ 24 movie_player.cc 25 movie_player.cc \ 26 \ 27 bsp_manager.cc \ 28 bsp_file.cc \ 29 bsp_tree_node.cc \ 30 bsp_tree_leaf.cc \ 31 \ 32 md2/md2Model.cc \ 33 \ 34 md3/md3_model.cc \ 35 md3/md3_animation.cc \ 36 md3/md3_bone_frame.cc \ 37 md3/md3_mesh.cc \ 38 md3/md3_data.cc \ 39 md3/md3_tag.cc 25 40 26 41 … … 32 47 noinst_HEADERS = \ 33 48 model.h \ 49 interactive_model.h \ 50 md_model_structure.cc \ 34 51 tc.h \ 35 52 vertex_array_model.h \ … … 38 55 objModel.h \ 39 56 primitive_model.h \ 40 md2Model.h \41 57 anorms.h \ 42 58 anormtab.h \ … … 54 70 bsp_file.h \ 55 71 bsp_tree_node.h \ 56 bsp_tree_leaf.h 72 bsp_tree_leaf.h \ 73 \ 74 md2/md2Model.h \ 75 \ 76 md3/md3_model.h \ 77 md3/md3_animation.h \ 78 md3/md3_bone_frame.h \ 79 md3/md3_mesh.h \ 80 md3/md3_data.h \ 81 md3/md3_tag.h 82 -
trunk/src/lib/graphics/importer/bsp_file.cc
r8330 r8490 37 37 #include <SDL/SDL_image.h> 38 38 39 // STL Containers 40 #include <vector> 41 39 42 using namespace std; 40 43 … … 50 53 int BspFile::read(const char* name) 51 54 { 52 //this->scale = 0.4;55 this->scale = 1.0; 53 56 int offset; 54 57 int size; … … 211 214 bspFile.read(this->visData, size); 212 215 213 PRINTF( 4)("BSP FILE: VisDataSize: %i Bytes. \n", size);214 PRINTF( 4)("BSP FILE: NumVisData: %i. \n", size /1 - 8);215 PRINTF( 4)("BSP FILE: Remainder: %i. \n", size % 1);216 PRINTF( 4)("BSP FILE: VisDataOffset: %i. \n", offset);216 PRINTF(0)("BSP FILE: VisDataSize: %i Bytes. \n", size); 217 PRINTF(0)("BSP FILE: NumVisData: %i. \n", size /1 - 8); 218 PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 1); 219 PRINTF(0)("BSP FILE: VisDataOffset: %i. \n", offset); 217 220 218 221 // Get the Textures … … 388 391 { 389 392 ::std::string absFileName; 390 char fileName [228]; 391 char ext [100]; 393 char* baseName = "/worlds/bsp/"; 394 395 char fileName [500]; 396 char ext [500]; 392 397 struct stat results; 393 398 … … 401 406 if(strlen(fileName) == 0) 402 407 { 408 403 409 // Default Material 404 410 this->Materials[i].mat = new Material(); 405 411 this->Materials[i].mat->setDiffuse(0.1,0.1,1.0); 406 412 this->Materials[i].mat->setAmbient(0.1,0.1,1.0 ); … … 417 423 418 424 // Check for mov 419 strcpy(fileName, &this->textures[8+ 72*i]); 425 strcpy(fileName, baseName); 426 strcpy(ext, &this->textures[8+ 72*i]); 427 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 420 428 strcpy(ext, ".mov"); 421 strncat (fileName, ext, strlen(fileName)); 429 strncat (fileName, ext, strlen(fileName) ); 430 431 PRINTF(0)("BSP FILE: Name %s . \n", fileName); 422 432 423 433 absFileName = ResourceManager::getFullName(fileName); … … 430 440 431 441 // Check for avi 432 strcpy(fileName, &this->textures[8+ 72*i]); 442 strcpy(fileName, baseName); 443 strcpy(ext, &this->textures[8+ 72*i]); 444 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 433 445 strcpy(ext, ".avi"); 434 446 strncat (fileName, ext, strlen(fileName)); … … 443 455 444 456 // Check for mpg 445 strcpy(fileName, &this->textures[8+ 72*i]); 457 strcpy(fileName, baseName); 458 strcpy(ext, &this->textures[8+ 72*i]); 459 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 446 460 strcpy(ext, ".mpg"); 447 461 strncat (fileName, ext, strlen(fileName)); … … 456 470 457 471 // Check for tga 458 strcpy(fileName, &this->textures[8+ 72*i]); 472 strcpy(fileName, baseName); 473 strcpy(ext, &this->textures[8+ 72*i]); 474 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 459 475 strcpy(ext, ".tga"); 460 476 strncat (fileName, ext, strlen(fileName)); … … 468 484 } 469 485 // Check for TGA 470 strcpy(fileName, &this->textures[8+ 72*i]); 486 strcpy(fileName, baseName); 487 strcpy(ext, &this->textures[8+ 72*i]); 488 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 471 489 strcpy(ext, ".TGA"); 472 490 strncat (fileName, ext, strlen(fileName)); … … 479 497 } 480 498 // Check for jpg 481 strcpy(fileName, &this->textures[8+ 72*i]); 499 strcpy(fileName, baseName); 500 strcpy(ext, &this->textures[8+ 72*i]); 501 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 482 502 strcpy(ext, ".jpg"); 483 503 strncat (fileName, ext, strlen(fileName)); … … 491 511 492 512 // Check for JPG 493 strcpy(fileName, &this->textures[8+ 72*i]); 513 strcpy(fileName, baseName); 514 strcpy(ext, &this->textures[8+ 72*i]); 515 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 494 516 strcpy(ext, ".JPG"); 495 517 strncat (fileName, ext, strlen(fileName)); … … 504 526 505 527 // Check for bmp 506 strcpy(fileName, &this->textures[8+ 72*i]); 528 strcpy(fileName, baseName); 529 strcpy(ext, &this->textures[8+ 72*i]); 530 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 507 531 strcpy(ext, ".bmp"); 508 532 strncat (fileName, ext, strlen(fileName)); … … 516 540 517 541 // Check for BMP 518 strcpy(fileName, &this->textures[8+ 72*i]); 542 strcpy(fileName, baseName); 543 strcpy(ext, &this->textures[8+ 72*i]); 544 strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); 519 545 strcpy(ext, ".BMP"); 520 546 strncat (fileName, ext, strlen(fileName)); … … 577 603 MoviePlayer * testMC = new MoviePlayer(mat); 578 604 testMC->start(0); 605 606 this->MovieMaterials.push_back(testMC); 579 607 580 608 //Material* tmp = new Material(); … … 605 633 sc = ((unsigned char *)(&lightMapTexture))[i]; 606 634 sc *= 1/255.0; 607 scale = 2.0; 635 636 scale = 1.0f; // Adjust brightness here 637 608 638 if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp; 609 639 scale*=255.0; -
trunk/src/lib/graphics/importer/bsp_file.h
r8186 r8490 18 18 */ 19 19 20 #include <vector> 20 21 class SDL_Surface; 21 22 class BspTreeNode; … … 212 213 213 214 214 215 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 215 216 }; 216 217 -
trunk/src/lib/graphics/importer/bsp_manager.cc
r8186 r8490 39 39 #include "movie_player.h" 40 40 41 #include "cd_engine.h"42 43 41 #include "world_entity.h" 44 42 … … 47 45 48 46 47 49 48 //CREATE_FACTORY( BspManager, CL_BSP_MODEL); 50 49 51 BspManager::BspManager() 52 { 50 BspManager::BspManager(WorldEntity* parent) 51 { 52 53 this->parent = parent; 53 54 /*// open a BSP file 54 55 this->bspFile = new BspFile(); … … 59 60 this->alreadyVisible = new bool [this->bspFile->numFaces]; 60 61 */ 61 CDEngine::getInstance()->setBSPModel(this); 62 62 63 } 63 64 … … 76 77 void BspManager::load(const char* fileName, float scale) 77 78 { 78 //this->setClassID(CL_BSP_MODEL, "BspManager"); 79 // open a BSP file 79 // open a BSP file 80 80 this->bspFile = new BspFile(); 81 81 this->bspFile->scale = scale; … … 85 85 this->alreadyVisible = new bool [this->bspFile->numFaces]; 86 86 87 87 this->outputFraction = 1.0f; 88 88 } 89 89 /* … … 102 102 */ 103 103 104 const void BspManager::tick(float time) 105 { 106 107 if(!this->bspFile->MovieMaterials.empty()) 108 { 109 ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ; 110 while(it != this->bspFile->MovieMaterials.end()) 111 { 112 (*it)->tick(time); 113 it++; 114 } 115 //this->bspFile->MovieMaterials.front()->tick(time ); 116 117 118 } 119 120 } 104 121 const void BspManager::draw() 105 122 { … … 109 126 this->out1 = this->out; 110 127 this->out2 = this->out; 111 if(this->collPlane != NULL) 112 { 113 this->out1.x += this->collPlane->x*5.0; 114 this->out1.y += this->collPlane->y*5.0; 115 this->out1.z += this->collPlane->z*5.0; 116 117 this->out2.x += this->collPlane->x*10.0; 118 this->out2.y += this->collPlane->y*10.0; 119 this->out2.z += this->collPlane->z*10.0; 128 if(this->collPlane != NULL) { 129 this->out1.x += this->collPlane->x*5.0; 130 this->out1.y += this->collPlane->y*5.0; 131 this->out1.z += this->collPlane->z*5.0; 132 133 this->out2.x += this->collPlane->x*10.0; 134 this->out2.y += this->collPlane->y*10.0; 135 this->out2.z += this->collPlane->z*10.0; 120 136 } 121 137 this->drawDebugCube(&this->out1); 122 138 this->drawDebugCube(&this->out2); 139 123 140 */ 141 142 124 143 // Draw Debug Terrain 125 144 /* … … 148 167 149 168 150 // this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor();169 this->viewDir= State::getCamera()->getAbsDirX(); 151 170 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 152 171 … … 157 176 158 177 159 this->cam = State::getCameraTargetNode()->getAbsCoor(); 160 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 178 179 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 180 181 161 182 this->outputStartsOut = true; 162 183 this->outputAllSolid = false; 163 184 this->outputFraction = 1.0f; 164 185 165 this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam);166 167 //if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam);168 169 186 if ( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0 ) //!< if (sizeof(Visdata) == 0) 170 187 { … … 172 189 173 190 174 // Iterate through all Leafs public final double readLEDouble()191 // Iterate through all Leafs 175 192 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) 176 193 { … … 179 196 if(curLeaf.cluster<0) continue; 180 197 181 182 198 /** Do Frustum culling and draw 'em all **/ 183 bool inFrustum = true; 184 185 Vector dir; 186 dir.x = State::getCameraNode()->getAbsDirX().x; 187 dir.y = State::getCameraNode()->getAbsDirX().y; 188 dir.z = State::getCameraNode()->getAbsDirX().z; 199 200 Vector dir = State::getCameraNode()->getAbsDirX(); 201 189 202 float dist = dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z; 190 203 //if(dist < 0) dist = -dist; … … 192 205 const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ; 193 206 194 if(dMins < - 150.0 && dMaxs < -150.0) {207 if(dMins < -300.0 && dMaxs < -300.0) { 195 208 continue; 196 209 } 197 if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000 && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000) {210 if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 2000 && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 2000) { 198 211 continue; 199 212 } … … 206 219 if (f >=0 && !this->isAlreadyVisible(f)) { 207 220 this->alreadyVisible[f] = true; 208 209 221 addFace(f); // "visibleFaces.append(f)" 210 222 } … … 302 314 return; 303 315 } 304 if(curFace.type != 1) return;316 // if(curFace.type != 1) return; 305 317 if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return; 306 318 307 319 if(this->lastTex != curFace.texture) { 308 320 if(this->bspFile->Materials[curFace.texture].animated) { 309 glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR); 310 glEnable(GL_BLEND); 321 // glBlendFunc(GL_ZERO,GL_ONE); 322 323 324 311 325 if(this->bspFile->Materials[curFace.texture].aviMat->getStatus() == 2) this->bspFile->Materials[curFace.texture].aviMat->start(0); 312 this->bspFile->Materials[curFace.texture].aviMat->tick(0.005);326 //this->bspFile->Materials[curFace.texture].aviMat->tick(0.005); 313 327 int n = this->bspFile->Materials[curFace.texture].aviMat->getTexture(); 314 328 glActiveTextureARB(GL_TEXTURE0_ARB); 315 329 glBindTexture(GL_TEXTURE_2D, n ); 316 glDisable(GL_BLEND); 330 this->lastTex = curFace.texture; 331 317 332 } else { 318 333 this->bspFile->Materials[curFace.texture].mat->select(); … … 322 337 323 338 if(curFace.lm_index < 0) { 339 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 324 340 glActiveTextureARB(GL_TEXTURE1_ARB); 325 341 glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap ); 326 342 glEnable(GL_TEXTURE_2D); 327 343 } else { 344 // glEnable(GL_BLEND); 345 //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 346 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 328 347 glActiveTextureARB(GL_TEXTURE1_ARB); 329 348 glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]); 330 349 glEnable(GL_TEXTURE_2D); 350 // glDisable(GL_BLEND); 331 351 } 332 352 … … 573 593 float startFraction = -1.0f; 574 594 float endFraction = 1.0f; 575 bool startsOut = false; 576 bool endsOut = false; 577 578 Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 579 Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 595 bool startsOut = false; 596 bool endsOut = false; 597 598 // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 599 // Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 600 601 for (int i = 0; i < curBrush->n_brushsides; i++) { 602 brushside& curBrushSide = this->bspFile->brushSides[curBrush->brushside + i] ; 603 plane& curPlane = this->bspFile->planes[curBrushSide.plane] ; 604 605 startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d; 606 endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d; 607 608 if (startDistance > 0) 609 startsOut = true; 610 if (endDistance > 0) 611 endsOut = true; 612 613 // make sure the trace isn't completely on one side of the brush 614 if (startDistance > 0 && endDistance > 0) { // both are in front of the plane, its outside of this brush 615 return; 616 } 617 if (startDistance <= 0 && endDistance <= 0) { // both are behind this plane, it will get clipped by another one 618 continue; 619 } 620 621 // MMM... BEEFY 622 if (startDistance > endDistance) { // line is entering into the brush 623 float fraction = (startDistance - EPSILON) / (startDistance - endDistance); // * 624 if (fraction > startFraction) 625 startFraction = fraction; 626 // store plane 627 this->collPlane = &curPlane; 628 629 } else { // line is leaving the brush 630 float fraction = (startDistance + EPSILON) / (startDistance - endDistance); // * 631 if (fraction < endFraction) 632 endFraction = fraction; 633 // store plane 634 this->collPlane = & curPlane; 635 636 } 637 638 } 639 if (startsOut == false) { 640 this->outputStartsOut = false; 641 if (endsOut == false) 642 this->outputAllSolid = true; 643 return; 644 } 645 646 if (startFraction < endFraction) { 647 if (startFraction > -1.0f && startFraction < outputFraction) { 648 if (startFraction < 0) 649 startFraction = 0; 650 this->outputFraction = startFraction; 651 } 652 } 653 654 } 655 656 void BspManager::checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd) 657 { 658 float EPSILON = 0.000001; 659 float startDistance; 660 float endDistance; 661 662 float startFraction = -1.0f; 663 float endFraction = 1.0f; 664 bool startsOut = false; 665 bool endsOut = false; 666 667 //Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 668 //Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 580 669 581 670 for (int i = 0; i < curBrush->n_brushsides; i++) { … … 736 825 737 826 float EPSILON = 0.000001; 738 float endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z) - node->d; 739 float startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d; 740 741 742 if(node->isLeaf) { 827 828 float endDistance = end->dot(node->plane) - node->d; 829 float startDistance = start->dot(node->plane) - node->d; 830 831 832 if( node->isLeaf) { 743 833 leaf& curLeaf = this->bspFile->leaves[node->leafIndex]; 744 834 for (int i = 0; i < curLeaf.n_leafbrushes ; i++) { … … 793 883 794 884 // STEP 3: calculate the middle point for the first side 795 middleFraction = startFraction + 796 (endFraction - startFraction) * fraction1; 797 798 middle.x = start->x + fraction1 * (end->x - start->x); 799 middle.y = start->y + fraction1 * (end->y - start->y); 800 middle.z = start->z + fraction1 * (end->z - start->z); 885 middleFraction = startFraction + (endFraction - startFraction) * fraction1; 886 middle = (*start) + ((*end) - (*start)) * fraction1; 887 801 888 802 889 // STEP 4: check the first side … … 805 892 806 893 else this->checkCollisionRayN(node->right,startFraction, middleFraction, 807 start, &middle );894 start, &middle ); 808 895 809 896 // STEP 5: calculate the middle point for the second side 810 middleFraction = startFraction + 811 (endFraction - startFraction) * fraction2; 812 813 middle.x = start->x + fraction2 * (end->x - start->x); 814 middle.y = start->y + fraction2 * (end->y - start->y); 815 middle.z = start->z + fraction2 * (end->z - start->z); 897 middleFraction = startFraction + (endFraction - startFraction) * fraction2; 898 middle = (*start) + ((*end) - (*start)) * fraction2; 816 899 817 900 // STEP 6: check the second side … … 824 907 825 908 } 909 void BspManager::checkCollisionBox(void) 910 { 911 912 }; 913 914 void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd, 915 Vector& inputMins, Vector& inputMaxs ) 916 { 917 if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 && 918 inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0) 919 { // the user called TraceBox, but this is actually a ray 920 //!> FIXME TraceRay( inputStart, inputEnd ); 921 } 922 else 923 { // setup for a box 924 //traceType = TT_BOX; 925 this->traceMins = inputMins; 926 this->traceMaxs = inputMaxs; 927 this->traceExtents.x = -traceMins.x > traceMaxs.x ? 928 -traceMins.x : traceMaxs.x; 929 this->traceExtents.y = -traceMins.y > traceMaxs.y ? 930 -traceMins.y : traceMaxs.y; 931 this->traceExtents.z = -traceMins.z > traceMaxs.z ? 932 -traceMins.z : traceMaxs.z; 933 //!> FIXME Trace( inputStart, inputEnd ); 934 } 935 } 826 936 827 937 void BspManager::checkCollision(WorldEntity* worldEntity) 828 938 { 829 return; 830 939 940 this->outputStartsOut = true; 941 this->outputAllSolid = false; 942 this->outputFraction = 1.0f; 943 831 944 Vector position = worldEntity->getAbsCoor(); 832 945 833 946 834 947 Vector forwardDir = worldEntity->getAbsDirX(); 835 forwardDir.x =2.0*forwardDir.x; 836 forwardDir.y =2.0*forwardDir.y; 837 forwardDir.z =2.0*forwardDir.z; 948 forwardDir = forwardDir * 8.0f; 838 949 839 950 Vector upDir = worldEntity->getAbsDirY(); 840 Vector dest = position; 951 upDir.x = 0.0; 952 upDir.y = 1.0; 953 upDir.z = 0.0; 954 Vector dest; 955 /* 841 956 dest.x += forwardDir.x; 842 957 dest.y += forwardDir.y; 843 958 dest.z += forwardDir.z; 844 Vector out = Vector(-1875.0,-1875.0,-1875.0); 845 if(!worldEntity->isA(CL_PLAYABLE)) { 846 847 848 849 959 */ 960 961 dest = worldEntity->getAbsCoor() - upDir*40.0; 962 Vector out = dest; 963 964 965 966 967 bool collision = false; 968 Vector position1 = position + Vector(0.0,0.1,0.0); 969 Vector position2 = position + Vector(0.0,0.2,0.0); 970 Vector dest1 = position1 + forwardDir; 971 Vector dest2 = position2 + forwardDir; 972 dest = position - Vector(0.0, 40.0,0.0); 973 Vector out1; 974 Vector out2; 975 976 977 float height = 40; 978 979 this->inputStart = position; 980 this->inputEnd = dest; 981 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 982 983 PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction); 984 PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z); 985 PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 986 // position1.debug(); 987 988 if( this->outputFraction == 1.0f) 989 { 990 if(this->outputAllSolid) 991 { 992 this->collPlane = new plane; 993 this->collPlane->x = 1.0f; 994 this->collPlane->y = 0.0f; 995 this->collPlane->z = 0.0f; 996 collision = true; 997 } 998 else 999 collision = false; 1000 1001 1002 out = dest; 850 1003 } 851 1004 else { 852 bool collision = false; 853 Vector position1 = position + Vector(0.0,0.1,0.0); 854 Vector position2 = position + Vector(0.0,0.2,0.0); 855 Vector dest1 = position1 + forwardDir; 856 Vector dest2 = position2 + forwardDir; 857 dest = position - upDir; 858 Vector out1; 859 Vector out2; 860 861 this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 ); 862 if(this->outputFraction == 1.0f) out1 = dest; 863 else { 864 collision = true; 865 out1.x = position1.x + (dest1.x -position1.x) * this->outputFraction; 866 out1.y = position1.y + (dest1.y -position1.y) * this->outputFraction; 867 out1.z = position1.z + (dest1.z - position1.z) * this->outputFraction; 868 869 } 870 871 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 872 if(this->outputFraction == 1.0f) out2= dest; 873 else 874 { 875 collision = true; 876 out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction; 877 out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction; 878 out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction; 879 880 } 881 882 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 883 if(this->outputFraction == 1.0f) out = dest; 884 else 885 { 1005 886 1006 collision = true; 887 1007 out.x = position.x + (dest.x -position.x) * this->outputFraction; … … 889 1009 out.z = position.z + (dest.z -position.z) * this->outputFraction; 890 1010 891 //Vector out3 = out + Vector(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z); 892 //this->out = out; 893 //this->out1 = out1; 894 //this->out2 = out2; 895 //this->drawDebugCube(&out1); 896 //this->drawDebugCube(&out2); 897 898 //this->drawDebugCube(&out3); 899 900 } 901 902 // Return the normal here: Normal's stored in this->collPlane; 903 // if(collision) worldEntity->collidesWithGround(out,out1,out2); 904 905 } 906 907 } 1011 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 1012 this->out = out; 1013 } 1014 1015 // Return the normal here: Normal's stored in this->collPlane; 1016 if( collision) { 1017 PRINTF(0)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 1018 worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out); 1019 } 1020 1021 } 1022 908 1023 909 1024 void BspManager::checkCollision(BspTreeNode* node, Vector* cam) … … 938 1053 this->drawDebugCube(&this->cam); 939 1054 this->drawDebugCube(&next); 940 State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);941 State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());1055 // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100); 1056 //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor()); 942 1057 } 943 1058 -
trunk/src/lib/graphics/importer/bsp_manager.h
r8186 r8490 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 16 16 Unofficial Quake 3 Map Specs by Kekoa Proudfoot http://graphics.stanford.edu/~kekoa/q3/ 17 17 18 18 Collision detection adapted from: 19 19 Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ 20 20 */ 21 21 22 #ifndef _BSP_MANAGER_H 23 #define _BSP_MANAGER_H 24 25 22 26 #include <vector> 23 27 #include <deque> 28 29 24 30 25 31 // FORWARD DECLARATIONS … … 45 51 public: 46 52 // Constructors 47 BspManager( );48 53 BspManager(WorldEntity* parent); 54 49 55 BspManager(const char* fileName, float scale = 0.4f); 50 56 void load(const char* fileName, float scale); … … 52 58 // Functions 53 59 const void draw(); 54 void draw_debug_face(int Face); 60 const void tick(float time); 61 void draw_debug_face(int Face); 55 62 void draw_face(int Face); 56 63 void draw_patch(face* Face); 57 58 64 59 void checkCollision(WorldEntity* worldEntity); 65 66 void checkCollision(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BspEntity. 67 If a collision has been detected, the collides-function of worldEntity will be called.*/ 60 68 61 69 private: 62 70 // Functions 63 71 BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree 64 void checkCollision(BspTreeNode* node, Vector* cam); 65 void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 66 void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 72 void checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only! 73 void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 74 void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 75 void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs ); 76 void checkCollisionBox(void); 67 77 void checkBrushRay(brush* curBrush); 68 78 void checkBrushRayN(brush* curBrush); 79 void checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd); 80 69 81 void drawDebugCube(Vector* cam); 70 82 bool isAlreadyVisible(int Face); 71 83 void addFace(int Face); 72 84 73 85 // Data 74 86 BspFile* bspFile; … … 79 91 plane* collPlane; 80 92 int lastTex; 81 82 //obsolete 93 94 //obsolete: global variables for collision detection 83 95 bool outputStartsOut; 84 96 bool outputAllSolid; 85 97 float outputFraction; 98 Vector inputStart; 99 Vector inputEnd; 86 100 101 Vector traceMins; //!< Mins of current bbox 102 Vector traceMaxs; //!< Maxs of current bbox 103 Vector traceExtents; /*!< Stores the maximum of the absolute value of each axis in the box. 104 For example, if traceMins was (-100,-3,-15) and traceMaxs was (55,22,7), traceExtents */ 105 106 WorldEntity* parent; //!< the parent entity of the bspManager: interface to this 107 87 108 bool * alreadyVisible; 88 109 // Deques to store the visible faces … … 90 111 ::std::deque<int> opal; //!< the others here. 91 112 92 Vector out; 93 Vector out1; 94 Vector out2; 113 Vector out; //!< For debugging only 114 Vector out1; //!< For debugging only 115 Vector out2; //!< For debugging only 116 117 int tgl; 95 118 }; 96 119 120 #endif /* _BSP_MANAGER_H */ -
trunk/src/lib/graphics/importer/md3/md3_data.cc
r8489 r8490 23 23 #include "material.h" 24 24 25 #include "debug.h" 25 26 26 27 namespace md3
Note: See TracChangeset
for help on using the changeset viewer.