Changeset 9003 in orxonox.OLD for trunk/src/lib/graphics/importer/bsp_manager.cc
- Timestamp:
- Jul 2, 2006, 1:36:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/bsp_manager.cc
r8894 r9003 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/ … … 69 69 BspManager::BspManager(const TiXmlElement* root) 70 70 { 71 72 71 72 73 73 if( root != NULL) 74 74 this->loadParams(root); 75 75 76 76 CDEngine::getInstance()->setBSPModel(this); 77 77 } */ 78 78 79 void BspManager::load(const char* fileName, float scale) 79 BspManager::~BspManager() 80 { 81 if(this->bspFile) 82 delete this->bspFile; 83 } 84 85 int BspManager::load(const char* fileName, float scale) 80 86 { 81 87 // open a BSP file 88 89 82 90 this->bspFile = new BspFile(); 83 91 this->bspFile->scale = scale; 84 this->bspFile->read(ResourceManager::getFullName(fileName).c_str()); 92 if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1) 93 return -1; 94 85 95 this->bspFile->build_tree(); 86 96 this->root = this->bspFile->get_root(); … … 88 98 89 99 this->outputFraction = 1.0f; 100 101 return 0; 90 102 } 91 103 /* … … 99 111 this->root = this->bspFile->get_root(); 100 112 this->alreadyVisible = new bool [this->bspFile->numFaces]; 101 113 102 114 CDEngine::getInstance()->setBSPModel(this); 103 115 } … … 962 974 Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; // 963 975 Vector dest1 = position + forwardDir*4.0f; 964 Vector dest2 = position2 + forwardDir ;976 Vector dest2 = position2 + forwardDir*4.0; 965 977 dest = position - Vector(0.0, 40.0,0.0); 966 978 Vector out = dest; … … 974 986 975 987 if( box != NULL) { 976 position = worldEntity->getAbsCoor() + box->center; // + box->axis[1] * box->halfLength[1]; 977 dest = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1] * 40.0; 978 979 position1 = worldEntity->getAbsCoor() + box->center + box->axis[0] * box->halfLength[0] * 2.0f; 980 dest1 = worldEntity->getAbsCoor() + box->center - box->axis[0] * box->halfLength[0] *2.0f; 981 982 983 position2 = worldEntity->getAbsCoor() + box->center + box->axis[2] * box->halfLength[2] * 2.0f; 984 dest2 = worldEntity->getAbsCoor() + box->center - box->axis[2] * box->halfLength[2] * 2.0f; 988 position = worldEntity->getAbsCoor() + box->center + Vector(0.0, 1.0, 0.0) * box->halfLength[1]; 989 dest = worldEntity->getAbsCoor() + box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET); 990 991 position1 = worldEntity->getAbsCoor() + box->center - worldEntity->getAbsDirX() * (box->halfLength[0] + BSP_X_OFFSET); 992 dest1 = worldEntity->getAbsCoor() + box->center + worldEntity->getAbsDirX() * (box->halfLength[0] + BSP_X_OFFSET); 993 994 position2 = worldEntity->getAbsCoor() + box->center - worldEntity->getAbsDirZ() * (box->halfLength[2] + BSP_Z_OFFSET); 995 dest2 = worldEntity->getAbsCoor() + box->center + worldEntity->getAbsDirZ() * (box->halfLength[2] + BSP_Z_OFFSET); 985 996 986 997 } else { … … 989 1000 } 990 1001 1002 1003 // PRINTF(0)("x and v\n"); 1004 // worldEntity->getAbsDirX().debug(); 1005 // worldEntity->getAbsDirV().debug(); 991 1006 992 1007 … … 1035 1050 plane* testPlane = this->collPlane; 1036 1051 1037 1038 1052 bool xCollision = false; 1039 1053 bool zCollision = false; 1040 if(!SolidFlag) { 1054 1041 1055 1042 1056 // 2nd Collision Detection … … 1048 1062 this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 ); 1049 1063 1050 if( !this->outputAllSolid !=1.0f) {1064 if(this->outputFraction < 1.0f) { 1051 1065 out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction; 1066 dest1 = position1 + (dest1 -position1) * this->outputFraction; 1052 1067 xCollision = true; 1053 1068 testPlane = this->collPlane; 1054 1069 } 1055 if(this->outputAllSolid) { 1070 if(this->outputAllSolid ) { 1071 1072 this->collPlane = new plane; 1073 this->collPlane->x = 0.0f; 1074 this->collPlane->y = 0.0f; 1075 this->collPlane->z = 0.0f; 1076 testPlane = this->collPlane; 1056 1077 SolidFlag = true; 1057 xCollision = true; 1078 xCollision = true; 1058 1079 } 1059 1080 //out.z = this->outputFraction; 1060 1081 1061 if(!SolidFlag) { 1082 1062 1083 1063 1084 // 3rd Collision Detection … … 1067 1088 this->inputStart = position2; 1068 1089 this->inputEnd = dest2; 1090 1069 1091 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 1070 1092 //out.x = this->outputFraction; 1071 1093 1072 if(this->outputFraction !=1.0f ) {1094 if(this->outputFraction < 1.0f ) { 1073 1095 out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction; 1096 dest2 = position2 + (dest2 -position2) * this->outputFraction; 1074 1097 zCollision = true; 1075 1098 testPlane = this->collPlane; 1076 1099 1077 1100 } 1078 if(this->outputAllSolid) { 1079 SolidFlag = true; 1080 zCollision = true; 1101 if(this->outputAllSolid ) { 1102 this->collPlane = new plane; 1103 this->collPlane->x = 0.0f; 1104 this->collPlane->y = 0.0f; 1105 this->collPlane->z = 0.0f; 1106 testPlane = this->collPlane; 1107 1108 SolidFlag = true; 1109 zCollision = true; 1081 1110 } 1082 } 1083 }//end if1111 1112 //end if 1084 1113 /* 1085 1114 This is how you would calculate the Coordinates where worldEntity Collided with the BSP world. … … 1091 1120 // Return the normal here: Normal's stored in this->collPlane; 1092 1121 if( collision) { 1093 PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 1094 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y || (xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0), this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1095 } else { 1096 if(xCollision || zCollision) { 1097 1098 worldEntity->registerCollision((xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0) , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1099 } 1100 1101 } 1122 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1123 } 1124 if(xCollision) { 1125 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag); 1126 } 1127 if(zCollision) { 1128 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag); 1129 } 1130 1131 1102 1132 //else worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false); 1103 1133
Note: See TracChangeset
for help on using the changeset viewer.