Changeset 10355 in orxonox.OLD for branches/ODE/src/lib/graphics
- Timestamp:
- Jan 24, 2007, 8:48:26 PM (18 years ago)
- Location:
- branches/ODE
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/src/lib/graphics/importer/bsp/bsp_file.cc
r10033 r10355 40 40 #include <vector> 41 41 42 #ifdef WITH_ODE 43 #include <ode/ode.h> 44 #endif 42 45 43 46 … … 330 333 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 331 334 // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed? 335 #ifdef WITH_ODE 336 this->ODE_Geometry = new dTriMeshDataID[this->numPatches*7*7]; 337 #endif 332 338 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 333 339 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; … … 728 734 * @todo cleanup this function, let the user choose the level of tesselation 729 735 */ 730 736 #ifdef WITH_ODE 737 uint Ind [] = {8,0,9, 0,1,9, 9,1,10, 1,2,10, 10,2,11, 2,3,11, 11,3,12, 3,4,12, 12,4,13, 4,5,13, 13,5,14, 5,6,14, 14,6,15, 6,7,15, 738 16,8,17, 8,9,17, 17,9,18, 9,10,18, 18,10,19, 10,11,19, 19,11,20, 11,12,20, 20,12,21, 12,13,21, 21,13,22, 13,14,22, 22,14,23, 14,15,23, 739 24,16,25, 16,17,25, 25,17,26, 17,18,26, 26,18,27, 18,19,27, 27,19,28, 19,20,28, 28,20,29, 20,21,29, 29,21,30, 21,22,30, 30,22,31, 22,23,31, 740 32,24,33, 24,25,33, 33,25,34, 25,26,34, 34,26,35, 26,27,35, 35,27,36, 27,28,36, 36,28,37, 28,29,37 ,37,29,38, 29,30,38, 38,30,39, 30,31,39, 741 40,32,41, 32,33,41, 41,33,42, 33,34,42, 42,34,43, 34,35,43, 43,35,44, 35,36,44, 44,36,45, 36,37,45, 45,37,46, 37,38,46, 46,38,47, 38,39,47, 742 48,40,49, 40,41,49, 49,41,50, 41,42,50, 50,42,51, 42,43,51, 51,43,52, 43,44,52, 52,44,53, 44,45,53, 53,45,54, 45,46,54, 54,46,55, 46,47,55, 743 56,48,57, 48,49,57, 57,49,58, 49,50,58, 58,50,59, 50,51,59, 59,51,60, 51,52,60, 60,52,61, 52,53,61, 61,53,62, 52,54,62, 62,54,63, 54,55,63, 0 }; 744 #endif 731 745 732 746 void BspFile::tesselate(int iface) … … 888 902 } 889 903 } 904 905 #ifdef WITH_ODE 906 this->ODE_Geometry[this->patchOffset] = dGeomTriMeshDataCreate(); 907 // Create ODE Triangle Mesh Geometry 908 dGeomTriMeshDataBuildSingle(this->ODE_Geometry[this->patchOffset], &((((BspVertex*)(this->patchVertice))[level1*level1*this->patchOffset ]).position[0]), sizeof(BspVertex), level1*level1, &(Ind[0]) ,7*14*3, 3* sizeof(uint) ); 909 #endif 890 910 891 911 -
branches/ODE/src/lib/graphics/importer/bsp/bsp_file.h
r10033 r10355 17 17 Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ 18 18 */ 19 20 #define WITH_ODE 21 #ifdef WITH_ODE 22 #include <ode/ode.h> 23 #endif 19 24 20 25 #include <vector> … … 159 164 AMat loadMat( char* mat ); 160 165 AMat loadAVI(char * mat); 166 167 #ifdef WITH_ODE 168 dTriMeshDataID* getODE_Geometry(void) {return this->ODE_Geometry;} 169 #endif 161 170 162 171 … … 215 224 216 225 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 226 227 #ifdef WITH_ODE 228 dTriMeshDataID* ODE_Geometry; //!< ODE Geometry Data for patches 229 dGeomID* ODE_Geom_IDs; //!< IDs of ODE Geometry Data 230 #endif 231 217 232 }; 218 233 -
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 -
branches/ODE/src/lib/graphics/importer/bsp/bsp_manager.h
r10033 r10355 31 31 #define BSP_Y_OFFSET 40.0f 32 32 #define BSP_Z_OFFSET 20.0f 33 34 #define WITH_ODE 35 36 #ifdef WITH_ODE 37 #include <ode/ode.h> 38 #endif 33 39 34 40 … … 136 142 137 143 int tgl; 144 145 146 #ifdef WITH_ODE 147 dWorldID world; 148 dSpaceID space; 149 dJointGroupID contactgroup; 150 dContact contact[300]; 151 dGeomID* ODE_Geom_IDs; //!< IDs of ODE Geometry Data 152 #endif 138 153 }; 139 154
Note: See TracChangeset
for help on using the changeset viewer.