Changeset 9919 in orxonox.OLD for branches/ODE
- Timestamp:
- Nov 5, 2006, 9:07:04 PM (18 years ago)
- Location:
- branches/ODE
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ODE/configure.ac
r9905 r9919 304 304 #-----# 305 305 AX_CHECK_REQUIRED_HEADER_LIB([ode/ode.h],[ode],[main],,,[http://www.ode.org]) 306 306 307 307 308 308 ;; -
branches/ODE/src/lib/graphics/importer/bsp_file.cc
r9869 r9919 39 39 // STL Containers 40 40 #include <vector> 41 42 #include<ode/ode.h> 41 43 42 44 … … 332 334 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 333 335 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; 336 337 this->ODE_Geometry = new dTriMeshDataID[this->numPatches*7*7]; 338 this->ODE_Geom_IDs = new dGeomID[this->numPatches* 7 *7]; 339 334 340 335 341 PRINTF(4)("BSP FILE:NumberOfPatches: %i . \n", numPatches); … … 729 735 */ 730 736 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 731 745 732 746 void BspFile::tesselate(int iface) … … 877 891 } 878 892 879 // Create indices893 // Create indices 880 894 GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; 881 895 … … 888 902 } 889 903 } 904 905 this->ODE_Geometry[this->patchOffset] = dGeomTriMeshDataCreate(); 906 // Create ODE Triangle Mesh Geometry 907 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) ); 890 908 891 909 -
branches/ODE/src/lib/graphics/importer/bsp_file.h
r9003 r9919 19 19 20 20 #include <vector> 21 #include <ode/ode.h> 22 21 23 class SDL_Surface; 22 24 class BspTreeNode; … … 86 88 { 87 89 int texture; //!< Texture index. 88 int effect; //!< Index into lump 12 (Effects), or -1.90 int effect; //!< Index into lump #include <ode/ode.h>12 (Effects), or -1. 89 91 int type; //!< Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard 90 92 int vertex; //!< Index of first vertex. … … 159 161 AMat loadMat( char* mat ); 160 162 AMat loadAVI(char * mat); 163 dTriMeshDataID* getODE_Geometry(void) {return this->ODE_Geometry;} 161 164 162 165 … … 215 218 216 219 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 220 221 dTriMeshDataID* ODE_Geometry; //!< ODE Geometry Data for patches 222 dGeomID* ODE_Geom_IDs; //!< IDs of ODE Geometry Data 217 223 }; 218 224 -
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 -
branches/ODE/src/lib/graphics/importer/bsp_manager.h
r9110 r9919 26 26 #include <vector> 27 27 #include <deque> 28 #include <ode/ode.h> 28 29 29 30 … … 136 137 137 138 int tgl; 139 140 dWorldID world; 141 dSpaceID space; 142 dJointGroupID contactgroup; 143 dContact contact[300]; 144 dGeomID* ODE_Geom_IDs; //!< IDs of ODE Geometry Data 145 138 146 }; 139 147 -
branches/ODE/src/lib/graphics/importer/static_model.h
r9869 r9919 61 61 void acquireData(const StaticModelData::Pointer& data); 62 62 const StaticModelData::Pointer& dataPointer() const { return this->data; }; 63 //StaticModelData* dataPointer(){return this->data;}; 63 64 64 65 inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); }; -
branches/ODE/src/lib/graphics/text_engine/text_engine.cc
r9869 r9919 86 86 void TextEngine::enableFonts() 87 87 { 88 if ( !TTF_WasInit())88 if (false /*!TTF_WasInit()*/) 89 89 { 90 90 if(TTF_Init()==-1) … … 102 102 void TextEngine::disableFonts() 103 103 { 104 if ( TTF_WasInit())104 if (false /*TTF_WasInit()*/) 105 105 { 106 106 // Font::removeDefaultFont(); … … 141 141 SDL_version compile_version; 142 142 SDL_version link_version; 143 TTF_VERSION(&compile_version);144 link_version = *TTF_Linked_Version();143 //TTF_VERSION(&compile_version); 144 // link_version = *TTF_Linked_Version(); 145 145 146 146 if (compile_version.major == link_version.major && -
branches/ODE/src/world_entities/creatures/fps_player.cc
r9869 r9919 39 39 40 40 #include "shared_network_data.h" 41 #include "terrain.h" 41 42 42 43 … … 167 168 168 169 //subscribe to collision reaction 169 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 170 //this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 171 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, Terrain::staticClassID()); 170 172 171 173 this->initWeapon = false; -
branches/ODE/src/world_entities/npcs/generic_npc.cc
r9869 r9919 32 32 33 33 #include "bsp_entity.h" 34 #include "terrain.h" 34 35 35 36 #include "class_id_DEPRECATED.h" … … 96 97 97 98 // collision reaction registration 98 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 99 //this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 100 this->subscribeReaction(CREngine::CR_PHYSICS_FULL_WALK, Terrain::staticClassID()); 99 101 } 100 102 -
branches/ODE/src/world_entities/terrain.cc
r9877 r9919 24 24 25 25 #include "model.h" 26 #include "static_model.h" 27 #include "static_model_data.h" 26 28 #include "network_game_manager.h" 27 29 … … 33 35 #include "state.h" 34 36 #include "debug.h" 37 #include "aabb.h" 38 #include "cr_defs.h" 39 #include "cd_engine.h" 35 40 36 41 #include "class_id_DEPRECATED.h" 42 #include <ode/ode.h> 37 43 ObjectListDefinitionID(Terrain, CL_TERRAIN); 38 44 CREATE_FACTORY(Terrain); … … 43 49 Terrain::Terrain (const TiXmlElement* root) 44 50 { 51 this->loaded = false; 45 52 this->init(); 46 53 … … 49 56 this->loadParams(root); 50 57 58 59 if(this->getModel()) 60 { 61 62 StaticModelData::Pointer ModelData = ((StaticModel*)this->getModel())->dataPointer(); 63 //ModelData->buildTriangleList(); 64 65 PRINTF(0)(" Dieses Model hat %i Vertices \n", ModelData->getVertices().size()); 66 PRINTF(0)(" Dieses Model hat %i Dreiecke \n",((ModelData->getTriangles()).size() )); 67 this->Ind = new unsigned int [(ModelData->getTriangles()).size()*3]; 68 for(int i = 0 ; i < (ModelData->getTriangles()).size(); i++) 69 { 70 Ind[3*i] = (ModelData->getTrianglesExt())[i].indexToVertices[0] / 3 ; 71 Ind[3*i +1] = (ModelData->getTrianglesExt())[i].indexToVertices[1] / 3; 72 Ind[3*i +2] = (ModelData->getTrianglesExt())[i].indexToVertices[2] / 3; 73 74 } 75 76 //((StaticModel*)(this->getModel()))->acquireData(ModelData); 77 this->ODE_Geometry = dGeomTriMeshDataCreate(); 78 dGeomTriMeshDataBuildSingle(this->ODE_Geometry,&((ModelData->getVertices())[0]), 3*sizeof(float),(ModelData->getVertices().size() /3 ) , &Ind[0] ,((ModelData->getTriangles()).size() *3 ), 3*sizeof(unsigned int) ); 79 // Create ODE-Data here! 80 81 this->world = dWorldCreate(); 82 this->space = dSimpleSpaceCreate(0); 83 84 //!fixme 85 for (int i=0; i<30; i++) { 86 contact[i].surface.mode = dContactBounce | dContactSoftCFM; 87 contact[i].surface.mu = dInfinity; 88 contact[i].surface.mu2 = 0; 89 contact[i].surface.bounce = 0.1; 90 contact[i].surface.bounce_vel = 0.1; 91 contact[i].surface.soft_cfm = 0.01; 92 } 93 94 contactgroup = dJointGroupCreate (0); 95 dWorldSetGravity (world,0,0,-0.5); 96 dWorldSetCFM (world,1e-5); 97 98 this->ODE_Geom_ID = dCreateTriMesh(space,this->ODE_Geometry,0 , 0, 0); 99 100 101 CDEngine::getInstance()->setTerrain(this); 102 this->loaded = true; 103 this->toList(OM_ENVIRON); 104 } 51 105 // if (this->model != NULL) 52 106 //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); … … 62 116 Terrain::Terrain(const std::string& fileName) 63 117 { 118 this->loaded = false; 64 119 this->init(); 65 120 … … 67 122 { 68 123 this->loadModel(fileName); 124 125 69 126 } 70 127 else … … 112 169 113 170 this->heightMapMaterial = new Material(); 171 172 114 173 } 115 174 … … 428 487 return 0; 429 488 } 489 490 void Terrain::go() 491 { 492 PRINTF(0)("It's me! :-)"); 493 } 494 495 void Terrain::checkCollisionTerrain(WorldEntity* worldEntity) { 496 if(!this->loaded) return; 497 498 AABB* box = worldEntity->getModelAABB(); 499 dReal aabbox [6]; 500 501 if( box != NULL) 502 { 503 504 dGeomID RayX = dCreateRay(space,box->halfLength[0] *2.0f); 505 dGeomRaySet (RayX, worldEntity->getAbsCoor().x - box->halfLength[0] ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 506 1.0f, 0.0f, 0.0f); 507 dGeomID RayY = dCreateRay(space,box->halfLength[1] *2.0f); 508 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y - box->halfLength[1], worldEntity->getAbsCoor().z, 509 0.0f, 1.0f, 0.0f); 510 dGeomID RayZ = dCreateRay(space,box->halfLength[2] *2.0f); 511 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z - box->halfLength[2], 512 0.0f, 0.0f, 1.0f); 513 514 dGeomID RayXPos = dCreateRay(space,box->halfLength[0]); 515 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 516 1.0f, 0.0f, 0.0f); 517 dGeomID RayYPos = dCreateRay(space,box->halfLength[1] ); 518 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 519 0.0f, 1.0f, 0.0f); 520 dGeomID RayZPos = dCreateRay(space,box->halfLength[2] ); 521 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 522 0.0f, 0.0f, 1.0f); 523 524 dGeomID RayXNeg = dCreateRay(space,box->halfLength[0] * 40.0f ); 525 dGeomRaySet (RayX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z, 526 -1.0f, 0.0f, 0.0f); 527 dGeomID RayYNeg = dCreateRay(space,box->halfLength[1] ); 528 dGeomRaySet (RayY, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y , worldEntity->getAbsCoor().z, 529 0.0f, -1.0f, 0.0f); 530 dGeomID RayZNeg = dCreateRay(space,box->halfLength[2] ); 531 dGeomRaySet (RayZ, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z , 532 0.0f, 0.0f, -1.0f); 533 534 535 dGeomID BBOX = dCreateBox (space,box->halfLength[0]*2.0f, box->halfLength[1]*40.0f ,2.0f* box->halfLength[2]); 536 //dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x ,worldEntity->getAbsCoor().y, worldEntity->getAbsCoor().z); 537 dGeomSetPosition (BBOX, worldEntity->getAbsCoor().x + box->center.x ,worldEntity->getAbsCoor().y+box->center.y, worldEntity->getAbsCoor().z+box->center.z); 538 539 540 541 542 int g; 543 bool collision = false; 544 545 546 // dGeomGetAABB (this->bspFile->ODE_Geom_IDs[i],aabbox ); 547 // BBOX2 = dCreateBox (space, aabbox[1]-aabbox[0], aabbox[3]-aabbox[2], aabbox[5]-aabbox[4]); 548 // dGeomSetPosition (BBOX2,(aabbox[1]+ aabbox[0])/2, (aabbox[3]+ aabbox[2])/2, (aabbox[4]+ aabbox[5])/2); 549 // dGeomDestroy(BBOX2); 550 g = 0; 551 if(true || dCollide(this->ODE_Geom_ID,BBOX, 10, &contact[0].geom, sizeof(dContact)) ) { 552 553 //PRINTF(0)("Collision \n"); 554 for(int i = 0; i <1 ; i++) 555 { 556 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 557 // Vector(contact[i].geom.pos[0],contact[i].geom.pos[1],contact[i].geom.pos[2]), false); 558 } 559 560 if(dCollide(this->ODE_Geom_ID,RayX, 1, &contact[0].geom, sizeof(dContact))) { 561 if(dCollide(this->ODE_Geom_ID,RayXPos, 1, &contact[0].geom, sizeof(dContact))) { 562 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), 563 Vector((float)contact[0].geom.pos[0],(float)contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 564 565 }//if 566 if(dCollide(this->ODE_Geom_ID,RayXNeg, 1, &contact[0].geom, sizeof(dContact))) { 567 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X_NEG , this, worldEntity, Vector(1.0f, 0.0f, 0.0f), 568 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 569 570 }//if 571 }//if 572 573 574 if(dCollide(this->ODE_Geom_ID,RayY, 1, &contact[0].geom, sizeof(dContact))) { 575 576 577 if(dCollide(this->ODE_Geom_ID,RayYNeg, 1, &contact[0].geom, sizeof(dContact))) { 578 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 579 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 580 581 582 }//if 583 else if(dCollide(this->ODE_Geom_ID,RayYPos, 1, &contact[0].geom, sizeof(dContact))) { 584 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 585 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1] ,contact[0].geom.pos[2]), false); 586 587 }//if 588 else { 589 590 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this, worldEntity, Vector(0.0f, 1.0f, 0.0f), 591 Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 592 593 } 594 595 }//if 596 597 if(dCollide(this->ODE_Geom_ID,RayZ, 1, &contact[0].geom, sizeof(dContact))) { 598 if(dCollide(this->ODE_Geom_ID,RayZPos, 1, &contact[0].geom, sizeof(dContact))) { 599 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 600 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 601 602 }//if 603 if(dCollide(this->ODE_Geom_ID,RayZNeg, 1, &contact[0].geom, sizeof(dContact))) { 604 // worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this, worldEntity, Vector(0.0f, 0.0f, 1.0f), 605 // Vector(contact[0].geom.pos[0],contact[0].geom.pos[1],contact[0].geom.pos[2]), false); 606 607 }//if 608 609 610 }//if 611 612 } //if 613 614 615 dGeomDestroy(RayX); 616 dGeomDestroy(RayY); 617 dGeomDestroy(RayZ); 618 dGeomDestroy(RayXPos); 619 dGeomDestroy(RayYPos); 620 dGeomDestroy(RayZPos); 621 dGeomDestroy(RayXNeg); 622 dGeomDestroy(RayYNeg); 623 dGeomDestroy(RayZNeg); 624 625 dGeomDestroy(BBOX); 626 } // if(bbox != 0) 627 628 } -
branches/ODE/src/world_entities/terrain.h
r9869 r9919 12 12 13 13 #include "world_entity.h" 14 #include <ode/ode.h> 14 15 15 16 // FORWARD DECLARATION … … 26 27 { 27 28 ObjectListDeclaration(Terrain); 28 29 29 30 public: 30 31 Terrain(const TiXmlElement* root = NULL); … … 32 33 Terrain(DebugTerrain debugTerrain); 33 34 virtual ~Terrain(); 35 36 void go(); 37 void checkCollisionTerrain(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BspEntity. 38 If a collision has been detected, the collides-function of worldEntity will be called.*/ 34 39 35 40 void init(); … … 53 58 Model* vegetation; 54 59 int modelList; 55 60 bool loaded; 56 61 HeightMap* heightMap; 57 62 Material* heightMapMaterial; 58 63 Vector terrainScale; 64 unsigned int* Ind; 65 66 dTriMeshDataID ODE_Geometry; //!< ODE Geometry Data of the static model 67 dGeomID ODE_Geom_ID; //!< ID of ODE Geometry Data 68 dWorldID world; 69 dSpaceID space; 70 dJointGroupID contactgroup; 71 dContact contact[300]; 59 72 }; 60 73
Note: See TracChangeset
for help on using the changeset viewer.