Changeset 7833 in orxonox.OLD for branches/bsp_model
- Timestamp:
- May 24, 2006, 6:41:08 PM (19 years ago)
- Location:
- branches/bsp_model/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/collision_detection/cd_engine.cc
r6316 r7833 29 29 #include "quadtree_node.h" 30 30 31 31 #include "bsp_manager.h" 32 32 33 33 using namespace std; … … 137 137 * this checks the collisions with the ground 138 138 */ 139 void CDEngine::checkCollisionGround( )139 void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1) 140 140 { 141 141 if( likely( this->terrain != NULL)) 142 142 { 143 143 Quadtree* q = dynamic_cast<Terrain*>(this->terrain)->ssp->getQuadtree(); 144 145 144 // QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor()); 146 145 } 147 //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor()); 146 147 if( likely( this->bspManager != NULL)) 148 { 149 std::list<WorldEntity*>::iterator iterator; 150 PRINTF(3)("checking for collisions\n"); 151 152 iterator = list1.begin(); 153 while (iterator != list1.end()) 154 { 155 bspManager->checkCollision(*iterator); 156 iterator++; 157 } 158 } 148 159 } 149 160 -
branches/bsp_model/src/lib/collision_detection/cd_engine.h
r6316 r7833 17 17 class OBBTree; 18 18 class Terrain; 19 class BspManager; 19 20 //class Player; 20 21 … … 50 51 51 52 inline void setTerrain(Terrain* terrain) { this->terrain = terrain; } 53 inline void setBSPModel(BspManager* bspManager) { this->bspManager = bspManager; } 52 54 // inline void setPlayer(Player* player) { this->player = player; } /* only for debug purposes \todo: delete*/ 53 55 … … 56 58 // void checkCollisions(); 57 59 void checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2); 58 60 void checkCollisionGround(std::list<WorldEntity*>& list1); 61 59 62 void drawBV(const std::list<WorldEntity*>& drawList ) const; 60 63 void debug(); … … 68 71 69 72 void checkCollisionObjects(); 70 void checkCollisionGround(); 73 71 74 72 75 void debugSpawnTree(int depth, sVec3D* vertices, int numVertices); … … 79 82 80 83 Terrain* terrain; //!< this it a ref to the terrain, serving as a ground for all WE 84 BspManager* bspManager; 81 85 // Player* player; 82 86 }; -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r7801 r7833 32 32 #include "movie_player.h" 33 33 34 35 34 #include "cd_engine.h" 35 36 #include "world_entity.h" 36 37 37 38 BspManager::BspManager() … … 43 44 this->root = this->bspFile->get_root(); 44 45 this->alreadyVisible = new bool [this->bspFile->numFaces]; 46 47 CDEngine::getInstance()->setBSPModel(this); 45 48 } 46 49 … … 77 80 78 81 79 80 // this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor() ;82 83 // this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor() ; 81 84 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 82 85 … … 88 91 89 92 this->cam = State::getCameraTargetNode()->getAbsCoor(); 90 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection93 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 91 94 this->outputStartsOut = true; 92 95 this->outputAllSolid = false; 93 96 this->outputFraction = 1.0f; 94 97 95 98 this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam); 96 99 97 100 if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam); 98 101 99 102 if ( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0 ) //!< if (sizeof(Visdata) == 0) 100 103 { 101 102 103 104 105 106 104 107 // Iterate through all Leafspublic final double readLEDouble() 105 108 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) … … 108 111 leaf& curLeaf = (this->bspFile->leaves)[i]; 109 112 if(curLeaf.cluster<0) continue; 110 111 113 114 112 115 /** Do Frustum culling and draw 'em all **/ 113 116 bool inFrustum = true; 114 117 115 118 Vector dir; 116 dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;117 dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;118 dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;119 dir.x = State::getCameraNode()->getAbsDirZ().x; 120 dir.y = State::getCameraNode()->getAbsDirZ().y; 121 dir.z = State::getCameraNode()->getAbsDirZ().z; 119 122 float dist = dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z; 120 123 //if(dist < 0) dist = -dist; 121 124 const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist ; 122 125 const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ; 123 124 if(dMins < -30.0 && dMaxs < -30.0) 125 { 126 //continue; 126 127 if(dMins < -1.0 && dMaxs < -1.0) { 128 //continue; 127 129 } 128 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) 129 { 130 //continue; 130 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) { 131 //continue; 131 132 } 132 133 133 134 134 135 // Iterate through all faces 135 136 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) { … … 138 139 if (f >=0 && !this->isAlreadyVisible(f)) { 139 140 this->alreadyVisible[f] = true; 140 141 141 142 addFace(f); // "visibleFaces.append(f)" 142 143 } … … 147 148 148 149 } //for 149 } 150 else { 151 152 150 } else { 151 152 153 153 unsigned int v; 154 154 unsigned char visSet; … … 165 165 visSet =((char*) (this->bspFile->visData))[v + 8]; 166 166 167 // gets bit of visSet 167 // gets bit of visSet 168 168 if( ((visSet) & (1 << (cluster & 7))) != 0 ) { 169 169 170 170 // Frustum culling 171 171 172 172 Vector dir; 173 dir.x = this->cam.x - State::getCameraTargetNode()->getLastAbsCoor().x;174 dir.y = this->cam.y - State::getCameraTargetNode()->getLastAbsCoor().y;175 dir.z = this->cam.z - State::getCameraTargetNode()->getLastAbsCoor().z;173 dir.x = State::getCameraNode()->getAbsDirX().x; 174 dir.y = State::getCameraNode()->getAbsDirX().y; 175 dir.z = State::getCameraNode()->getAbsDirX().z; 176 176 const float dist = dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z; 177 //if(dist < 0) dist = -dist;177 //if(dist < 0) dist = -dist; 178 178 const float dMins = dir.x*(float)curLeaf.mins[0] +dir.y*(float)curLeaf.mins[1] +dir.z*(float)curLeaf.mins[2] - dist; 179 179 const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist; 180 181 if(dMins < -150.0 && dMaxs < -150.0) 182 { 183 continue; 180 181 if(dMins < -30.0 && dMaxs < -30.0) { 182 continue; 184 183 } 185 186 184 185 187 186 // Iterate through all faces 188 187 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) { … … 238 237 239 238 if(this->lastTex != curFace.texture) { 240 if(this->bspFile->Materials[curFace.texture].animated) 241 { 239 if(this->bspFile->Materials[curFace.texture].animated) { 242 240 glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR); 243 241 glEnable(GL_BLEND); … … 248 246 glBindTexture(GL_TEXTURE_2D, n ); 249 247 glDisable(GL_BLEND); 250 } 251 else 252 { 253 this->bspFile->Materials[curFace.texture].mat->select(); 254 this->lastTex = curFace.texture; 248 } else { 249 this->bspFile->Materials[curFace.texture].mat->select(); 250 this->lastTex = curFace.texture; 255 251 } 256 252 } … … 267 263 268 264 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 269 270 // glColor4f(3.0,3.0,3.0,1.0);265 266 // glColor4f(3.0,3.0,3.0,1.0); 271 267 glEnableClientState(GL_VERTEX_ARRAY ); 272 268 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); … … 370 366 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 371 367 for(int i = Face->n_meshverts -1; i >=0 ; i--) { 372 //glFrontFace(GL_CW);368 //glFrontFace(GL_CW); 373 369 //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]); 374 370 … … 382 378 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 383 379 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0])); 384 380 385 381 386 382 … … 390 386 391 387 392 // glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );388 // glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 393 389 394 390 … … 436 432 float startDistance; 437 433 float endDistance; 438 434 439 435 float startFraction = -1.0f; 440 436 float endFraction = 1.0f; 441 437 bool startsOut = false; 442 438 bool endsOut = false; 443 439 444 440 Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 445 441 Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 446 442 447 for (int i = 0; i < curBrush->n_brushsides; i++) 448 { 443 for (int i = 0; i < curBrush->n_brushsides; i++) { 449 444 brushside& curBrushSide = this->bspFile->brushSides[curBrush->brushside + i] ; 450 445 plane& curPlane = this->bspFile->planes[curBrushSide.plane] ; 451 446 452 453 447 startDistance = inputStart.x * curPlane.x + inputStart.y * curPlane.y+ inputStart.z * curPlane.z - curPlane.d; 448 endDistance = inputEnd.x * curPlane.x +inputEnd.y * curPlane.y +inputEnd.z * curPlane.z -curPlane.d; 454 449 455 450 if (startDistance > 0) … … 458 453 endsOut = true; 459 454 460 // make sure the trace isn't completely on one side of the brush 461 if (startDistance > 0 && endDistance > 0) 462 { // both are in front of the plane, its outside of this brush 455 // make sure the trace isn't completely on one side of the brush 456 if (startDistance > 0 && endDistance > 0) { // both are in front of the plane, its outside of this brush 463 457 return; 464 458 } 465 if (startDistance <= 0 && endDistance <= 0) 466 { // both are behind this plane, it will get clipped by another one 459 if (startDistance <= 0 && endDistance <= 0) { // both are behind this plane, it will get clipped by another one 467 460 continue; 468 461 } 469 462 470 // MMM... BEEFY 471 if (startDistance > endDistance) 472 { // line is entering into the brush 463 // MMM... BEEFY 464 if (startDistance > endDistance) { // line is entering into the brush 473 465 float fraction = (startDistance - EPSILON) / (startDistance - endDistance); // * 474 466 if (fraction > startFraction) 475 467 startFraction = fraction; 476 } 477 else 478 { // line is leaving the brush 468 } else { // line is leaving the brush 479 469 float fraction = (startDistance + EPSILON) / (startDistance - endDistance); // * 480 470 if (fraction < endFraction) 481 471 endFraction = fraction; 482 472 } 483 484 } 485 if (startsOut == false) 486 { 487 this->outputStartsOut = false; 488 if (endsOut == false) 489 this->outputAllSolid = true; 490 return; 491 } 492 493 if (startFraction < endFraction) 494 { 495 if (startFraction > -1.0f && startFraction < outputFraction) 496 { 473 474 } 475 if (startsOut == false) { 476 this->outputStartsOut = false; 477 if (endsOut == false) 478 this->outputAllSolid = true; 479 return; 480 } 481 482 if (startFraction < endFraction) { 483 if (startFraction > -1.0f && startFraction < outputFraction) { 497 484 if (startFraction < 0) 498 485 startFraction = 0; … … 500 487 } 501 488 } 502 489 503 490 } 504 491 … … 518 505 //object *brush = &BSP.brushes[BSP.leafBrushes[leaf->firstLeafBrush + i]]; 519 506 if (curBrush.n_brushsides > 0 && 520 ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1))521 // CheckBrush( brush );522 this->checkBrushRay(&curBrush);507 ((((BspTexture*)(this->bspFile->textures))[curBrush.texture]).contents & 1)) 508 // CheckBrush( brush ); 509 this->checkBrushRay(&curBrush); 523 510 if(curBrush.n_brushsides <=0) this->outputAllSolid = true; 524 511 } … … 548 535 fraction2 = (startDistance + EPSILON) * inverseDistance; 549 536 } else if (endDistance < startDistance) { 550 side = 0; // front(start)->x * (node->plane.x)+ 537 side = 0; // front(start)->x * (node->plane.x)+ 551 538 float inverseDistance = 1.0f / (startDistance - endDistance); 552 539 fraction1 = (startDistance + EPSILON) * inverseDistance; … … 596 583 597 584 } 585 586 587 void BspManager::checkCollision(WorldEntity* worldEntity) 588 { 589 590 Vector position = worldEntity->getAbsCoor(); 591 592 593 Vector forwardDir = worldEntity->getAbsDirX(); 594 forwardDir.x =10*forwardDir.x; 595 forwardDir.y =10*forwardDir.y; 596 forwardDir.z =10*forwardDir.z; 597 598 Vector upDir = worldEntity->getAbsDirY(); 599 Vector dest = position; 600 dest.x += forwardDir.x; 601 dest.y += forwardDir.y; 602 dest.z += forwardDir.z; 603 Vector out = Vector(-1875.0,-1875.0,-1875.0); 604 if(!worldEntity->isA(CL_PLAYABLE)) { 605 } 606 else { 607 bool collision = false; 608 Vector position1 = position + Vector(0.0,0.1,0.0); 609 Vector position2 = position + Vector(0.0,0.2,0.0); 610 Vector dest1 = position1 + forwardDir; 611 Vector dest2 = position2 + forwardDir; 612 dest = position - upDir; 613 Vector out1; 614 Vector out2; 615 616 this->checkCollisionRay(this->root,0.0f,1.0f, &position1, &dest1 ); 617 if(this->outputFraction == 1.0f) out1 = dest; 618 else { 619 collision = true; 620 out1.x = position1.x + (dest1.x -position1.x) * this->outputFraction; 621 out1.y = position1.y + (dest1.y -position1.y) * this->outputFraction; 622 out1.z = position1.z + (dest1.z - position1.z) * this->outputFraction; 623 624 } 625 626 this->checkCollisionRay(this->root,0.0f,1.0f, &position2, &dest2 ); 627 if(this->outputFraction == 1.0f) out2= dest; 628 else 629 { 630 collision = true; 631 out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction; 632 out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction; 633 out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction; 634 635 } 636 637 this->checkCollisionRay(this->root,0.0f,1.0f, &position, &dest ); 638 if(this->outputFraction == 1.0f) out = dest; 639 else 640 { 641 collision = true; 642 out.x = position.x + (dest.x -position.x) * this->outputFraction; 643 out.y = position.y + (dest.y -position.y) * this->outputFraction; 644 out.z = position.z + (dest.z -position.z) * this->outputFraction; 645 646 } 647 648 if(collision) worldEntity->collidesWithGround(out,out1,out2); 649 650 } 651 652 } 653 598 654 void BspManager::checkCollision(BspTreeNode* node, Vector* cam) 599 655 { … … 625 681 626 682 if (camLeaf.cluster < 0) { 627 this->drawDebugCube(&this->cam);628 629 630 631 683 this->drawDebugCube(&this->cam); 684 this->drawDebugCube(&next); 685 State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100); 686 State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor()); 687 } 632 688 633 689 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
r7563 r7833 25 25 struct face; 26 26 struct brush; 27 class WorldEntity; 27 28 28 29 class BspManager … … 38 39 void draw_patch(face* Face); 39 40 41 void checkCollision(WorldEntity* worldEntity); 40 42 41 43 private: -
branches/bsp_model/src/story_entities/game_world.cc
r7339 r7833 418 418 this->dataTank->objectManager->getObjectList(OM_COMMON)); 419 419 420 421 CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_00)); 422 CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_01)); 423 420 424 } 421 425 -
branches/bsp_model/src/world_entities/world_entity.cc
r7230 r7833 275 275 276 276 /** 277 * this function is called, when two entities collide 278 * @param entity: the world entity with whom it collides 279 * 280 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 281 */ 282 void WorldEntity::collidesWithGround(const Vector& location) 283 { 284 PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassName() ); 285 } 286 287 void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2) 288 { 289 290 PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() ); 291 Vector v = this->getAbsDirX(); 292 v.x *= 10; 293 v.y *= 10; 294 v.z *= 10; 295 this->setAbsCoor(ray_2 - v); 296 } 297 298 /** 277 299 * this is called immediately after the Entity has been constructed, initialized and then Spawned into the World 278 300 * -
branches/bsp_model/src/world_entities/world_entity.h
r7221 r7833 62 62 63 63 virtual void collidesWith (WorldEntity* entity, const Vector& location); 64 virtual void collidesWithGround(const Vector& location); 65 virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2); 64 66 void drawBVTree(unsigned int depth, int drawMode) const; 65 67
Note: See TracChangeset
for help on using the changeset viewer.