Changeset 6727 in orxonox.OLD for branches/height_map_merge/src/lib/graphics/importer/height_map.cc
- Timestamp:
- Jan 25, 2006, 5:46:16 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map_merge/src/lib/graphics/importer/height_map.cc
r6603 r6727 37 37 lowResModel = new VertexArrayModel(); 38 38 39 this->load(i1,j1,i2,j2,hm,highResModel, 2);39 this->load(i1,j1,i2,j2,hm,highResModel,4); 40 40 this->load(i1,j1,i2,j2,hm,lowResModel, 8); 41 41 } … … 57 57 //FIXME 58 58 float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(0.0,100.0,0.0)).len(); 59 if (cameraDistance > 5000 )59 if (cameraDistance > 10000 ) 60 60 { 61 61 62 62 } 63 else if (cameraDistance > 1000 )63 else if (cameraDistance >= 50000 ) 64 64 { 65 65 this->drawLowRes(); … … 98 98 int sampleRate = Res; 99 99 100 100 float height = 0; 101 101 int offset = 0; 102 102 … … 128 128 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 129 129 model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x); 130 model->addTexCoor(( ((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);130 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate)); 131 131 model->addColor(r/255.0,g/255.0,b/255.0); 132 132 … … 147 147 height += (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )]; 148 148 height += (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )]; 149 150 149 height=height/5.0; 151 150 152 151 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right 153 152 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));153 model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate)); 155 154 156 155 //PRINTF(0)("TexCoord: %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0); … … 163 162 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 164 163 model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x); 165 model->addTexCoor(( ((w+sampleRate)/sampleRate))/4.0,(((i+ sampleRate)/sampleRate))/4.0);164 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate)); 166 165 model->addColor(r/255.0,g/255.0,b/255.0); 167 166 … … 208 207 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 209 208 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 210 model->addTexCoor(( (j/sampleRate))/texRatef,(((i - sampleRate)/sampleRate))/texRatef);209 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate)); 211 210 model->addColor(r/255.0,g/255.0,b/255.0); 212 211 … … 225 224 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 226 225 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 227 model->addTexCoor(( (j/sampleRate))/texRatef,(((i)/sampleRate))/texRatef);226 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate)); 228 227 model->addColor(r/255.0,g/255.0,b/255.0); 229 228 … … 246 245 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 247 246 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 248 model->addTexCoor(( (j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);247 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate)); 249 248 model->addColor(r/255.0,g/255.0,b/255.0); 250 249 … … 255 254 { 256 255 int i = i2; 257 256 height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )]; 258 257 height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )]; 259 258 height += (float) (unsigned char) hm->heights[j -1+ sampleRate + (i+1)*(heightMap->w )]; … … 263 262 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 264 263 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x); 265 model->addTexCoor(( (j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);264 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate)); 266 265 model->addColor(r/255.0,g/255.0,b/255.0); 267 266 … … 452 451 for(int j = 1; j < j_max ; j++) 453 452 { 454 455 453 tiles[i][j]->draw(); 456 454 } … … 500 498 501 499 502 503 504 505 500 void HeightMap::scale(Vector v) 506 501 { … … 510 505 } 511 506 512 void HeightMap::shift(Vector v) 513 { 514 shiftX = v.x; 515 shiftY = v.y; 516 shiftZ = v.z; 517 } 518 519 520 float HeightMap::getHeight(float x, float y) 521 { 507 void HeightMap::setAbsCoor(Vector v) 508 { 509 offsetX = v.x; 510 offsetY = v.y; 511 offsetZ = v.z; 512 } 513 514 515 float HeightMap::getHeight(float x, float y) 516 { 517 518 //x -= offsetX; 519 //y -= offsetZ; 520 521 522 522 int xInt = (int)x / scaleX; x -= (float)xInt*scaleX; xInt = heightMap->h - xInt; 523 int yInt = (int)y / scaleZ; y -= (float)yInt*scaleZ; 524 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w ) return 0.0f; 523 int yInt = (int)y / scaleZ; y -= (float)yInt*scaleZ; /*yInt = heightMap->w - yInt;*/ 524 525 if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w ) return shiftY; 526 525 527 float height = heights[yInt + (xInt)*heightMap->w]*scaleY; 528 526 529 float a = normalVectorField[(xInt)][yInt].x; 527 530 float b = normalVectorField [(xInt)][yInt].z; 528 531 float c = normalVectorField [(xInt)][yInt].y; 529 height -= ( (a/c)*(x) + (b/c)*(y))*scaleY; 530 return height; 531 } 532 533 height -= ( (a/c)*(x) + (b/c)*(y); 534 535 return (height ); 536 }
Note: See TracChangeset
for help on using the changeset viewer.