Changeset 9919 in orxonox.OLD for branches/ODE/src/lib/graphics/importer/bsp_manager.cc
- Timestamp:
- Nov 5, 2006, 9:07:04 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/src/lib/graphics/importer/bsp_manager.cc
r9869 r9919 48 48 #include "cr_defs.h" 49 49 50 #include<ode/ode.h> 51 50 52 51 53 //CREATE_FACTORY( BspManager, CL_BSP_MODEL); … … 88 90 { 89 91 // open a BSP file 92 this->world = dWorldCreate(); 93 space = dSimpleSpaceCreate(0); 94 95 //!fixme 96 for (int i=0; i<30; i++) { 97 contact[i].surface.mode = dContactBounce | dContactSoftCFM; 98 contact[i].surface.mu = dInfinity; 99 contact[i].surface.mu2 = 0; 100 contact[i].surface.bounce = 0.1; 101 contact[i].surface.bounce_vel = 0.1; 102 contact[i].surface.soft_cfm = 0.01; 103 } 104 105 90 106 91 107 … … 101 117 this->outputFraction = 1.0f; 102 118 119 contactgroup = dJointGroupCreate (0); 120 dWorldSetGravity (world,0,0,-0.5); 121 dWorldSetCFM (world,1e-5); 122 this->ODE_Geom_IDs = new dGeomID[this->bspFile->numPatches* 7 *7]; 123 124 for( int i = 0 ; i < (this->bspFile->numPatches ); i++ ) 125 { 126 this->ODE_Geom_IDs[i] = dCreateTriMesh(space,(this->bspFile->getODE_Geometry())[i],0 , 0, 0); 127 128 } 103 129 return 0; 104 130 } … … 970 996 971 997 972 #if 0 973 // Retrieve Bounding box 974 AABB* box = worldEntity->getModelAABB(); 975 976 977 Vector forwardDir = Vector(0.0,0.0,1.0); 978 Vector upDir = Vector(0.0,1.0,0.0); 979 Vector position = worldEntity->getAbsCoor(); 980 981 bool SolidFlag = false; 982 bool collision = false; 983 Vector position1 = position; 984 Vector position2 = position + Vector(0.0,1.0,0.0); 985 Vector position3 = position; 986 Vector position4 = position + Vector(0.0,1.0,0.0); 987 Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; // 988 Vector dest1 = position + forwardDir*4.0f; 989 Vector dest2 = position2 + forwardDir*4.0; 990 Vector dest3 = position + forwardDir*4.0f; 991 Vector dest4 = position2 + forwardDir*4.0; 992 dest = position - Vector(0.0, 40.0,0.0); 993 Vector out = dest; 994 Vector out1; 995 Vector out2; 996 997 998 plane* testPlane; 999 1000 bool xCollision = false; 1001 bool zCollision = false; 1002 1003 1004 float height = 40; 1005 1006 1007 if( box != NULL) { 1008 position = worldEntity->getAbsCoor() + box->center; // + Vector(0.0, 1.0, 0.0) * box->halfLength[1] * 1.0f; 1009 dest = worldEntity->getAbsCoor() + box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET) * 100; 1010 1011 Vector dirX = worldEntity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize(); 1012 1013 //position1 = worldEntity->getAbsCoor() + box->center - dirX * (box->halfLength[0] + BSP_X_OFFSET); 1014 dest1 = worldEntity->getAbsCoor() + box->center + dirX * (box->halfLength[0] + BSP_X_OFFSET); 1015 dest2 = worldEntity->getAbsCoor() - box->center + dirX * (box->halfLength[0] + BSP_X_OFFSET); 1016 1017 Vector dirZ = worldEntity->getAbsDirZ(); dirX.y = 0.0f; dirZ.normalize(); 1018 //position2 = worldEntity->getAbsCoor() + box->center - dirZ * (box->halfLength[2] + BSP_Z_OFFSET); 1019 dest3 = worldEntity->getAbsCoor() + box->center + dirZ * (box->halfLength[2] + BSP_Z_OFFSET); 1020 dest4 = worldEntity->getAbsCoor() - box->center + dirZ * (box->halfLength[2] + BSP_Z_OFFSET); 1021 } else { 1022 // Init positions and destinations to anything useful! 1023 1024 } 1025 1026 1027 1028 // 1st Ray: Y RAY 1029 this->inputStart = position; 1030 this->inputEnd = dest; 1031 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 1032 1033 1034 // 1035 if(!this->outputStartsOut ) { 1036 this->collPlane = new plane; 1037 this->collPlane->x = 0.0f; 1038 this->collPlane->y = 0.0f; 1039 this->collPlane->z = 0.0f; 1040 collision = true; 1041 } else { 1042 1043 if( this->outputFraction == 1.0f) { 1044 if(this->outputAllSolid ) { 1045 this->collPlane = new plane; 1046 this->collPlane->x = 0.0f; 1047 this->collPlane->y = 0.0f; 1048 this->collPlane->z = 0.0f; 1049 collision = true; 1050 SolidFlag = true; 1051 } else 1052 collision = false; 1053 1054 1055 out = dest; 1056 1057 } else { 1058 collision = true; 1059 out.x = position.x + (dest.x -position.x) * this->outputFraction; 1060 out.y = position.y + (dest.y -position.y) * this->outputFraction; 1061 out.z = position.z + (dest.z -position.z) * this->outputFraction; 1062 1063 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 1064 this->out = out; 1065 } 1066 } 1067 testPlane = this->collPlane; 1068 1069 1070 bool xCollisionNeg = false; 1071 bool zCollisionNeg = false; 1072 1073 1074 1075 // 2nd Collision Detection X-RAY 1076 this->outputStartsOut = true; 1077 this->outputAllSolid = false; 1078 this->outputFraction = 1.0f; 1079 this->inputStart = position1; 1080 this->inputEnd = dest1; 1081 this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 ); 1082 1083 if(this->outputFraction < 1.0f) { 1084 out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction; 1085 dest1 = position1 + (dest1 -position1) * this->outputFraction; 1086 xCollision = true; 1087 testPlane = this->collPlane; 1088 } 1089 if(this->outputAllSolid ) { 1090 1091 this->collPlane = new plane; 1092 this->collPlane->x = 0.0f; 1093 this->collPlane->y = 0.0f; 1094 this->collPlane->z = 0.0f; 1095 testPlane = this->collPlane; 1096 SolidFlag = true; 1097 xCollision = true; 1098 } 1099 //out.z = this->outputFraction; 1100 1101 1102 1103 // 3rd Collision Detection Z-RAY 1104 this->outputStartsOut = true; 1105 this->outputAllSolid = false; 1106 this->outputFraction = 1.0f; 1107 this->inputStart = position2; 1108 this->inputEnd = dest2; 1109 1110 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 1111 //out.x = this->outputFraction; 1112 1113 if(this->outputFraction < 1.0f ) { 1114 out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction; 1115 dest2 = position2 + (dest2 -position2) * this->outputFraction; 1116 zCollision = true; 1117 testPlane = this->collPlane; 1118 1119 } 1120 if(this->outputAllSolid ) { 1121 this->collPlane = new plane; 1122 this->collPlane->x = 0.0f; 1123 this->collPlane->y = 0.0f; 1124 this->collPlane->z = 0.0f; 1125 testPlane = this->collPlane; 1126 1127 SolidFlag = true; 1128 zCollision = true; 1129 } 1130 1131 1132 // Return the normal here: Normal's stored in this->collPlane; 1133 if( collision) { 1134 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1135 } 1136 if(xCollision) { 1137 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag); 1138 } 1139 1140 if(zCollision) { 1141 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag); 1142 } 1143 #endif 1144 1145 } 1146 998 999 1000 // Create the World-Entities BBOX 1001 AABB* box = worldEntity->getModelAABB(); 1002 dReal aabbox [6]; 1003 1004 if( box != NULL) 1005 { 1006 1007 dGeomID RayX = dCreateRay(space,box->halfLength[0] *2.0f); 1008 dGeomRaySet (RayX, worldEntity->getAbsCoor().x - box->halfLength[0] ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1009 1.0f, 0.0f, 0.0f); 1010 dGeomID RayY = dCreateRay(space,box->halfLength[1] *2.0f); 1011 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y - box->halfLength[1], worldEntity->getAbsCoor().z, 1012 0.0f, 1.0f, 0.0f); 1013 dGeomID RayZ = dCreateRay(space,box->halfLength[2] *2.0f); 1014 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2], 1015 0.0f, 0.0f, 1.0f); 1016 1017 dGeomID RayXPos = dCreateRay(space,box->halfLength[0]); 1018 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1019 1.0f, 0.0f, 0.0f); 1020 dGeomID RayYPos = dCreateRay(space,box->halfLength[1] ); 1021 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1022 0.0f, 1.0f, 0.0f); 1023 dGeomID RayZPos = dCreateRay(space,box->halfLength[2] ); 1024 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1025 0.0f, 0.0f, 1.0f); 1026 1027 dGeomID RayXNeg = dCreateRay(space,box->halfLength[0] * 40.0f ); 1028 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 1029 -1.0f, 0.0f, 0.0f); 1030 dGeomID RayYNeg = dCreateRay(space,box->halfLength[1] ); 1031 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z, 1032 0.0f, -1.0f, 0.0f); 1033 dGeomID RayZNeg = dCreateRay(space,box->halfLength[2] ); 1034 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z , 1035 0.0f, 0.0f, -1.0f); 1036 1037 1038 dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*40.0f + BSP_Y_OFFSET*30.0f ,2.0f* box->halfLength[2]); 1039 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 1040 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 1041 1042 1043 dGeomID BBOX2 ; 1044 1045 int g; 1046 bool collision = false; 1047 1048 for( int i = 0 ; i < this->bspFile->numPatches /* * 7 */; i++ ) 1049 { 1050 // dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox ); 1051 // BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]); 1052 // dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2); 1053 // dGeomDestroy(BBOX2); 1054 g = 0; 1055 if(dCollide(this->ODE_Geom_IDs[i],BBOX, 1, &contact[0].geom, sizeof(dContact)) ) { 1056 1057 if(dCollide(this->ODE_Geom_IDs[i],RayX, 1, &contact[0].geom, sizeof(dContact))) { 1058 if(dCollide(this->ODE_Geom_IDs[i],RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 1059 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f), 1060 Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1061 1062 }//if 1063 if(dCollide(this->ODE_Geom_IDs[i],RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 1064 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X_NEG , this->parent, worldEntity, Vector(1.0f, 0.0f, 0.0f), 1065 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1066 1067 }//if 1068 }//if 1069 1070 1071 if(dCollide(this->ODE_Geom_IDs[i],RayY, 1, &contact[0].geom, sizeof(dContact))) { 1072 1073 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1074 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1075 1076 //PRINTF(0)("Ground \n"); 1077 if(dCollide(this->ODE_Geom_IDs[i],RayYPos, 1, &contact[0].geom, sizeof(dContact))) { 1078 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1079 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false); 1080 1081 }//if 1082 else if(dCollide(this->ODE_Geom_IDs[i],RayYNeg, 1, &contact[0].geom, sizeof(dContact))) { 1083 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1084 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1085 1086 }//if 1087 else { 1088 1089 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(0.0f, 1.0f, 0.0f), 1090 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1091 1092 } 1093 1094 }//if 1095 1096 if(dCollide(this->ODE_Geom_IDs[i],RayZ, 1, &contact[0].geom, sizeof(dContact))) { 1097 if(dCollide(this->ODE_Geom_IDs[i],RayZPos, 1, &contact[0].geom, sizeof(dContact))) { 1098 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f), 1099 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1100 1101 }//if 1102 if(dCollide(this->ODE_Geom_IDs[i],RayZNeg, 1, &contact[0].geom, sizeof(dContact))) { 1103 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent, worldEntity, Vector(0.0f, 0.0f, 1.0f), 1104 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 1105 1106 }//if 1107 1108 1109 }//if 1110 1111 } //if 1112 } //for 1113 1114 dGeomDestroy(RayX); 1115 dGeomDestroy(RayY); 1116 dGeomDestroy(RayZ); 1117 dGeomDestroy(RayXPos); 1118 dGeomDestroy(RayYPos); 1119 dGeomDestroy(RayZPos); 1120 dGeomDestroy(RayXNeg); 1121 dGeomDestroy(RayYNeg); 1122 dGeomDestroy(RayZNeg); 1123 1124 dGeomDestroy(BBOX); 1125 } // if(bbox != 0) 1126 } 1147 1127 1148 1128
Note: See TracChangeset
for help on using the changeset viewer.