Changeset 10355 in orxonox.OLD for branches/ODE
- Timestamp:
- Jan 24, 2007, 8:48:26 PM (18 years ago)
- Location:
- branches/ODE
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/configure.ac
r9886 r10355 298 298 AX_CHECK_REQUIRED_HEADER_LIB([SDL.h SDL/SDL.h], [SDL], [main],,, [http://www.libsdl.org]) 299 299 300 301 302 #-----# 303 # ODE # 304 #-----# 305 #AX_CHECK_REQUIRED_HEADER_LIB([ode/ode.h],[ode],[main],,,[http://www.ode.org]) 306 307 308 # adding the lib to the files to link 309 LIBS="-lode $LIBS" 310 311 # introduce the optional configure parameter for the path of libXXX.a 312 AC_ARG_WITH(ode, 313 AC_HELP_STRING( 314 [--with-ode=prefix], 315 [try this for the ode-library prefix install directory] 316 ), 317 ode_PATHSET=1, 318 ode_PATHSET=0 319 ) 320 321 # if optional parameter used, extend path flags for compliler and linker 322 CPPFLAGS="$CPPFLAGS -I$with_ode/include" 323 CFLAGS="$CFLAGS -I$with_ode/include" 324 LDFLAGS="$LDFLAGS -L$with_ode/ode/src" 325 326 # overwrite global variable (used for Makefile generation) 327 AC_SUBST(GLOBALCPPFLAGS, $CPPFLAGS ) 328 AC_SUBST(GLOBALLDFLAGS, $LDFLAGS ) 329 330 331 332 300 333 ;; 334 335 301 336 302 337 ########### … … 375 410 #--------# 376 411 AX_CHECK_REQUIRED_HEADER_LIB([AL/al.h], [OpenAL32], [main],,, [http://www.openal.org]) 412 413 #-----# 414 # ODE # 415 #-----# 416 AX_CHECK_REQUIRED_HEADER_LIB([ode/ode.h],[ode],[main],,,[http://www.ode.org]) 417 377 418 378 419 #-----------# -
branches/ODE/src/lib/collision_detection/cd_engine.cc
r10033 r10355 68 68 void CDEngine::checkCollisions(ObjectManager::EntityList& list1, ObjectManager::EntityList& list2) 69 69 { 70 71 70 72 BVTree* tree; 71 73 ObjectManager::EntityList::iterator entity1, entity2, pre1, pre2; … … 84 86 if( likely((*entity2) != this->terrain)) 85 87 { 88 86 89 PRINTF(5)("checking object %s (%s) against %s (%s)\n", 87 (*entity1)->getClassCName(), (*entity1)->getCName(), (*entity2)->getClassCName(), (*entity2)->getCName()); 90 (*entity1)->getClassCName(), (*entity1)->getCName(), (*entity2)->getClassCName(), (*entity2)->getCName()); 91 #ifndef WITH_ODE 88 92 tree = (*entity1)->getOBBTree(); 89 93 if( likely(tree != NULL) && (*entity2)->getOBBTree() != NULL) 90 tree->collideWith(*entity1, *entity2); 94 tree->collideWith(*entity1, *entity2); 95 #endif 96 (*entity1)->checkCollision(*entity2); 97 98 91 99 } 92 100 } … … 102 110 { 103 111 std::list<WorldEntity*>::iterator entityIterator; 112 113 for( ObjectList<Terrain>::const_iterator bspIterator = Terrain::objectList().begin(); 114 bspIterator != Terrain::objectList().end(); 115 bspIterator++) { 116 for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++) 117 { 118 PRINTF(5)("Checking %s against: %s\n", ((dynamic_cast<Terrain*>(*bspIterator)))->getCName(), (*entityIterator)->getClassCName()); 119 (dynamic_cast<Terrain*>(*bspIterator))->checkCollision(*entityIterator); 120 } 121 } 122 104 123 // for all bsp managers check all entities 105 124 for( ObjectList<BspEntity>::const_iterator bspIterator = BspEntity::objectList().begin(); … … 108 127 for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++) 109 128 { 110 // PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassCName());129 // PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getCName(), (*entityIterator)->getClassCName()); 111 130 (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator); 112 131 } 132 113 133 } 134 114 135 } 115 136 -
branches/ODE/src/lib/collision_reaction/cr_physics_full_walk.cc
r10013 r10355 53 53 {} 54 54 55 55 56 56 /** 57 57 * caluculates and applys the reaction to a specific collision … … 60 60 void CRPhysicsFullWalk::reactToCollision(Collision* collision) 61 61 { 62 //PRINTF(0)("REACTION..................HEHEHEHEH:-)\n"); 62 63 63 64 AABB* box = collision->getEntityA()->getModelAABB(); … … 66 67 if( box == NULL) 67 68 { 68 PRINTF( 2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");69 PRINTF(0)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 69 70 return; 70 71 } … … 91 92 Vector collPos = collision->getEntityA()->getAbsCoor() + box->center - ce->getCollisionPosition(); 92 93 94 93 95 // test the 3 axis differently 94 96 switch( ce->getType()) … … 96 98 /* collision in the X-AXIS */ 97 99 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X: 98 front = collPos.len() - box->halfLength[0]; 100 101 // PRINTF(0)("ZZZZZZZZZZ ZZZZZ\n"); 102 front = (collPos- entity->getAbsCoor()).len() - box->halfLength[0]; 99 103 100 104 // object is beneath the plane (ground) 101 105 if( front <= 0.0f ) 102 106 { 107 // PRINTF(0)("FRONT"); 103 108 Vector dirX = entity->getAbsDirX(); 104 109 dirX.y = 0.0f; … … 116 121 117 122 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG: 123 124 // PRINTF(0)("ZZZZZZZZZZ ZZZZZ\n"); 118 125 back = collPos.len() - box->halfLength[0]; 119 126 … … 121 128 if( back <= 0.0f) 122 129 { 130 // PRINTF(0)("FRONT"); 123 131 Vector dirX = entity->getAbsDirX(); 124 132 dirX.y = 0.0f; … … 136 144 137 145 146 147 148 138 149 /* collision in the Y-AXIS */ 139 150 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG: 140 151 // calulate the height above ground 141 height = collPos.len()- box->halfLength[1];142 143 152 height = height = collPos.dot(Vector(0.0,1.0,0.0)) - box->halfLength[1] ; // collPos.len() - box->halfLength[1]; 153 // PRINTF(0)("HEIGHT : %f \n" , height); 154 144 155 // object is beneath the plane (ground) 145 156 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 146 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 147 { 148 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 157 if(height < 10.0f )//&& -height < CR_MAX_WALK_HEIGHT) 158 { 159 160 entity->shiftCoor(Vector(0.0f,-(height -10.0f) + 0.0001, 0.0f)); 161 //entity->setVelocity(Vector(entity->getVelocity().x, entity->getVelocity().y,entity->getVelocity().z)); 162 //entity->setAbsCoor(Vector(entity->getAbsCoor().x, entity->getLastAbsCoor().y+ 100.0*(entity->getAbsCoor()-entity->getLastAbsCoor()).len(),entity->getAbsCoor().z) ); 163 // PRINTF(0)("Geschw. %f\n",(0.0f)); 164 // PRINTF(0)("ENTITY:. %s\n",entity->getCName()); 165 149 166 entity->setOnGround(true); 150 167 } … … 153 170 { 154 171 entity->setAbsCoor(entity->getLastAbsCoor()); 155 PRINTF(0)("ground collision: reset pos\n");172 // PRINTF(0)("ground collision: reset pos\n"); 156 173 } 157 174 else … … 166 183 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z: 167 184 185 //PRINTF(0)("ZZZZZZZZZZ ZZZZZ\n"); 168 186 right = collPos.len() - box->halfLength[2]; 169 187 … … 187 205 // collision in the z-axis 188 206 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG: 189 207 208 // PRINTF(0)("ZZZZZZZZZZ ZZZZZ\n"); 190 209 left = collPos.len() - box->halfLength[2]; 191 210 -
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 -
branches/ODE/src/world_entities/space_ships/hover.cc
r10114 r10355 33 33 34 34 #include "debug.h" 35 #include "bsp_entity.h" 36 #include "terrain.h" 37 #include "state.h" 38 #include "camera.h" 35 39 36 40 … … 214 218 215 219 registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); 220 221 //this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 222 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, WorldEntity::staticClassID()); 216 223 } 217 224 … … 353 360 354 361 void Hover::draw() const 355 { 362 { 356 363 Vector tmpRot; 357 364 WorldEntity::draw(); … … 401 408 glRotatef(this->rotorCycle, 0,1,0); 402 409 this->getModel(5)->draw(); 410 403 411 glPopMatrix (); 412 413 glPushMatrix(); 414 glTranslatef (this->getAbsCoor ().x, 415 this->getAbsCoor ().y-2.0, 416 this->getAbsCoor ().z); 417 418 /* glBegin(GL_QUADS); 419 glColor4f(0.9,0.9,0.2,0.33); 420 glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up 421 glTexCoord2f(0.0f, 1.0f); glVertex3f(-10.0f, - 2.0f, -1.00f); // Point 1 (Top) 422 glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, -2.0f, 10.0f); // Point 2 (Top) 423 glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f, -2.0f, 10.0f); // Point 3 (Top) 424 glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f, -2.0f, -10.0f); // Point 4 (Top) 425 glEnd(); */ 426 427 //this->getModel(0)->draw(); 428 // glMatrixMode(GL_MODELVIEW); 429 430 // Vector tmpRot = this->getAbsDir().getSpacialAxis(); 431 // glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 432 433 Vector a = Vector(0.0,0.0,-10.0); 434 435 436 // drawDebugCube( &a); 437 // Experiment 438 439 440 441 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT ); 442 glDepthMask(GL_FALSE); 443 //glClear( GL_STENCIL_BUFFER_BIT); 444 glDisable(GL_TEXTURE_2D); 445 glActiveTextureARB(GL_TEXTURE0_ARB); 446 glDisable(GL_TEXTURE_2D); 447 // drawDebugCube( &a); 448 449 450 //glEnable(GL_CULL_FACE); 451 glEnable(GL_STENCIL_TEST); 452 //glEnable(GL_POLYGON_OFFSET_FILL); 453 //glPolygonOffset(0.0f, 100.0f); 454 //drawDebugCube( &a); 455 456 457 458 glDisable( GL_LIGHTING ); // Turn Off Lighting 459 glDepthMask( GL_FALSE ); // Turn Off Writing To The Depth-Buffer 460 //glDepthFunc( GL_LEQUAL ); 461 glEnable( GL_STENCIL_TEST ); // Turn On Stencil Buffer Testing 462 //glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); // Don't Draw Into The Colour Buffer 463 //glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL ); 464 465 466 glColorMask(0, 0, 0, 0); 467 glStencilFunc(GL_ALWAYS, 1, 0xffffffff); 468 469 // First Pass. Increase Stencil Value In The Shadow 470 471 glFrontFace( GL_CCW ); 472 glStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); 473 //doShadowPass( object, lightPosition ); 474 //drawDebugCube(&(State::getCamera()->getAbsCoor() + State::getCamera()->getAbsDirV()*3.0f) ); 475 drawDebugCube( &a); 476 this->getModel(0)->draw(); 477 //WorldEntity::draw(); 478 479 // Second Pass. Decrease Stencil Value In The Shadow 480 glFrontFace( GL_CW ); 481 glStencilOp( GL_KEEP, GL_KEEP, GL_DECR ); 482 //doShadowPass( object, lightPosition ); 483 //drawDebugCube(&(State::getCamera()->getAbsCoor() ) ); 484 drawDebugCube( &a); 485 this->getModel(0)->draw(); 486 //WorldEntity::draw(); 487 488 glFrontFace( GL_CCW ); 489 490 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 491 glDepthMask(GL_TRUE); 492 493 494 glColor4f( 0.0f, 0.9f, 0.0f, 0.4f ); 495 glDisable(GL_POLYGON_OFFSET_FILL); 496 glDisable(GL_DEPTH_TEST); 497 glDisable(GL_CULL_FACE); 498 //glEnable( GL_BLEND ); 499 //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 500 //glStencilFunc( GL_NOTEQUAL, 0, 0xffffffff ); 501 //glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); 502 ////glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); 503 504 glPushMatrix(); 505 glLoadIdentity(); 506 glBegin( GL_TRIANGLE_STRIP ); 507 glVertex3f( -1.1f, 1.1f, -5.5f ); 508 glVertex3f( -1.1f, -1.1f, -5.5f ); 509 glVertex3f( 1.1f, 1.1f, -5.5f ); 510 glVertex3f( 1.1f, -1.1f, -5.5f ); 511 glEnd(); 512 glPopMatrix (); 513 514 /* 515 glPushMatrix(); 516 glLoadIdentity(); 517 glMatrixMode(GL_PROJECTION); 518 glPushMatrix(); 519 glLoadIdentity(); 520 glOrtho(0, 1, 1, 0, 0, 1); 521 522 523 glColor4f(0.0f, 0.0f, 0.0f, 0.4f); 524 glBegin(GL_QUADS); 525 glVertex2i(0, 0); 526 glVertex2i(0, 1); 527 glVertex2i(1, 1); 528 glVertex2i(1, 0); 529 glEnd(); 530 531 glEnable(GL_DEPTH_TEST); 532 533 glPopMatrix(); 534 glMatrixMode(GL_MODELVIEW); 535 */ 536 537 glPopAttrib(); 538 glPopMatrix (); 404 539 } 405 540 … … 441 576 } 442 577 } 578 579 void drawDebugCube(const Vector* cam) 580 { 581 glBegin(GL_QUADS); 582 // Front Face 583 glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer 584 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 1 (Front) 585 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 2 (Front) 586 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Front) 587 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 4 (Front) 588 // Back Face 589 glNormal3f( 0.0f, 0.0f,-1.0f); // Normal Pointing Away From Viewer 590 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Back) 591 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 2 (Back) 592 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 3 (Back) 593 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 4 (Back) 594 // Top Face 595 glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up 596 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 1 (Top) 597 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 2 (Top) 598 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Top) 599 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 4 (Top) 600 // Bottom Face 601 glNormal3f( 0.0f,-1.0f, 0.0f); // Normal Pointing Down 602 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Bottom) 603 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 2 (Bottom) 604 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 3 (Bottom) 605 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 4 (Bottom) 606 // Right face 607 glNormal3f( 1.0f, 0.0f, 0.0f); // Normal Pointing Right 608 glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 1 (Right) 609 glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 2 (Right) 610 glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Right) 611 glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 4 (Right) 612 // Left Face 613 glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Pointing Left 614 glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Left) 615 glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 2 (Left) 616 glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 3 (Left) 617 glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 4 (Left) 618 glEnd(); // Done Drawing Quads 619 620 621 glBegin(GL_QUADS); 622 623 return; 624 // Bottom Face. Red, 75% opaque, magnified texture 625 626 //glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting 627 // glColor4f(0.9,0.2,0.2,.75); // Basic polygon color 628 629 //glTexCoord2f(0.800f, 0.800f); 630 glVertex3f(cam->x-5.0f, cam->y-100.0f,cam->z -5.0f); 631 // glTexCoord2f(0.200f, 0.800f); 632 glVertex3f(cam->x+5.0f, cam->y-100.0f,cam->z -5.0f); 633 //glTexCoord2f(0.200f, 0.200f); 634 glVertex3f(cam->x+ 5.0f,cam->y -100.0f,cam->z + 5.0f); 635 //glTexCoord2f(0.800f, 0.200f); 636 glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z + 5.0f); //OK 637 638 639 // Top face; offset. White, 50% opaque. 640 641 // glNormal3f( 0.0f, 5.0f, 0.0f); glColor4f(0.5,0.5,0.5,.5); 642 643 //glTexCoord2f(0.005f, 5.995f); 644 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); 645 //glTexCoord2f(0.005f, 0.005f); 646 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); 647 //glTexCoord2f(5.995f, 0.005f); 648 glVertex3f(cam->x+ 5.0f, cam->y+100.0f, cam->z +5.0f); 649 //glTexCoord2f(5.995f, 5.995f); 650 glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f); //OKQUAD_STRI 651 652 653 // Far face. Green, 50% opaque, non-uniform texture cooridinates. 654 655 //glNormal3f( 0.0f, 0.0f,-5.0f); glColor4f(0.2,0.9,0.2,.5); 656 657 // glTexCoord2f(0.995f, 0.005f); 658 glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f); 659 // glTexCoord2f(2.995f, 2.995f); 660 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); 661 // glTexCoord2f(0.005f, 0.995f); 662 glVertex3f(cam->x+ 5.0f,cam->y+ 100.0f, cam->z -5.0f); 663 //glTexCoord2f(0.005f, 0.005f); 664 glVertex3f( cam->x+5.0f,cam->y -100.0f, cam->z -5.0f); 665 666 667 // Right face. Blue; 25% opaque 668 669 // glNormal3f( 5.0f, 0.0f, 0.0f); glColor4f(0.2,0.2,0.9,.25); 670 671 // glTexCoord2f(0.995f, 0.005f); 672 glVertex3f(cam->x+ 5.0f, cam->y -100.0f, cam->z -5.0f); 673 // glTexCoord2f(0.995f, 0.995f); 674 glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f); 675 // glTexCoord2f(0.005f, 0.995f); 676 glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z + 5.0f); 677 // glTexCoord2f(0.005f, 0.005f); 678 glVertex3f(cam->x+ 5.0f, cam->y-100.0f, cam->z +5.0f); 679 680 681 // Front face; offset. Multi-colored, 50% opaque. 682 683 // glNormal3f( 0.0f, 0.0f, 5.0f); 684 685 // glColor4f( 0.9f, 0.2f, 0.2f, 0.5f); 686 // glTexCoord2f( 0.005f, 0.005f); 687 glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z +5.0f); 688 // glColor4f( 0.2f, 0.9f, 0.2f, 0.5f); 689 // glTexCoord2f( 0.995f, 0.005f); 690 glVertex3f(cam->x+ 5.0f, cam->y-100.0f, cam->z +5.0f); 691 // glColor4f( 0.2f, 0.2f, 0.9f, 0.5f); 692 // glTexCoord2f( 0.995f, 0.995f); 693 glVertex3f( cam->x+5.0f, cam->y+100.0f, cam->z +5.0f); 694 // glColor4f( 0.5f, 0.5f, 0.5f, 0.5f); 695 // glTexCoord2f( 0.005f, 0.995f); g 696 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); 697 698 699 // Left Face; offset. Yellow, varying levels of opaque. 700 701 // glNormal3f(-5.0f, 0.0f, 0.0f); 702 703 // glColor4f(0.9,0.9,0.2,0.0); 704 // glTexCoord2f(0.005f, 0.005f); 705 glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f); 706 //glColor4f(0.9,0.9,0.2,0.66); 707 // glTexCoord2f(0.995f, 0.005f); 708 glVertex3f(cam->x-5.0f,cam->y -100.0f, cam->z +5.0f); 709 // glColor4f(0.9,0.9,0.2,5.0); 710 // glTexCoord2f(0.995f, 0.995f); 711 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); 712 // glColor4f(0.9,0.9,0.2,0.33); 713 // glTexCoord2f(0.005f, 0.995f); 714 glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); 715 716 glEnd(); 717 } -
branches/ODE/src/world_entities/world_entity.cc
r10147 r10355 1 1 2 2 3 3 /* … … 45 45 46 46 #include "projectiles/projectile.h" 47 48 49 #include "class_id.h" 50 #include "aabb.h" 51 #include "cr_defs.h" 52 #include "cd_engine.h" 53 #include "collision_tube.h" 54 55 #include "static_model.h" 56 57 58 59 #ifdef WITH_ODE 60 #include <ode/ode.h> 61 #endif 47 62 48 63 SHELL_COMMAND(model, WorldEntity, loadModel) … … 283 298 bool WorldEntity::buildObbTree(int depth) 284 299 { 300 301 #ifdef WITH_ODE 302 this->world = dWorldCreate(); // the World will be Static for mor efficiency 303 this->space = dSimpleSpaceCreate(0); // same for the space 304 contactgroup = dJointGroupCreate (0); 305 dWorldSetGravity (world,0,0,-0.5); 306 dWorldSetCFM (world,1e-5); 307 308 309 if(this->getModel(0)!=0) 310 { 311 if(this->getModel(0)->isA( StaticModel::staticClassID() ) ) 312 { 313 314 315 316 StaticModelData::Pointer ModelData = ((StaticModel*)this->getModel())->dataPointer(); 317 //ModelData->buildTriangleList(); 318 319 PRINTF(0)(" Dieses Model hat %i Vertices \n", ModelData->getVertices().size()); 320 PRINTF(0)(" Dieses Model hat %i Dreiecke \n",((ModelData->getTriangles()).size() )); 321 this->Ind = new unsigned int [(ModelData->getTriangles()).size()*3]; 322 for(int i = 0 ; i < (ModelData->getTriangles()).size(); i++) 323 { 324 Ind[3*i] = (ModelData->getTrianglesExt())[i].indexToVertices[0] / 3 ; 325 Ind[3*i +1] = (ModelData->getTrianglesExt())[i].indexToVertices[1] / 3; 326 Ind[3*i +2] = (ModelData->getTrianglesExt())[i].indexToVertices[2] / 3; 327 328 } 329 330 //((StaticModel*)(this->getModel()))->acquireData(ModelData); 331 this->ODE_Geometry = dGeomTriMeshDataCreate(); 332 dGeomTriMeshDataBuildSingle(this->ODE_Geometry,&((ModelData->getVertices())[0]), 3*sizeof(float),(ModelData->getVertices().size() /3 ) , &Ind[0] ,((ModelData->getTriangles()).size() *3 ), 3*sizeof(unsigned int) ); 333 // Create ODE-Data here! 334 335 336 //!fixme 337 for (int i=0; i<30; i++) { 338 contact[i].surface.mode = dContactBounce | dContactSoftCFM; 339 contact[i].surface.mu = dInfinity; 340 contact[i].surface.mu2 = 0; 341 contact[i].surface.bounce = 0.1; 342 contact[i].surface.bounce_vel = 0.1; 343 contact[i].surface.soft_cfm = 0.01; 344 } 345 346 347 this->ODE_Geom_ID = dCreateTriMesh(space,this->ODE_Geometry,0 , 0, 0); 348 349 350 //CDEngine::getInstance()->setTerrain(this); 351 //this->loaded = true; 352 //this->toList(OM_ENVIRON); 353 354 } else 355 { 356 if(this->getModelAABB() == NULL ) 357 { 358 this->ODE_Geom_ID = dCreateBox (space, 20.0f, 40.0f ,20.0f); 359 //dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*2.0f ,2.0f* box->halfLength[2]); 360 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 361 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 362 } 363 } 364 365 366 if(this->getModelAABB() != NULL ) 367 { 368 AABB* box = this->getModelAABB(); 369 //this->ODE_Geom_ID = dCreateBox (space, 2.0f, 4.0f ,2.0f); 370 this->ODE_Geom_ID = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*2.0f ,2.0f* box->halfLength[2]); 371 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 372 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 373 } 374 } 375 376 else 377 { 378 if(this->getModelAABB() != NULL ) 379 { 380 AABB* box = this->getModelAABB(); 381 //this->ODE_Geom_ID = dCreateBox (space, 2.0f, 4.0f ,2.0f); 382 this->ODE_Geom_ID = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*2.0f ,2.0f* box->halfLength[2]); 383 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 384 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 385 } 386 387 if(this->getModelAABB() == NULL ) 388 { 389 this->ODE_Geom_ID = dCreateBox (space, 20.0f, 40.0f ,20.0f); 390 //dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*2.0f ,2.0f* box->halfLength[2]); 391 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 392 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 393 } 394 } 395 396 397 398 #endif 399 400 285 401 if( this->obbTree != NULL) 286 402 { … … 317 433 return false; 318 434 } 435 319 436 return true; 320 437 } 438 439 440 441 void WorldEntity::checkCollision(WorldEntity* worldEntity) { 442 443 #ifndef WITH_ODE 444 return; 445 #endif 446 #ifdef WITH_ODE 447 //if(!this->loaded) return; 448 //dWorldSetQuickStepNumIterations (this->world, 1); 449 //dWorldQuickStep (this->world, 0.1); 450 451 AABB* box = worldEntity->getModelAABB(); 452 dReal aabbox [6]; 453 454 if( (this->getModel(0)!= 0) && (this->getModel(0)->isA( StaticModel::staticClassID())) ) { 455 456 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 457 if(box != NULL ) 458 { 459 //PRINTF(0)("Do have abb-box! :_)\n"); 460 dGeomID RayX = dCreateRay(space,box->halfLength[0] *2.0f); 461 dGeomRaySet (RayX, worldEntity->getAbsCoor().x - box->halfLength[0] ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 462 1.0f, 0.0f, 0.0f); 463 dGeomID RayY = dCreateRay(space,box->halfLength[1] * 10000.0f); 464 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y - 5000.0f*box->halfLength[1], worldEntity->getAbsCoor().z, 465 0.0f, 1.0f, 0.0f); 466 dGeomID RayZ = dCreateRay(space,box->halfLength[2] *2.0f); 467 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2], 468 0.0f, 0.0f, 1.0f); 469 470 dGeomID RayXPos = dCreateRay(space,box->halfLength[0]); 471 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 472 1.0f, 0.0f, 0.0f); 473 dGeomID RayYPos = dCreateRay(space,box->halfLength[1] * 1100.0 ); 474 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 475 0.0f, 1.0f, 0.0f); 476 dGeomID RayZPos = dCreateRay(space,box->halfLength[2] ); 477 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 478 0.0f, 0.0f, 1.0f); 479 480 dGeomID RayXNeg = dCreateRay(space,box->halfLength[0] ); 481 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 482 -1.0f, 0.0f, 0.0f); 483 dGeomID RayYNeg = dCreateRay(space, box->halfLength[1] * 1100.0f ); 484 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z, 485 0.0f, -1.0f, 0.0f); 486 dGeomID RayZNeg = dCreateRay(space,box->halfLength[2] ); 487 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z , 488 0.0f, 0.0f, -1.0f); 489 490 //dGeomID BBOX = dCreateBox (space, 2.0f, 4.0f ,2.0f); 491 dGeomID BBOX = dCreateBox (space,box->halfLength[0]*0.003f, box->halfLength[1]*500.0f ,0.0030f* box->halfLength[2]); 492 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 493 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 494 495 496 497 498 499 int g; 500 bool collision = false; 501 502 503 // dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox ); 504 // BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]); 505 // dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2); 506 // dGeomDestroy(BBOX2); 507 g = 0; 508 if( dCollide(this->ODE_Geom_ID,BBOX, 2, &contact[0].geom, sizeof(dContact)) ) { 509 510 PRINTF(0)("%s :Collision wit %s at %f , %f , %f : height: %f. \n", this->getCName(),worldEntity->getCName(), contact[0].geom.pos[0],contact[0].geom.pos[1]+2.1,contact[0].geom.pos[2], (worldEntity->getAbsCoorY() - contact[0].geom.pos[1]) ); 511 for(int i = 0; i <1 ; i++) 512 { 513 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , worldEntity, this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 514 } 515 516 if(dCollide(this->ODE_Geom_ID,RayX, 1, &contact[0].geom, sizeof(dContact))) { 517 if(dCollide(this->ODE_Geom_ID,RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 518 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), 519 // Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 520 521 }//if 522 if(dCollide(this->ODE_Geom_ID,RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 523 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_X_NEG , this, worldEntity, //Vector(1.0f, 0.0f, 0.0f), 524 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 525 526 }//if 527 }//if 528 529 if(this->isA("Terrain")) //ClassList::StringToID) 530 { 531 532 533 534 if(this->isA("Terrain")) 535 { 536 PRINTF(0)("Ich bin ein %s \n",this->getClassCName() ); 537 } 538 539 if( dCollide(this->ODE_Geom_ID,RayY, 1, &contact[0].geom, sizeof(dContact))) { 540 541 /* 542 if(false && dCollide(this->ODE_Geom_ID,RayYNeg, 1, &contact[0].geom, sizeof(dContact))) { 543 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, ,this1.0f, 0.0f), 544 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 545 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 546 PRINTF(0)("Kooomische ................Collision"); 547 548 }//if 549 if( false && dCollide(this->ODE_Geom_ID,RayYPos, 1, &contact[0].geom, sizeof(dContact))) { 550 551 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , worldEntity,this, Vector(0.0f, -1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 552 PRINTF(0)("Kooomische ................Collision"); 553 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 554 //Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false); 555 556 }//if 557 else { */ 558 559 //CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 560 PRINTF(0)("Kooomische ................Collision"); 561 562 //worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 563 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 564 565 //} 566 567 }//if 568 569 if(dCollide(this->ODE_Geom_ID,RayZ, 1, &contact[0].geom, sizeof(dContact))) { 570 if(dCollide(this->ODE_Geom_ID,RayZPos, 1, &contact[0].geom, sizeof(dContact))) { 571 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 572 PRINTF(0)("Kooomische ................Collision"); 573 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 574 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 575 576 }//if 577 if(dCollide(this->ODE_Geom_ID,RayZNeg, 1, &contact[0].geom, sizeof(dContact))) { 578 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 579 PRINTF(0)("Kooomische ................Collision"); 580 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 581 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 582 583 }//if 584 585 586 if(dCollide(this->ODE_Geom_ID,RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 587 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 588 PRINTF(0)("Kooomische ................Collision"); 589 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 590 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 591 592 }//if 593 if(dCollide(this->ODE_Geom_ID,RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 594 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG , worldEntity,this, Vector(0.0f, 1.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 595 PRINTF(0)("Kooomische ................Collision"); 596 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 597 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 598 599 }//if 600 601 602 }//if 603 }//if 604 605 } //if 606 607 608 dGeomDestroy(RayX); 609 dGeomDestroy(RayY); 610 dGeomDestroy(RayZ); 611 dGeomDestroy(RayXPos); 612 dGeomDestroy(RayYPos); 613 dGeomDestroy(RayZPos); 614 dGeomDestroy(RayXNeg); 615 dGeomDestroy(RayYNeg); 616 dGeomDestroy(RayZNeg); 617 618 dGeomDestroy(BBOX); 619 } // if(bbox != 0) 620 621 if(box == NULL) 622 { 623 dGeomID BBOX = dCreateBox (space, 20.0f, 40.0f ,20.0f); 624 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 625 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 626 if(dCollide(this->ODE_Geom_ID,BBOX, 1, &contact[0].geom, sizeof(dContact))) 627 { 628 629 PRINTF(0)("Collision wit %s at %f , %f , %f . \n", worldEntity->getCName(), contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2] ); 630 631 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 632 } 633 dGeomDestroy(BBOX); 634 } 635 } 636 else { 637 dGeomSetPosition (this->ODE_Geom_ID, this->getAbsCoor().x ,this->getAbsCoor().y, this->getAbsCoor().z); 638 //if(box != NULL ) 639 dGeomID BBOX = dCreateBox (space, 10.0f, 40.0f ,10.0f); 640 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 641 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 642 if(dCollide(this->ODE_Geom_ID,BBOX, 1, &contact[0].geom, sizeof(dContact))) 643 { 644 645 PRINTF(5)("Collision wit %s at %f , %f , %f . \n", worldEntity->getCName(), contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2] ); 646 647 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , worldEntity, this, Vector(1.0f, 0.0f, 0.0f), Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 648 } 649 dGeomDestroy(BBOX); 650 651 } 652 653 #endif 654 655 } 656 321 657 322 658 -
branches/ODE/src/world_entities/world_entity.h
r10147 r10355 22 22 #include <vector> 23 23 24 #ifdef WITH_ODE 25 #include <ode/ode.h> 26 #endif 24 27 25 28 // FORWARD DECLARATION … … 76 79 /* --- Collision Detection Block --- */ 77 80 bool buildObbTree(int depth); 81 void checkCollision(WorldEntity* worldEntity); 82 78 83 virtual void collidesWith (WorldEntity* entity, const Vector& location); 79 84 virtual void collidesWithGround(const Vector& location); … … 230 235 int healthMax_handle; 231 236 237 unsigned int* Ind; 238 239 240 #ifdef WITH_ODE 241 dTriMeshDataID ODE_Geometry; //!< ODE Geometry Data of the static model 242 dGeomID ODE_Geom_ID; //!< ID of ODE Geometry Data 243 dWorldID world; 244 dSpaceID space; 245 dJointGroupID contactgroup; 246 dContact contact[300]; 247 #endif 232 248 233 249
Note: See TracChangeset
for help on using the changeset viewer.