Changeset 7563 in orxonox.OLD for branches/bsp_model/src/lib/graphics
- Timestamp:
- May 10, 2006, 12:54:38 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/bsp_file.h
r7511 r7563 62 62 leaf; 63 63 64 typedef struct 64 struct brush 65 65 { 66 66 int brushside; //!< First brushside for brush. 67 67 int n_brushsides; //!< Number of brushsides for brush. 68 68 int texture; //!< Texture index. 69 } 70 brush; 69 }; 71 70 72 71 typedef struct … … 128 127 } 129 128 lightmap; 129 130 typedef struct 131 { 132 char name[64]; 133 int flags; 134 int contents; 135 } 136 BspTexture; 130 137 131 138 class BspFile … … 182 189 int numLightMaps; 183 190 191 192 184 193 BspTreeNode* build_tree_rec( int i ); 185 194 unsigned int loadLightMapToGL(lightmap&); -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r7544 r7563 74 74 75 75 76 this->cam = State::getCameraTargetNode()->getAbsCoor();76 77 77 this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor() ; 78 78 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); … … 84 84 85 85 86 87 this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 88 89 if (true /*(((int *)(this->bspFile->header))[35] == 0 ) || viscluster < 0*/) //!< if (sizeof(Visdata) == 0) 86 this->cam = State::getCameraTargetNode()->getAbsCoor(); 87 //this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 88 this->outputStartsOut = true; 89 this->outputAllSolid = false; 90 this->outputFraction = 1.0f; 91 92 this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam); 93 94 if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam); 95 96 if (true || (((int *)(this->bspFile->header))[35] == 0 ) || viscluster < 0) //!< if (sizeof(Visdata) == 0) 90 97 { 91 /** Do Frustum culling and draw 'em all **/ 92 98 99 100 93 101 // Iterate through all Leafspublic final double readLEDouble() 94 102 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) … … 96 104 // cluster = (this->bspFile->leaves)[i].cluster; 97 105 leaf& curLeaf = (this->bspFile->leaves)[i]; 98 99 106 if(curLeaf.cluster<0) continue; 107 108 109 /** Do Frustum culling and draw 'em all **/ 110 bool inFrustum = true; 111 float dMins; 112 float dMaxs; 113 Vector dir; 114 dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x; 115 dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y; 116 dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z; 117 float dist = dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z; 118 //if(dist < 0) dist = -dist; 119 dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] ; 120 dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] ; 121 122 if(dMins < 0.0 && dMaxs < 0.0) 123 { 124 //continue; 125 } 126 127 100 128 // Iterate through all faces 101 129 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) { … … 103 131 if (f >=0 && !this->isAlreadyVisible(f)) { 104 132 this->alreadyVisible[f] = true; 105 /* if(ActLeaf->leafIndex == i)public final double readLEDouble() 106 { 107 this->alreadyVisible[i] = false; 108 this->draw_debug_face(f); 109 this->alreadyVisible[i] = true; 110 } 111 else */ 133 112 134 addFace(f); // "visibleFaces.append(f)" 113 135 } … … 131 153 leaf& curLeaf = (this->bspFile->leaves)[i] ; 132 154 cluster = curLeaf.cluster; 133 134 if(cluster < 0) continue;155 156 if(cluster < 0) continue; 135 157 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8)); 136 visSet =((unsigned char*) (this->bspFile->visData))[v+8]; 137 138 139 if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) == 0 ) 140 { 158 visSet =((unsigned char*) (this->bspFile->visData))[v + 8]; 159 160 161 if( !((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) ) { 141 162 // Iterate through all faces 142 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) 143 { 163 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) { 144 164 const int f = (j + curLeaf.leafface) % this->bspFile->numFaces; 145 165 … … 152 172 } 153 173 154 }// if174 }// if 155 175 156 176 }//for … … 170 190 }//draw 171 191 172 void BspManager::draw_leaf() 173 {} 192 174 193 175 194 void BspManager::draw_face(int curface) … … 189 208 } 190 209 if(curFace.type == 3) return; 191 // if(this->bspFile->Materials[curFace.texture] != NULL)192 210 // if(this->bspFile->Materials[curFace.texture] != NULL) 211 193 212 if(this->lastTex != curFace.texture) { 194 213 this->bspFile->Materials[curFace.texture].mat->select(); 195 this->lastTex = curFace.texture; 196 } 197 198 if(curFace.lm_index < 0) 199 { 200 glActiveTextureARB(GL_TEXTURE1_ARB); 201 glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap ); 202 glEnable(GL_TEXTURE_2D); 203 } 204 else 205 { 214 this->lastTex = curFace.texture; 215 } 216 217 if(curFace.lm_index < 0) { 218 glActiveTextureARB(GL_TEXTURE1_ARB); 219 glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap ); 220 glEnable(GL_TEXTURE_2D); 221 } else { 206 222 glActiveTextureARB(GL_TEXTURE1_ARB); 207 223 glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]); 208 224 glEnable(GL_TEXTURE_2D); 209 210 211 225 } 226 227 glColor4f(3.0,3.0,3.0,1.0); 212 228 glEnableClientState(GL_VERTEX_ARRAY ); 213 229 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 214 230 glEnableClientState(GL_NORMAL_ARRAY ); 215 231 // glEnableClientState(GL_COLOR_ARRAY); 216 232 217 233 218 234 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 219 235 220 236 glClientActiveTextureARB(GL_TEXTURE0_ARB); 221 237 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0])); 222 238 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 223 239 224 240 glClientActiveTextureARB(GL_TEXTURE1_ARB); 225 241 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1])); 226 242 //glEnableClientState(GL_TEXTURE_COORD_ARRAY); 227 243 228 244 229 245 glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0])); 230 246 // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0])); … … 292 308 this->lastTex = Face->texture; 293 309 } 294 295 296 297 if(Face->lm_index < 0) 298 { 310 311 312 313 if(Face->lm_index < 0) { 299 314 glActiveTextureARB(GL_TEXTURE1_ARB); 300 315 glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap); 301 316 glEnable(GL_TEXTURE_2D); 302 } 303 else 304 { 317 } else { 305 318 glActiveTextureARB(GL_TEXTURE1_ARB); 306 319 glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[Face->lm_index]); 307 320 glEnable(GL_TEXTURE_2D); 308 }309 310 311 glEnable( GL_AUTO_NORMAL);321 } 322 glColor4f(3.0,3.0,3.0,1.0); 323 324 //glEnable( GL_AUTO_NORMAL); 312 325 glEnableClientState(GL_VERTEX_ARRAY ); 313 326 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); … … 315 328 glFrontFace(GL_CW); 316 329 //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]); 317 318 330 331 319 332 glEnableClientState(GL_NORMAL_ARRAY ); 320 333 321 334 glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0])); 322 323 335 336 324 337 glClientActiveTextureARB(GL_TEXTURE0_ARB); 325 338 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0])); 326 339 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 327 340 328 341 329 342 glClientActiveTextureARB(GL_TEXTURE1_ARB); 330 343 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0])); 331 344 //glEnableClientState(GL_TEXTURE_COORD_ARRAY); 332 345 333 346 334 347 glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 335 348 336 349 337 350 338 351 … … 341 354 & ( (((GLuint*) (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8] )) ); 342 355 } 343 356 344 357 glFrontFace(GL_CCW); 345 358 } 346 359 glDisableClientState(GL_TEXTURE0_ARB); 347 360 glDisableClientState(GL_TEXTURE1_ARB); 348 glDisable(GL_AUTO_NORMAL);361 //glDisable(GL_AUTO_NORMAL); 349 362 glDisableClientState(GL_VERTEX_ARRAY ); 350 363 glDisableClientState(GL_TEXTURE_COORD_ARRAY ); 351 364 352 365 glBegin(GL_QUADS); 353 366 354 367 glEnd(); 355 368 } … … 376 389 } 377 390 391 void BspManager::checkBrushRay(brush* curBrush) 392 { 393 float EPSILON = 0.000001; 394 float startDistance; 395 float endDistance; 396 397 float startFraction = -1.0f; 398 float endFraction = 1.0f; 399 bool startsOut = false; 400 bool endsOut = false; 401 402 Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 403 Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 404 405 for (int i = 0; i < curBrush->n_brushsides; i++) 406 { 407 brushside& curBrushSide = this->bspFile->brushSides[curBrush->brushside + i] ; 408 plane& curPlane = this->bspFile->planes[curBrushSide.plane] ; 409 410 startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d; 411 endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d; 412 413 if (startDistance > 0) 414 startsOut = true; 415 if (endDistance > 0) 416 endsOut = true; 417 418 // make sure the trace isn't completely on one side of the brush 419 if (startDistance > 0 && endDistance > 0) 420 { // both are in front of the plane, its outside of this brush 421 return; 422 } 423 if (startDistance <= 0 && endDistance <= 0) 424 { // both are behind this plane, it will get clipped by another one 425 continue; 426 } 427 428 // MMM... BEEFY 429 if (startDistance > endDistance) 430 { // line is entering into the brush 431 float fraction = (startDistance - EPSILON) / (startDistance - endDistance); // * 432 if (fraction > startFraction) 433 startFraction = fraction; 434 } 435 else 436 { // line is leaving the brush 437 float fraction = (startDistance + EPSILON) / (startDistance - endDistance); // * 438 if (fraction < endFraction) 439 endFraction = fraction; 440 } 441 442 } 443 if (startsOut == false) 444 { 445 this->outputStartsOut = false; 446 if (endsOut == false) 447 this->outputAllSolid = true; 448 return; 449 } 450 451 if (startFraction < endFraction) 452 { 453 if (startFraction > -1.0f && startFraction < outputFraction) 454 { 455 if (startFraction < 0) 456 startFraction = 0; 457 this->outputFraction = startFraction; 458 } 459 } 460 461 } 462 463 void BspManager::checkCollisionRay(BspTreeNode* node, float startFraction, float endFraction, Vector* start, Vector* end) 464 { 465 466 467 float EPSILON = 0.000001; 468 float endDistance = (end)->x * (node->plane.x) +(end)->y * (node->plane.y) +(end)->z * (node->plane.z) - node->d; 469 float startDistance = (start)->x * (node->plane.x)+ (start)->y * (node->plane.y)+ (start)->z * (node->plane.z)- node->d; 470 471 472 if(node->isLeaf) { 473 leaf& curLeaf = this->bspFile->leaves[node->leafIndex]; 474 for (int i = 0; i < curLeaf.n_leafbrushes ; i++) { 475 brush& curBrush = this->bspFile->brushes[((int*)(this->bspFile->leafBrushes))[curLeaf.leafbrush_first+i]]; 476 //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]]; 477 if (curBrush.n_brushsides > 0 && 478 ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1)) 479 // CheckBrush( brush ); 480 this->checkBrushRay(&curBrush); 481 if(curBrush.n_brushsides <=0) this->outputAllSolid = true; 482 } 483 return; 484 } 485 486 487 if (startDistance >= 0 && endDistance >= 0) // A 488 { // both points are in front of the plane 489 // so check the front child 490 this->checkCollisionRay(node->left,0,0,start,end); 491 } else if (startDistance < 0 && endDistance < 0) // B 492 { // both points are behind the plane 493 // so check the back child 494 this->checkCollisionRay(node->right,0,0,start,end); 495 } else // C 496 { // the line spans the splitting plane 497 int side; 498 float fraction1, fraction2, middleFraction; 499 Vector middle; 500 501 // STEP 1: split the segment into two 502 if (startDistance < endDistance) { 503 side = 1; // back 504 float inverseDistance = 1.0f / (startDistance - endDistance); 505 fraction1 = (startDistance + EPSILON) * inverseDistance; 506 fraction2 = (startDistance + EPSILON) * inverseDistance; 507 } else if (endDistance < startDistance) { 508 side = 0; // front(start)->x * (node->plane.x)+ 509 float inverseDistance = 1.0f / (startDistance - endDistance); 510 fraction1 = (startDistance + EPSILON) * inverseDistance; 511 fraction2 = (startDistance - EPSILON) * inverseDistance; 512 } else { 513 side = 0; // front 514 fraction1 = 1.0f; 515 fraction2 = 0.0f; 516 } 517 518 // STEP 2: make sure the numbers are valid 519 if (fraction1 < 0.0f) fraction1 = 0.0f; 520 else if (fraction1 > 1.0f) fraction1 = 1.0f; 521 if (fraction2 < 0.0f) fraction2 = 0.0f; 522 else if (fraction2 > 1.0f) fraction2 = 1.0f; 523 524 // STEP 3: calculate the middle point for the first side 525 middleFraction = startFraction + 526 (endFraction - startFraction) * fraction1; 527 528 middle.x = start->x + fraction1 * (end->x - start->x); 529 middle.y = start->y + fraction1 * (end->y - start->y); 530 middle.z = start->z + fraction1 * (end->z - start->z); 531 532 // STEP 4: check the first side 533 //CheckNode( node->children[side], startFraction, middleFraction, start, middle ); 534 if(side == 0) this->checkCollisionRay(node->left,startFraction, middleFraction, start, &middle ); 535 536 else this->checkCollisionRay(node->right,startFraction, middleFraction, 537 start, &middle ); 538 539 // STEP 5: calculate the middle point for the second side 540 middleFraction = startFraction + 541 (endFraction - startFraction) * fraction2; 542 543 middle.x = start->x + fraction2 * (end->x - start->x); 544 middle.y = start->y + fraction2 * (end->y - start->y); 545 middle.z = start->z + fraction2 * (end->z - start->z); 546 547 // STEP 6: check the second side 548 if(side == 1)this->checkCollisionRay(node->left,middleFraction, endFraction, &middle, end); 549 550 else this->checkCollisionRay(node->right,middleFraction, endFraction,&middle, end ); 551 552 553 } 554 555 } 378 556 void BspManager::checkCollision(BspTreeNode* node, Vector* cam) 379 557 { 558 Vector next = this->cam; 559 next.x = (State::getCameraTargetNode()->getLastAbsCoor()).x ; 560 next.y = (State::getCameraTargetNode()->getLastAbsCoor()).y ; 561 next.z = (State::getCameraTargetNode()->getLastAbsCoor()).z ; 562 380 563 float dist = 0; 381 564 if(!(node->isLeaf)) { … … 399 582 leaf& camLeaf = ((leaf *)(this->bspFile->leaves))[(node->leafIndex ) ]; 400 583 401 if (camLeaf.cluster < 0) {this->drawDebugCube(&this->cam); }584 if (camLeaf.cluster < 0) {this->drawDebugCube(&this->cam); this->drawDebugCube(&next);} 402 585 403 586 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
r7395 r7563 17 17 18 18 19 // FORWARD DECLARATION 19 // FORWARD DECLARATIONS 20 20 class BspFile; 21 21 class BspTreeLeaf; … … 24 24 class set; 25 25 struct face; 26 struct brush; 26 27 27 28 class BspManager … … 33 34 // Functions 34 35 void draw(); 35 void draw_leaf(); 36 void draw_debug_face(int Face); 36 void draw_debug_face(int Face); 37 37 void draw_face(int Face); 38 38 void draw_patch(face* Face); … … 41 41 private: 42 42 // Functions 43 BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree 44 void checkCollision(BspTreeNode* node, Vector* cam); 45 void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 46 void checkBrushRay(brush* curBrush); 47 void drawDebugCube(Vector* cam); 48 bool isAlreadyVisible(int Face); 49 void addFace(int Face); 50 51 // Data 43 52 BspFile* bspFile; 44 53 BspTreeNode* root; 45 BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree46 void checkCollision(BspTreeNode* node, Vector* cam);47 void drawDebugCube(Vector* cam);48 54 Vector cam; 49 55 Vector ship; 50 56 Vector viewDir; 57 int lastTex; 58 59 //obsolete 60 bool outputStartsOut; 61 bool outputAllSolid; 62 float outputFraction; 63 51 64 bool * alreadyVisible; 52 bool isAlreadyVisible(int Face);53 void addFace(int Face);54 int lastTex;55 56 57 65 // Deques to store the visible faces 58 66 ::std::deque<int> trasparent; //!< the ones with transparancy go here
Note: See TracChangeset
for help on using the changeset viewer.