Changeset 6727 in orxonox.OLD for branches/height_map_merge/src
- Timestamp:
- Jan 25, 2006, 5:46:16 PM (19 years ago)
- Location:
- branches/height_map_merge/src
- Files:
-
- 4 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 } -
branches/height_map_merge/src/lib/graphics/importer/height_map.h
r6603 r6727 10 10 11 11 ### File Specific: 12 main-programmer: 12 main-programmer: bottac@ee.ethz.ch 13 13 */ 14 14 … … 17 17 18 18 19 #define texRate 6419 #define texRate 32 20 20 #define texRatef 4.0f 21 #define tileSize 6421 #define tileSize 128 22 22 23 23 class SDL_Surface; … … 58 58 void load(const char*, int Mode); 59 59 void scale( Vector V); 60 void s hift(Vector V);60 void setAbsCoor(Vector V); 61 61 float getHeight(float x, float y); 62 float getNormal(float x, float y); 62 63 HeightMap(); 63 64 HeightMap(const char*); … … 78 79 Vector ** normalVectorField ; 79 80 Tile *** tiles; 80 Vector camCoords; 81 Vector camCoords; 82 Vector offsetCoords; 81 83 Material * tmp_mat; 82 84 Material* red_mat; … … 86 88 float scaleY ; 87 89 float scaleZ ; 88 float shiftX ; 89 float shiftY ; 90 float shiftZ ; 90 float shiftX ; // to be removed 91 float shiftY ; // to be removed 92 float shiftZ ; // to be removed 93 float offsetX; 94 float offsetY; 95 float offsetZ; 91 96 int cmScaleX; 92 97 int cmScaleY; -
branches/height_map_merge/src/world_entities/terrain.cc
r6603 r6727 30 30 31 31 #include "glincl.h" 32 33 #include "state.h" 32 34 33 35 using namespace std; … … 154 156 155 157 this->heightMap = new HeightMap(hmName, hmColorName); 156 heightMap->scale(Vector(23.0f, 3.5f,23.0f));157 heightMap->s hift(Vector(-1000.0,-90.0,-4000.0));158 heightMap->scale(Vector(23.0f,1.1f,23.0f)); 159 heightMap->setAbsCoor(this->getAbsCoor()); 158 160 heightMap->load(); 159 161 delete[] hmName; … … 166 168 { 167 169 if (this->heightMapMaterial != NULL) 168 delete this->heightMapMaterial;170 delete this->heightMapMaterial; 169 171 170 172 … … 214 216 void Terrain::draw () const 215 217 { 218 219 220 216 221 glMatrixMode(GL_MODELVIEW); 217 222 glPushMatrix(); 218 223 219 224 /* translate */ 220 glTranslatef (this->getAbsCoor ().x,225 /* glTranslatef (this->getAbsCoor ().x, 221 226 this->getAbsCoor ().y, 222 227 this->getAbsCoor ().z); 228 */ 223 229 /* rotate */ 224 Vector tmpRot = this->getAbsDir().getSpacialAxis();225 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );230 // Vector tmpRot = this->getAbsDir().getSpacialAxis(); 231 //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 226 232 227 233 if (this->objectList) … … 237 243 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 238 244 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 239 240 glEnable(GL_LIGHTING); 245 glEnable(GL_LIGHTING); 241 246 glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ; 242 247 glEnable (GL_COLOR_MATERIAL) ; … … 245 250 glPopMatrix(); 246 251 247 248 252 glMatrixMode(GL_MODELVIEW); 253 glPushMatrix(); 254 glLoadIdentity(); 255 Vector camera = State::getCamera()->getAbsCoor(); // Go on here ..........!!! 256 float height = heightMap->getHeight(camera.x, camera.z); 257 258 glEnable (GL_COLOR_MATERIAL) ; 259 glBegin(GL_QUADS); // Draw The Cube Using quads 260 glColor3f(0.0f,1.0f,0.0f); // Color Blue 261 glVertex3f(camera.x + 13.0f,height+13.0f,camera.z-13.0f); // Top Right Of The Quad (Top) 262 glVertex3f(camera.x-13.0f, height+13.0f,camera.z-13.0f); // Top Left Of The Quad (Top) 263 glVertex3f(camera.x-13.0f, height+13.0f, camera.z+13.0f); // Bottom Left Of The Quad (Top) 264 glVertex3f(camera.x+ 13.0f, height+13.0f, camera.z+13.0f); // Bottom Right Of The Quad (Top) 265 glEnd(); // End Drawing The Plan 266 267 268 glPopMatrix(); 249 269 /* THIS IS ONLY FOR DEBUGGING INFORMATION */ 250 270 if (this->ssp != NULL) … … 457 477 { 458 478 } 479 480 float Terrain::getHeight(float x, float y) 481 { 482 if(this->heightMap != NULL) 483 return (this->heightMap->getHeight(x, y)); 484 return 0; 485 } -
branches/height_map_merge/src/world_entities/terrain.h
r6495 r6727 46 46 47 47 void buildDebugTerrain(DebugTerrain debugTerrain); 48 49 float getHeight(float x, float y); 48 50 virtual void draw() const; 49 51
Note: See TracChangeset
for help on using the changeset viewer.