Changeset 10355 in orxonox.OLD for branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.cc
- Timestamp:
- Jan 24, 2007, 8:48:26 PM (18 years ago)
- Location:
- branches/ODE
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.cc
r10076 r10355 49 49 #include "collision_tube.h" 50 50 51 #ifdef WITH_ODE 52 #include<ode/ode.h> 53 #endif 51 54 52 55 //CREATE_FACTORY( BspManager, CL_BSP_MODEL); … … 88 91 int BspManager::load(const char* fileName, float scale) 89 92 { 93 #ifdef WITH_ODE 94 this->world = dWorldCreate(); 95 space = dSimpleSpaceCreate(0); 96 97 //!fixme 98 for (int i=0; i<30; i++) { 99 contact[i].surface.mode = dContactBounce | dContactSoftCFM; 100 contact[i].surface.mu = dInfinity; 101 contact[i].surface.mu2 = 0; 102 contact[i].surface.bounce = 0.1; 103 contact[i].surface.bounce_vel = 0.1; 104 contact[i].surface.soft_cfm = 0.01; 105 } 106 #endif 90 107 // open a BSP file 108 91 109 92 110 … … 101 119 102 120 this->outputFraction = 1.0f; 121 122 123 #ifdef WITH_ODE 124 125 contactgroup = dJointGroupCreate (0); 126 dWorldSetGravity (world,0,0,-0.5); 127 dWorldSetCFM (world,1e-5); 128 this->ODE_Geom_IDs = new dGeomID[this->bspFile->numPatches* 7 *7]; 129 130 for( int i = 0 ; i < (this->bspFile->numPatches ); i++ ) 131 { 132 this->ODE_Geom_IDs[i] = dCreateTriMesh(space,(this->bspFile->getODE_Geometry())[i],0 , 0, 0); 133 134 } 135 136 #endif 137 103 138 104 139 return 0; … … 124 159 { 125 160 126 if( !this->bspFile->MovieMaterials.empty()) {161 if(unlikely(!this->bspFile->MovieMaterials.empty())) { 127 162 ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ; 128 163 while(it != this->bspFile->MovieMaterials.end()) { … … 138 173 const void BspManager::draw() 139 174 { 175 176 // Remove lines below 177 //glShadeModel( GL_SMOOTH ); // Enable Smooth Shading 178 //glColor( 0.0f, 0.0f, 0.0f, 0.5f ); // Black Background 179 //glClearDepth( 1.0f ); // Depth Buffer Setup 180 //glClearStencil( 0 ); // Stencil Buffer Setup 181 //glEnable( GL_DEPTH_TEST ); // Enables Depth Testing 182 //glDepthFunc( GL_LEQUAL ); 140 183 141 184 /* … … 171 214 this->lastTex = -1; 172 215 // erase alreadyVisible 173 for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false;216 // for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false; 174 217 float tmp = 0; 175 218 //this->opal.clear(); … … 184 227 185 228 186 this->viewDir= State::getCamera()->getAbsDirX();187 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z);229 // this->viewDir= State::getCamera()->getAbsDirX(); 230 // float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 188 231 189 232 BspTreeNode* ActLeaf = this->getLeaf(this->bspFile->root, &ship); … … 197 240 198 241 199 this->outputStartsOut = true; 200 this->outputAllSolid = false; 201 this->outputFraction = 1.0f; 202 203 if ( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0 ) //!< if (sizeof(Visdata) == 0) 204 { 205 206 242 //this->outputStartsOut = true; 243 //this->outputAllSolid = false; 244 //this->outputFraction = 1.0f; 245 246 if (unlikely( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0) ) //!< if (sizeof(Visdata) == 0) 247 { 207 248 208 249 // Iterate through all Leafs … … 258 299 259 300 if(cluster < 0) continue; 260 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8));301 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster >> 3)); 261 302 visSet =((char*) (this->bspFile->visData))[v + 8]; 262 303 263 304 // gets bit of visSet 264 if( ((visSet) & (1 << (cluster & 7))) != 0) {305 if( ((visSet) & (1 << (cluster & 7))) /* != 0 */) { 265 306 266 307 // Frustum culling … … 275 316 const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist; 276 317 277 if(dMins < - 70.0 && dMaxs < -70.0) {318 if(dMins < -0.0 && dMaxs < -0.0) { 278 319 continue; 279 320 } … … 299 340 300 341 while(!this->opal.empty()) { 342 343 301 344 this->draw_face(this->opal.front()); 345 this->alreadyVisible[(int)(this->opal.front())] = false; 302 346 this->opal.pop_front(); 303 347 } 304 348 while(!this->trasparent.empty()) { 305 349 this->draw_face(this->trasparent.back()); 350 this->alreadyVisible[(int)(this->trasparent.back())] = false; 306 351 this->trasparent.pop_back(); 307 352 } … … 319 364 { 320 365 face& curFace = (this->bspFile->faces)[curface]; 366 if (unlikely(curFace.effect != -1)) return; 321 367 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice; 322 int stride = sizeof(BspVertex); // sizeof(Vertex)368 const int stride = sizeof(BspVertex); // sizeof(Vertex) 323 369 int offset = curFace.vertex; 324 if (curFace.effect != -1) return;370 325 371 // PRINTF(0)("BSP Manager: "); 326 372 // PRINTF(0)("BSP Manager: type: %i \n", curFace.texture); … … 353 399 } 354 400 355 if( curFace.lm_index < 0) {401 if(unlikely(curFace.lm_index < 0)) { 356 402 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 357 403 glActiveTextureARB(GL_TEXTURE1_ARB); … … 375 421 glEnableClientState(GL_NORMAL_ARRAY ); 376 422 // glEnableClientState(GL_COLOR_ARRAY); 423 424 //TUTU 425 //glShadeModel( GL_SMOOTH ); // Enable Smooth Shading 426 // glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); // Black Background 427 // glClearDepth( 1.0f ); // Depth Buffer Setup 428 // glClearStencil( 0 ); // Stencil Buffer Setup 429 // glEnable( GL_DEPTH_TEST ); // Enables Depth Testing 430 // glDepthFunc( GL_LEQUAL ); 431 //TUTU 377 432 378 433 … … 449 504 void BspManager::draw_patch(face* Face) 450 505 { 506 if (Face->effect != -1) return; 451 507 if(this->lastTex != Face->texture) { 452 508 this->bspFile->Materials[Face->texture].mat->select(); 453 509 this->lastTex = Face->texture; 454 510 } 455 if (Face->effect != -1) return;456 457 458 if( Face->lm_index < 0) {511 512 513 514 if(unlikely(Face->lm_index < 0)) { 459 515 glActiveTextureARB(GL_TEXTURE1_ARB); 460 516 glBindTexture(GL_TEXTURE_2D, this->bspFile->whiteLightMap); … … 960 1016 { 961 1017 1018 962 1019 // Init Collision Detection 963 1020 this->outputStartsOut = true; … … 969 1026 this->checkCollisionY(worldEntity); 970 1027 this->checkCollisionZ(worldEntity); 1028 1029 1030 #ifdef WITH_ODE 1031 // Create the World-Entities BBOX 1032 AABB* box = worldEntity->getModelAABB(); 1033 dReal aabbox [6]; 1034 1035 1036 if( box != NULL) 1037 { 1038 1039 1040 //PRINTF(0)(" BOX NOT NULL ........... \n"); 1041 1042 dGeomID RayX = dCreateRay(this->space,box->halfLength[0] *2.0f); 1043 dGeomRaySet (RayX, worldEntity->getAbsCoor().x - box->halfLength[0] ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1044 1.0f, 0.0f, 0.0f); 1045 dGeomID RayY = dCreateRay(space,box->halfLength[1] *2.0f); 1046 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y - box->halfLength[1], worldEntity->getAbsCoor().z, 1047 0.0f, 1.0f, 0.0f); 1048 dGeomID RayZ = dCreateRay(space,box->halfLength[2] *2.0f); 1049 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2], 1050 0.0f, 0.0f, 1.0f); 1051 1052 dGeomID RayXPos = dCreateRay(space,box->halfLength[0]); 1053 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1054 1.0f, 0.0f, 0.0f); 1055 dGeomID RayYPos = dCreateRay(space,box->halfLength[1] ); 1056 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1057 0.0f, 1.0f, 0.0f); 1058 dGeomID RayZPos = dCreateRay(space,box->halfLength[2] ); 1059 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1060 0.0f, 0.0f, 1.0f); 1061 1062 dGeomID RayXNeg = dCreateRay(space,box->halfLength[0] * 1.0f ); 1063 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1064 -1.0f, 0.0f, 0.0f); 1065 dGeomID RayYNeg = dCreateRay(space,box->halfLength[1] ); 1066 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z, 1067 0.0f, -1.0f, 0.0f); 1068 dGeomID RayZNeg = dCreateRay(space,box->halfLength[2] ); 1069 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z , 1070 0.0f, 0.0f, -1.0f); 1071 1072 1073 dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*40.0f + BSP_Y_OFFSET*30.0f ,2.0f* box->halfLength[2]); 1074 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 1075 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 1076 1077 1078 dGeomID BBOX2 ; 1079 1080 int g; 1081 bool collision = false; 1082 1083 for( int i = 0 ; i < this->bspFile->numPatches ; i++ ) 1084 { 1085 // dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox ); 1086 // BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]); 1087 // dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2); 1088 // dGeomDestroy(BBOX2); 1089 g = 0; 1090 if(true || dCollide(this->ODE_Geom_IDs[i],BBOX, 1, &contact[0].geom, sizeof(dContact)) ) { 1091 1092 if( true || dCollide(this->ODE_Geom_IDs[i],RayX, 1, &contact[0].geom, sizeof(dContact))) { 1093 if(dCollide(this->ODE_Geom_IDs[i],RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 1094 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f), 1095 Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), true); 1096 1097 }//if 1098 if(dCollide(this->ODE_Geom_IDs[i],RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 1099 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f), 1100 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), true); 1101 1102 }//if 1103 }//if 1104 1105 1106 if(dCollide(this->ODE_Geom_IDs[i],RayY, 1, &contact[0].geom, sizeof(dContact))) { 1107 1108 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1109 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1110 1111 //PRINTF(0)("Ground \n"); 1112 if(dCollide(this->ODE_Geom_IDs[i],RayYPos, 1, &contact[0].geom, sizeof(dContact))) { 1113 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1114 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false); 1115 1116 }//if 1117 else if(dCollide(this->ODE_Geom_IDs[i],RayYNeg, 1, &contact[0].geom, sizeof(dContact))) { 1118 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1119 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1120 1121 }//if 1122 else { 1123 1124 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1125 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1126 1127 } 1128 1129 }//if 1130 1131 if(true || dCollide(this->ODE_Geom_IDs[i],RayZ, 1, &contact[0].geom, sizeof(dContact))) { 1132 if(dCollide(this->ODE_Geom_IDs[i],RayZPos, 1, &contact[0].geom, sizeof(dContact))) { 1133 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f), 1134 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), true); 1135 1136 }//if 1137 if(dCollide(this->ODE_Geom_IDs[i],RayZNeg, 1, &contact[0].geom, sizeof(dContact))) { 1138 CoRe::CollisionTube::getInstance()->registerCollisionEvent(CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f), 1139 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), true); 1140 1141 }//if 1142 1143 1144 }//if 1145 1146 } //if 1147 } //for 1148 1149 dGeomDestroy(RayX); 1150 dGeomDestroy(RayY); 1151 dGeomDestroy(RayZ); 1152 dGeomDestroy(RayXPos); 1153 dGeomDestroy(RayYPos); 1154 dGeomDestroy(RayZPos); 1155 dGeomDestroy(RayXNeg); 1156 dGeomDestroy(RayYNeg); 1157 dGeomDestroy(RayZNeg); 1158 1159 dGeomDestroy(BBOX); 1160 } // if(bbox != 0) 1161 #endif 971 1162 972 1163
Note: See TracChangeset
for help on using the changeset viewer.