Changeset 6939 in orxonox.OLD for branches/height_map_merge/src/lib/graphics
- Timestamp:
- Feb 1, 2006, 2:54:01 PM (19 years ago)
- Location:
- branches/height_map_merge/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map_merge/src/lib/graphics/importer/height_map.cc
r6745 r6939 56 56 // This Draws the LOD's 57 57 //FIXME 58 float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(0.0,100.0,0.0)).len(); 59 if (cameraDistance > 10000 ) 58 float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(this->x, hmref->offsetY , this->z) ).len(); 59 if(cameraDistance < 0) cameraDistance = -cameraDistance; 60 if(cameraDistance > 5000 ) 60 61 { 61 62 return; 62 63 } 63 else if (cameraDistance >= 50000 )64 else if (cameraDistance >= 1000 ) 64 65 { 65 66 this->drawLowRes(); … … 96 97 #define normalVectorField hm->normalVectorField 97 98 99 hmref = hm; // FIXME 100 101 this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX; 102 this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ; 103 98 104 int sampleRate = Res; 99 105 … … 106 112 107 113 108 PRINTF(0)("loadin * \n"); 114 109 115 110 116 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 111 117 112 118 SDL_LockSurface(heightMap); 113 119 SDL_LockSurface(hm->colourMap); 120 114 121 for(int i = i1 ; i <= i2 ; i +=sampleRate) 115 122 { … … 120 127 if(hm->hasColourMap) 121 128 { 122 r = (float)colours[3*w+2 + 3*i*(heightMap->w )];123 g = (float)colours[3*w+1 + 3*i*(heightMap->w)];124 b = (float)colours[3*w+0 + 3*i*(heightMap->w)];129 r = colours[(3*w+2 + 3*i*(heightMap->w )) ]; 130 g = colours[(3*w+1 + 3*i*(heightMap->w)) ]; 131 b = colours[(3*w+0 + 3*i*(heightMap->w))]; 125 132 } 126 133 127 134 w = j1; 128 135 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 129 model->addNormal(normalVectorField[i ][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);136 model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i % heightMap->h][w % heightMap->w].x); 130 137 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate)); 131 PRINTF(0)("shiftX %f,shiftY %f,shiftZ %f\n", shiftX, shiftY ,shiftZ);138 132 139 model->addColor(r/255.0,g/255.0,b/255.0); 133 140 … … 135 142 { 136 143 144 145 // To be fixed 146 if(hm->hasColourMap) 147 { 148 r = colours[(3*j+2 + 3*i*(heightMap->w )) ]; 149 g = colours[(3*j+1 + 3*i*(heightMap->w)) ]; 150 b = colours[(3*j+0 + 3*i*(heightMap->w))]; 151 } 152 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ]; 153 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ]; 154 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))]; 155 height += (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ]; 156 height += (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ]; 157 height=height/5.0; 158 159 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right 160 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x); 161 model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate)); 162 163 //PRINTF(0)("TexCoord: %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0); 164 165 model->addColor(r/255.0,g/255.0,b/255.0); 166 w = j; 167 } 168 169 170 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 171 model->addNormal(normalVectorField[i % heightMap->h][w % heightMap->w].y,normalVectorField[i % heightMap->h][w % heightMap->w].z,normalVectorField[i% heightMap->h][w % heightMap->w].x); 172 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate)); 173 model->addColor(r/255.0,g/255.0,b/255.0); 174 175 } 176 177 178 179 180 181 SDL_UnlockSurface(heightMap); 182 int cnt = 0; 183 for(int i = i1 ; i < i2 ; i +=sampleRate) 184 { 185 186 for(int j = j1-sampleRate ; j < j2 + 2*sampleRate ; j += sampleRate) 187 { 188 189 model->addIndice(cnt); 190 model->addIndice(cnt + (j2 -j1 + 3* sampleRate )/ sampleRate ); 191 cnt++; 192 193 } 194 195 196 197 model->newStripe(); 198 199 200 } 201 cnt += (j2 -j1 + 3* sampleRate)/ sampleRate; 202 203 for(int j = j1 ; j <= j2 ; j += sampleRate) 204 { 205 int i = i1; 206 207 // To be fixed 208 if(hm->hasColourMap) 209 { 210 r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ]; 211 g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ]; 212 b = (float)colours[(3*j+0 + 3*i*(heightMap->w))]; 213 } 214 215 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 216 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j % heightMap->w].z,normalVectorField[i % heightMap->h][j % heightMap->w].x); 217 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate)); 218 model->addColor(r/255.0,g/255.0,b/255.0); 219 220 } 221 222 for(int j = j1 ; j <= j2 ; j += sampleRate) 223 { 224 int i = i1; 225 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ]; 226 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ]; 227 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))]; 228 height += (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ]; 229 height += (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ]; 230 height=height/5.0; 231 232 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 233 model->addNormal(normalVectorField[i % heightMap->h][j % heightMap->w].y,normalVectorField[i % heightMap->h][j% heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x); 234 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate)); 235 model->addColor(r/255.0,g/255.0,b/255.0); 236 237 } 238 239 240 241 for(int j = j1 ; j <= j2 ; j += sampleRate) 242 { 243 int i = i2; 137 244 138 245 // To be fixed … … 143 250 b = (float)colours[3*j+0 + 3*i*(heightMap->w)]; 144 251 } 145 height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];146 height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];147 height += (float) (unsigned char) hm->heights[j -1+ sampleRate + (i+1)*(heightMap->w )];148 height += (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];149 height += (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];150 height=height/5.0;151 152 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right153 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);154 model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));155 156 //PRINTF(0)("TexCoord: %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);157 158 model->addColor(r/255.0,g/255.0,b/255.0);159 w = j;160 }161 162 163 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right164 model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);165 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));166 model->addColor(r/255.0,g/255.0,b/255.0);167 168 }169 170 171 172 173 174 SDL_UnlockSurface(heightMap);175 int cnt = 0;176 for(int i = i1 ; i < i2 ; i +=sampleRate)177 {178 179 for(int j = j1-sampleRate ; j < j2 + 2*sampleRate ; j += sampleRate)180 {181 182 model->addIndice(cnt);183 model->addIndice(cnt + (j2 -j1 + 3* sampleRate )/ sampleRate );184 cnt++;185 186 }187 188 189 190 model->newStripe();191 192 193 }194 cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;195 196 for(int j = j1 ; j <= j2 ; j += sampleRate)197 {198 int i = i1;199 200 // To be fixed201 if(hm->hasColourMap)202 {203 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];204 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];205 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];206 }207 252 208 253 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 209 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 210 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate)); 211 model->addColor(r/255.0,g/255.0,b/255.0); 212 213 } 214 215 for(int j = j1 ; j <= j2 ; j += sampleRate) 216 { 217 int i = i1; 218 height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )]; 219 height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )]; 220 height += (float) (unsigned char) hm->heights[j -1+ sampleRate + (i+1)*(heightMap->w )]; 221 height += (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )]; 222 height += (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )]; 223 height=height/5.0; 224 225 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 226 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 227 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate)); 228 model->addColor(r/255.0,g/255.0,b/255.0); 229 230 } 231 232 233 234 for(int j = j1 ; j <= j2 ; j += sampleRate) 235 { 236 int i = i2; 237 238 // To be fixed 239 if(hm->hasColourMap) 240 { 241 r = (float)colours[3*j+2 + 3*i*(heightMap->w )]; 242 g = (float)colours[3*j+1 + 3*i*(heightMap->w)]; 243 b = (float)colours[3*j+0 + 3*i*(heightMap->w)]; 244 } 245 246 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 247 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 254 model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x); 248 255 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate)); 249 256 model->addColor(r/255.0,g/255.0,b/255.0); … … 255 262 { 256 263 int i = i2; 257 height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];258 height += (float)(unsigned char) hm->heights[ j+ 1 + sampleRate + (i+1)*(heightMap->w )];259 height += (float) (unsigned char) hm->heights[ j -1+ sampleRate + (i+1)*(heightMap->w)];260 height += (float)(unsigned char)hm->heights[ j +sampleRate+ (i+2)*(heightMap->w)];261 height += (float)(unsigned char)hm->heights[ j+sampleRate + (i)*(heightMap->w )];264 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ]; 265 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ]; 266 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))]; 267 height += (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))]; 268 height += (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ]; 262 269 height=height/5.0; 263 270 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 264 model->addNormal(normalVectorField[i ][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);271 model->addNormal(normalVectorField[i%heightMap->h][j%heightMap->w].y,normalVectorField[i%heightMap->h][j%heightMap->w].z,normalVectorField[i%heightMap->h][j%heightMap->w].x); 265 272 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate)); 266 273 model->addColor(r/255.0,g/255.0,b/255.0); … … 302 309 303 310 311 SDL_UnlockSurface(hm->colourMap); 304 312 305 313 model->finalize(); … … 416 424 { 417 425 delete heightMap; 426 delete colourMap; 427 428 429 for(int i=0;i < heightMap->h/tileSize ; i++) 430 { 431 for(int j = 0; j < heightMap->w/ tileSize; j++) 432 { 433 delete tiles [i][j]; 434 } 435 } 436 for(int i=0;i < heightMap->h/tileSize ; i++) 437 delete[] tiles[i]; 438 delete[] tiles; 439 440 418 441 } 419 442 … … 427 450 428 451 //SetUp Arrays 429 for(int i = 0; i < (heightMap->h - tileSize)/ tileSize; i ++)430 { 431 for(int j = 0; j < (heightMap->w - tileSize)/ tileSize; j ++)452 for(int i = 0; i < (heightMap->h )/ tileSize; i ++) 453 { 454 for(int j = 0; j < (heightMap->w )/ tileSize; j ++) 432 455 { 433 456 … … 444 467 Vector v = camera->getAbsCoor(); 445 468 446 int i_min = 1;447 int i_max = (heightMap->h - tileSize)/ tileSize;448 int j_min = 1;449 int j_max= (heightMap->w - tileSize) / tileSize;450 451 452 453 for(int i = 1; i < i_max ; i ++)454 { 455 for(int j = 1; j < j_max ; j++)469 int i_min = 0; 470 int i_max = (heightMap->h )/ tileSize; 471 int j_min = 0; 472 int j_max= (heightMap->w ) / tileSize; 473 474 475 476 for(int i = 0; i < i_max ; i ++) 477 { 478 for(int j = 0; j < j_max ; j++) 456 479 { 457 480 tiles[i][j]->draw(); … … 472 495 473 496 497 498 // Initialize 499 for(int i=0; i< heightMap->h; i++) 500 { 501 for(int j = 0; j> heightMap->w; j++) 502 { 503 Vector v = Vector(0.0, 1.0, 0.0); 504 normalVectorField[i][j] = v; 505 } 506 } 507 474 508 // !!! Does not yet calculate the normals of some border points!!!!! 475 509 … … 499 533 } 500 534 535 536 537 501 538 } 502 539 … … 522 559 523 560 x -= offsetX; 524 y -= offsetZ; 561 y -= offsetZ; 525 562 526 563 … … 528 565 int yInt = (int)y / scaleZ; y -= (float) ((int) y); /*yInt = heightMap->w - yInt;*/ 529 566 530 PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y);567 //PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y); 531 568 532 569 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w ) return 0; 533 570 if( y >= 0.5*x) 571 { 572 // Check for ... 573 } 574 534 575 float height = heights[yInt + (xInt)*heightMap->w]*scaleY; 535 576 … … 543 584 PRINTF(0)("c: %f \n" ,c); 544 585 545 height += ( (a/c)*(x) + (b/c)*(y));586 height -= ( (a/c)*(x) + (b/c)*(y)); 546 587 547 588 PRINTF(0)("height: %f \n" ,height ); -
branches/height_map_merge/src/lib/graphics/importer/height_map.h
r6745 r6939 38 38 Tile(int i1, int j1, int i2, int j2, HeightMap* hm ) ; 39 39 Tile(); 40 float x; 41 float z; 40 42 ~Tile(); 41 43 … … 43 45 44 46 private: 47 HeightMap* hmref; 45 48 VertexArrayModel* highResModel; 46 49 VertexArrayModel* lowResModel; -
branches/height_map_merge/src/lib/graphics/importer/vertex_array_model.cc
r6603 r6939 139 139 glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ; 140 140 glEnable (GL_COLOR_MATERIAL) ; 141 142 141 143 142 144
Note: See TracChangeset
for help on using the changeset viewer.