[4597] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[3565] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
[5357] | 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[1853] | 16 | |
---|
| 17 | |
---|
[3559] | 18 | #include "terrain.h" |
---|
[4607] | 19 | |
---|
[9869] | 20 | #include "util/loading/resource_manager.h" |
---|
[7193] | 21 | #include "util/loading/load_param.h" |
---|
| 22 | #include "util/loading/factory.h" |
---|
[4842] | 23 | #include "spatial_separation.h" |
---|
| 24 | |
---|
[5511] | 25 | #include "model.h" |
---|
[9919] | 26 | #include "static_model.h" |
---|
| 27 | #include "static_model_data.h" |
---|
[6341] | 28 | #include "network_game_manager.h" |
---|
[5465] | 29 | |
---|
[6956] | 30 | #include "height_map.h" |
---|
| 31 | #include "material.h" |
---|
[6341] | 32 | |
---|
[5511] | 33 | #include "glincl.h" |
---|
| 34 | |
---|
[6956] | 35 | #include "state.h" |
---|
[9869] | 36 | #include "debug.h" |
---|
[9919] | 37 | #include "aabb.h" |
---|
| 38 | #include "cr_defs.h" |
---|
| 39 | #include "cd_engine.h" |
---|
[6956] | 40 | |
---|
[9869] | 41 | #include "class_id_DEPRECATED.h" |
---|
[9919] | 42 | #include <ode/ode.h> |
---|
[9869] | 43 | ObjectListDefinitionID(Terrain, CL_TERRAIN); |
---|
| 44 | CREATE_FACTORY(Terrain); |
---|
[1853] | 45 | |
---|
[3245] | 46 | /** |
---|
[4836] | 47 | * standard constructor |
---|
[5357] | 48 | */ |
---|
[4607] | 49 | Terrain::Terrain (const TiXmlElement* root) |
---|
[3365] | 50 | { |
---|
[9919] | 51 | this->loaded = false; |
---|
[3564] | 52 | this->init(); |
---|
[7055] | 53 | |
---|
| 54 | |
---|
[6695] | 55 | if( root != NULL) |
---|
| 56 | this->loadParams(root); |
---|
[4844] | 57 | |
---|
[9919] | 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 | } |
---|
[7221] | 105 | // if (this->model != NULL) |
---|
| 106 | //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f); |
---|
[3365] | 107 | } |
---|
[1853] | 108 | |
---|
[4855] | 109 | |
---|
[3564] | 110 | /** |
---|
[4836] | 111 | * Constructor for loading a Terrain out of a file |
---|
| 112 | * @param fileName The file to load data from. |
---|
[4597] | 113 | |
---|
[3566] | 114 | this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. |
---|
| 115 | */ |
---|
[7221] | 116 | Terrain::Terrain(const std::string& fileName) |
---|
[3566] | 117 | { |
---|
[9919] | 118 | this->loaded = false; |
---|
[3566] | 119 | this->init(); |
---|
| 120 | |
---|
[8316] | 121 | if (fileName.rfind(".obj" ) != std::string::npos || fileName.rfind(".OBJ") != std::string::npos ) |
---|
[7221] | 122 | { |
---|
| 123 | this->loadModel(fileName); |
---|
[9919] | 124 | |
---|
| 125 | |
---|
[7221] | 126 | } |
---|
[3566] | 127 | else |
---|
[7221] | 128 | { |
---|
| 129 | // load the hightMap here. |
---|
| 130 | } |
---|
[3566] | 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
[4836] | 134 | * a Constructor for the Debug-Worlds |
---|
[5308] | 135 | */ |
---|
[3564] | 136 | Terrain::Terrain(DebugTerrain debugTerrain) |
---|
| 137 | { |
---|
| 138 | this->init(); |
---|
| 139 | this->buildDebugTerrain(debugTerrain); |
---|
| 140 | } |
---|
| 141 | |
---|
[3245] | 142 | /** |
---|
[4836] | 143 | * standard deconstructor |
---|
[1853] | 144 | |
---|
[3245] | 145 | */ |
---|
[4746] | 146 | Terrain::~Terrain () |
---|
[3543] | 147 | { |
---|
[9869] | 148 | if (modelList) |
---|
| 149 | glDeleteLists(this->modelList, 1); |
---|
[4889] | 150 | if( this->ssp) |
---|
| 151 | delete ssp; |
---|
[6956] | 152 | |
---|
| 153 | if(this->heightMap) |
---|
[7221] | 154 | delete heightMap; |
---|
[3543] | 155 | } |
---|
[1853] | 156 | |
---|
[3245] | 157 | |
---|
[4746] | 158 | void Terrain::init() |
---|
[3559] | 159 | { |
---|
[9869] | 160 | this->registerObject(this, Terrain::_objectList); |
---|
[6142] | 161 | this->toList(OM_ENVIRON_NOTICK); |
---|
[8037] | 162 | this->toReflectionList(); |
---|
[4597] | 163 | |
---|
[9869] | 164 | this->modelList = 0; |
---|
[5308] | 165 | this->ssp = NULL; |
---|
[5465] | 166 | this->vegetation = NULL; |
---|
[6956] | 167 | |
---|
| 168 | this->heightMap = NULL; |
---|
[7055] | 169 | |
---|
| 170 | this->heightMapMaterial = new Material(); |
---|
[9919] | 171 | |
---|
| 172 | |
---|
[3559] | 173 | } |
---|
| 174 | |
---|
[4924] | 175 | |
---|
[4607] | 176 | void Terrain::loadParams(const TiXmlElement* root) |
---|
| 177 | { |
---|
[6512] | 178 | WorldEntity::loadParams(root); |
---|
[3559] | 179 | |
---|
[7046] | 180 | LoadParam(root, "scale", this, Terrain, setScale) |
---|
[7221] | 181 | .describe("The scale in x,y,z direction"); |
---|
[7046] | 182 | |
---|
| 183 | LoadParam(root, "texture", this, Terrain, loadTexture) |
---|
[7221] | 184 | .describe("The name of the Texture for this heightMap"); |
---|
[7046] | 185 | |
---|
[5671] | 186 | LoadParam(root, "vegetation", this, Terrain, loadVegetation) |
---|
[7221] | 187 | .describe("the fileName of the vegetation, that should be loaded onto this terrain. (must be relative to the data-dir)") ; |
---|
[6956] | 188 | |
---|
| 189 | LoadParam(root, "height-map", this, Terrain, loadHeightMap) |
---|
[7221] | 190 | .describe("The HeightMap, splitted into two strings seperated by ','. 1: HeighMap, 2: ColorMap"); |
---|
[6956] | 191 | |
---|
[7046] | 192 | } |
---|
[6956] | 193 | |
---|
[7046] | 194 | void Terrain::setScale(float x, float y, float z) |
---|
| 195 | { |
---|
| 196 | this->terrainScale = Vector(x, y, z); |
---|
[4607] | 197 | } |
---|
| 198 | |
---|
[7221] | 199 | void Terrain::loadHeightMap(const std::string& heightMapFile, const std::string& colorMap) |
---|
[6956] | 200 | { |
---|
| 201 | if (this->heightMap != NULL) |
---|
| 202 | delete this->heightMap; |
---|
| 203 | this->heightMap = NULL; |
---|
| 204 | |
---|
[9869] | 205 | std::string hmName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(heightMapFile); |
---|
| 206 | std::string hmColorName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(colorMap); |
---|
[6956] | 207 | |
---|
| 208 | |
---|
| 209 | this->heightMap = new HeightMap(hmName, hmColorName); |
---|
[7221] | 210 | // heightMap->scale(Vector(43.0f,4.7f,43.0f)); |
---|
[7046] | 211 | heightMap->scale(this->terrainScale); |
---|
[6956] | 212 | heightMap->setAbsCoor(this->getAbsCoor()); |
---|
| 213 | heightMap->load(); |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | |
---|
[7221] | 217 | void Terrain::loadTexture(const std::string& textureName) |
---|
[6956] | 218 | { |
---|
[7221] | 219 | PRINTF(4)("Load texture: %s\n", textureName.c_str()); |
---|
[7046] | 220 | |
---|
[7221] | 221 | heightMapMaterial->setDiffuse(1.0,1.0,1.0); |
---|
| 222 | heightMapMaterial->setAmbient(1.0,1.0,1.0 ); |
---|
| 223 | heightMapMaterial->setSpecular(1.0,1.0,1.0); |
---|
| 224 | heightMapMaterial->setShininess(.5); |
---|
| 225 | heightMapMaterial->setTransparency(1.0); |
---|
[6956] | 226 | |
---|
[7221] | 227 | heightMapMaterial->setDiffuseMap(textureName); |
---|
| 228 | // heightMapMaterial->setAmbientMap(textureName); |
---|
| 229 | // heightMapMaterial->setSpecularMap(textureName); |
---|
[6956] | 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | |
---|
[7221] | 234 | void Terrain::loadVegetation(const std::string& vegetationFile) |
---|
[5465] | 235 | { |
---|
[7221] | 236 | PRINTF(4)("loadVegetation: %s\n", vegetationFile.c_str()); |
---|
[5465] | 237 | if (this->vegetation) |
---|
[9869] | 238 | this->vegetation = 0; |
---|
[7221] | 239 | if (!vegetationFile.empty()) |
---|
[5465] | 240 | { |
---|
[7221] | 241 | PRINTF(4)("fetching %s\n", vegetationFile.c_str()); |
---|
[9869] | 242 | this->loadModel(vegetationFile, 1.0, 2); |
---|
| 243 | this->vegetation = this->getModel(2); |
---|
[5465] | 244 | } |
---|
| 245 | else |
---|
| 246 | this->vegetation = NULL; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | |
---|
[6956] | 251 | |
---|
| 252 | |
---|
[5500] | 253 | void Terrain::draw () const |
---|
[4597] | 254 | { |
---|
[3559] | 255 | glPushMatrix(); |
---|
[4597] | 256 | |
---|
[3559] | 257 | /* translate */ |
---|
[4597] | 258 | glTranslatef (this->getAbsCoor ().x, |
---|
| 259 | this->getAbsCoor ().y, |
---|
| 260 | this->getAbsCoor ().z); |
---|
[3559] | 261 | /* rotate */ |
---|
[7221] | 262 | // Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
[6956] | 263 | //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[3559] | 264 | |
---|
[9869] | 265 | if (this->modelList) |
---|
| 266 | glCallList(this->modelList); |
---|
[5994] | 267 | else if (this->getModel()) |
---|
| 268 | this->getModel()->draw(); |
---|
[7046] | 269 | |
---|
[5465] | 270 | if (this->vegetation) |
---|
| 271 | this->vegetation->draw(); |
---|
[6956] | 272 | |
---|
[7046] | 273 | if( this->heightMap) |
---|
| 274 | { |
---|
| 275 | this->heightMapMaterial->select(); |
---|
| 276 | |
---|
| 277 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
| 278 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
---|
| 279 | this->heightMap->draw(); |
---|
| 280 | } |
---|
[3559] | 281 | glPopMatrix(); |
---|
[4904] | 282 | |
---|
[6956] | 283 | |
---|
[7221] | 284 | /* |
---|
| 285 | glMatrixMode(GL_MODELVIEW); |
---|
| 286 | glPushMatrix(); |
---|
| 287 | glLoadIdentity(); |
---|
| 288 | Vector camera = State::getCameraNode()->getAbsCoor(); // Go on here ..........!!! |
---|
[6956] | 289 | |
---|
[7221] | 290 | float height = heightMap->getHeight(camera.x, camera.z); |
---|
[6956] | 291 | |
---|
[7221] | 292 | glEnable (GL_COLOR_MATERIAL) ; |
---|
| 293 | glBegin(GL_QUADS); // Draw The Cube Using quads |
---|
| 294 | glColor3f(0.0f,1.0f,0.0f); // Color Blue |
---|
| 295 | glVertex3f(camera.x + 63.0f,Terrain->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Right Of The Quad (Top) |
---|
| 296 | glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f); // Top Left Of The Quad (Top) |
---|
| 297 | glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Left Of The Quad (Top) |
---|
| 298 | glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f); // Bottom Right Of The Quad (Top) |
---|
| 299 | glEnd(); // End Drawing The Plan |
---|
[6956] | 300 | |
---|
[7221] | 301 | glPopMatrix();*/ |
---|
[6956] | 302 | |
---|
| 303 | |
---|
[7221] | 304 | /* THIS IS ONLY FOR DEBUGGING INFORMATION */ |
---|
[9877] | 305 | // if (this->ssp != NULL) |
---|
| 306 | // this->ssp->drawQuadtree(); |
---|
[3559] | 307 | } |
---|
[3564] | 308 | |
---|
| 309 | |
---|
| 310 | void Terrain::buildDebugTerrain(DebugTerrain debugTerrain) |
---|
| 311 | { |
---|
| 312 | // if the terrain is the Terrain of Dave |
---|
| 313 | if (debugTerrain == TERRAIN_DAVE) |
---|
[7221] | 314 | { |
---|
[9869] | 315 | modelList = glGenLists(1); |
---|
| 316 | glNewList (modelList, GL_COMPILE); |
---|
[4597] | 317 | |
---|
[7221] | 318 | glColor3f(1.0,0,0); |
---|
[4597] | 319 | |
---|
[7221] | 320 | int sizeX = 100; |
---|
| 321 | int sizeZ = 80; |
---|
| 322 | float length = 1000; |
---|
| 323 | float width = 200; |
---|
| 324 | float widthX = float (length /sizeX); |
---|
| 325 | float widthZ = float (width /sizeZ); |
---|
[4597] | 326 | |
---|
[7221] | 327 | float height [sizeX][sizeZ]; |
---|
| 328 | Vector normal_vectors[sizeX][sizeZ]; |
---|
[4597] | 329 | |
---|
| 330 | |
---|
[7221] | 331 | for ( int i = 0; i<sizeX-1; i+=1) |
---|
| 332 | for (int j = 0; j<sizeZ-1;j+=1) |
---|
| 333 | //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; |
---|
[3564] | 334 | #ifdef __WIN32__ |
---|
[7221] | 335 | height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; |
---|
[3564] | 336 | #else |
---|
[7221] | 337 | height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; |
---|
[3564] | 338 | #endif |
---|
[4597] | 339 | |
---|
[7221] | 340 | //Die Huegel ein wenig glaetten |
---|
| 341 | for (int h=1; h<2;h++) |
---|
| 342 | for (int i=1;i<sizeX-2 ;i+=1 ) |
---|
| 343 | for(int j=1;j<sizeZ-2;j+=1) |
---|
| 344 | height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; |
---|
[4597] | 345 | |
---|
[7221] | 346 | //Berechnung von normalen Vektoren |
---|
| 347 | for(int i=1;i<sizeX-2;i+=1) |
---|
| 348 | for(int j=1;j<sizeZ-2 ;j+=1) |
---|
| 349 | { |
---|
| 350 | Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); |
---|
| 351 | Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); |
---|
| 352 | Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); |
---|
| 353 | Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); |
---|
| 354 | Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); |
---|
[4597] | 355 | |
---|
[7221] | 356 | Vector c1 = v2 - v1; |
---|
| 357 | Vector c2 = v3 - v1; |
---|
| 358 | Vector c3= v4 - v1; |
---|
| 359 | Vector c4 = v5 - v1; |
---|
| 360 | Vector zero = Vector (0,0,0); |
---|
| 361 | normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); |
---|
| 362 | normal_vectors[i][j].normalize(); |
---|
| 363 | } |
---|
[4597] | 364 | |
---|
[7221] | 365 | glBegin(GL_QUADS); |
---|
| 366 | int snowheight=3; |
---|
| 367 | for ( int i = 0; i<sizeX; i+=1) |
---|
| 368 | for (int j = 0; j<sizeZ;j+=1) |
---|
| 369 | { |
---|
| 370 | Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); |
---|
| 371 | Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); |
---|
| 372 | Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); |
---|
| 373 | Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); |
---|
| 374 | float a[3]; |
---|
| 375 | if(height[i][j]<snowheight) |
---|
| 376 | { |
---|
| 377 | a[0]=0; |
---|
| 378 | a[1]=1.0-height[i][j]/10-.3; |
---|
| 379 | a[2]=0; |
---|
| 380 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 381 | } |
---|
| 382 | else |
---|
| 383 | { |
---|
| 384 | a[0]=1.0; |
---|
| 385 | a[1]=1.0; |
---|
| 386 | a[2]=1.0; |
---|
| 387 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[4597] | 388 | |
---|
[7221] | 389 | } |
---|
| 390 | glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); |
---|
| 391 | glVertex3f(v1.x, v1.y, v1.z); |
---|
| 392 | if(height[i+1][j]<snowheight) |
---|
| 393 | { |
---|
| 394 | a[0]=0; |
---|
| 395 | a[1] =1.0-height[i+1][j]/10-.3; |
---|
| 396 | a[2]=0; |
---|
| 397 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 398 | } |
---|
| 399 | else |
---|
| 400 | { |
---|
| 401 | a[0]=1.0; |
---|
| 402 | a[1]=1.0; |
---|
| 403 | a[2]=1.0; |
---|
| 404 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[4597] | 405 | |
---|
[7221] | 406 | } |
---|
| 407 | glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); |
---|
| 408 | glVertex3f(v2.x, v2.y, v2.z); |
---|
| 409 | if(height[i+1][j+1]<snowheight) |
---|
| 410 | { |
---|
| 411 | a[0]=0; |
---|
| 412 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 413 | a[2]=0; |
---|
| 414 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | a[0]=1.0; |
---|
| 419 | a[1]=1.0; |
---|
| 420 | a[2]=1.0; |
---|
| 421 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
[4597] | 422 | |
---|
| 423 | |
---|
[7221] | 424 | } |
---|
| 425 | glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); |
---|
| 426 | glVertex3f(v3.x, v3.y, v3.z); |
---|
| 427 | if(height[i][j+1]<snowheight) |
---|
| 428 | { |
---|
| 429 | a[0]=0; |
---|
| 430 | a[1] =1.0-height[i+1][j+1]/10-.3; |
---|
| 431 | a[2]=0; |
---|
| 432 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 433 | } |
---|
| 434 | else |
---|
| 435 | { |
---|
| 436 | a[0]=1.0; |
---|
| 437 | a[1]=1.0; |
---|
| 438 | a[2]=1.0; |
---|
| 439 | glMaterialfv(GL_FRONT,GL_DIFFUSE,a); |
---|
| 440 | } |
---|
| 441 | glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); |
---|
| 442 | glVertex3f(v4.x, v4.y, v4.z); |
---|
[4597] | 443 | |
---|
[7221] | 444 | } |
---|
| 445 | glEnd(); |
---|
| 446 | glEndList(); |
---|
| 447 | } |
---|
[3564] | 448 | |
---|
| 449 | if (debugTerrain == TERRAIN_BENSCH) |
---|
[7221] | 450 | { |
---|
| 451 | /* |
---|
| 452 | this->model = (OBJModel*) new Model(); |
---|
| 453 | this->model->setName("CUBE"); |
---|
| 454 | this->model->addVertex (-0.5, -0.5, 0.5); |
---|
| 455 | this->model->addVertex (0.5, -0.5, 0.5); |
---|
| 456 | this->model->addVertex (-0.5, 0.5, 0.5); |
---|
| 457 | this->model->addVertex (0.5, 0.5, 0.5); |
---|
| 458 | this->model->addVertex (-0.5, 0.5, -0.5); |
---|
| 459 | this->model->addVertex (0.5, 0.5, -0.5); |
---|
| 460 | this->model->addVertex (-0.5, -0.5, -0.5); |
---|
| 461 | this->model->addVertex (0.5, -0.5, -0.5); |
---|
[4597] | 462 | |
---|
[7221] | 463 | this->model->addVertexTexture (0.0, 0.0); |
---|
| 464 | this->model->addVertexTexture (1.0, 0.0); |
---|
| 465 | this->model->addVertexTexture (0.0, 1.0); |
---|
| 466 | this->model->addVertexTexture (1.0, 1.0); |
---|
| 467 | this->model->addVertexTexture (0.0, 2.0); |
---|
| 468 | this->model->addVertexTexture (1.0, 2.0); |
---|
| 469 | this->model->addVertexTexture (0.0, 3.0); |
---|
| 470 | this->model->addVertexTexture (1.0, 3.0); |
---|
| 471 | this->model->addVertexTexture (0.0, 4.0); |
---|
| 472 | this->model->addVertexTexture (1.0, 4.0); |
---|
| 473 | this->model->addVertexTexture (2.0, 0.0); |
---|
| 474 | this->model->addVertexTexture (2.0, 1.0); |
---|
| 475 | this->model->addVertexTexture (-1.0, 0.0); |
---|
| 476 | this->model->addVertexTexture (-1.0, 1.0); |
---|
[3564] | 477 | |
---|
[7221] | 478 | this->model->finalize(); |
---|
| 479 | */ |
---|
| 480 | } |
---|
[3564] | 481 | } |
---|
[6341] | 482 | |
---|
[6956] | 483 | float Terrain::getHeight(float x, float y) |
---|
| 484 | { |
---|
[7221] | 485 | if(this->heightMap != NULL) |
---|
| 486 | return (this->heightMap->getHeight(x, y)); |
---|
| 487 | return 0; |
---|
[6956] | 488 | } |
---|
[9919] | 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 | } |
---|