Changeset 7499 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- May 3, 2006, 10:45:46 AM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/height_map.cc
r7498 r7499 35 35 /** 36 36 * default constructor 37 * @param i138 */ 39 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* heightMapReference )40 { 41 PRINTF( 4)("Tile Constructor\n");37 * @param xOffset 38 */ 39 Tile::Tile(int xOffset, int yOffset, int i2, int j2, HeightMap* heightMapReference ) 40 { 41 PRINTF(0)("Tile Constructor\n"); 42 42 43 43 this->highResModel = new VertexArrayModel(); … … 47 47 48 48 // create high res model 49 this->load( i1, j1, i2, j2, this->highResModel, 4);49 this->load(xOffset, yOffset, i2, j2, this->highResModel, 4); 50 50 // create low res model 51 this->load( i1, j1, i2, j2, this->lowResModel, 8);51 this->load(xOffset, yOffset, i2, j2, this->lowResModel, 8); 52 52 } 53 53 … … 84 84 * loads a tile 85 85 */ 86 void Tile::load(int i1, int j1, int i2, int j2, VertexArrayModel* model, int sampleRate)86 void Tile::load(int xOffset, int yOffset, int i2, int j2, VertexArrayModel* model, int sampleRate) 87 87 { 88 88 … … 99 99 100 100 //FIXME: OLD implementation 101 this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - (( i1+ i2) / 2)) * scaleX;102 this->z = this->heightMapReference->offsetZ + (( j1+ j2 ) / 2 ) * scaleZ;101 this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX; 102 this->z = this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ; 103 103 //NEW: 104 this->setAbsCoor(this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - (( i1+ i2) / 2)) * scaleX,104 this->setAbsCoor(this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX, 105 105 0, 106 this->heightMapReference->offsetZ + (( j1+ j2 ) / 2 ) * scaleZ);106 this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ); 107 107 108 108 … … 120 120 SDL_LockSurface(this->heightMapReference->colorMap); 121 121 122 for( int i = i1; i <= i2 ; i +=sampleRate)122 for( int i = xOffset ; i <= i2 ; i +=sampleRate) 123 123 { 124 124 int w = 0; … … 132 132 } 133 133 134 w = j1; 134 w = yOffset; 135 136 PRINTF(0)("Values: i = %i, w = %i\n", i, w); 135 137 136 138 // add a vertex to the list 137 model->addVertex(scaleX *(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right139 model->addVertex(scaleX * (this->heightMapReference->heightMap->h - i) + shiftX, shiftY, scaleZ * w + shiftZ); // Top Right 138 140 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y, 139 141 normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z, 140 142 normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x); 141 model->addTexCoor((float)( j1-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));143 model->addTexCoor((float)(yOffset-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 142 144 model->addColor(r/255.0f, g/255.0f, b/255.0f); 143 145 144 146 145 for(int j = j1; j <= j2; j += sampleRate)147 for(int j = yOffset; j <= j2; j += sampleRate) 146 148 { 147 149 // adjust the colors acording to the color map … … 185 187 int cnt = 0; 186 188 187 for( int i = i1; i < i2; i +=sampleRate)188 { 189 for( int j = j1-sampleRate; j < j2 + 2 * sampleRate; j += sampleRate)189 for( int i = xOffset; i < i2; i +=sampleRate) 190 { 191 for( int j = yOffset-sampleRate; j < j2 + 2 * sampleRate; j += sampleRate) 190 192 { 191 193 model->addIndice(cnt); 192 model->addIndice(cnt + (j2 - j1+ 3* sampleRate )/ sampleRate );194 model->addIndice(cnt + (j2 -yOffset + 3* sampleRate )/ sampleRate ); 193 195 cnt++; 194 196 } 195 197 model->newStripe(); 196 198 } 197 cnt += (j2 - j1+ 3* sampleRate)/ sampleRate;198 199 for( int j = j1; j <= j2; j += sampleRate)200 { 201 int i = i1;199 cnt += (j2 -yOffset + 3* sampleRate)/ sampleRate; 200 201 for( int j = yOffset; j <= j2; j += sampleRate) 202 { 203 int i = xOffset; 202 204 203 205 // To be fixed … … 220 222 221 223 222 for(int j = j1; j <= j2 ; j += sampleRate)223 { 224 int i = i1;224 for(int j = yOffset ; j <= j2 ; j += sampleRate) 225 { 226 int i = xOffset; 225 227 height = (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w]; 226 228 height += (float)(unsigned char)this->heightMapReference->heights[j + 1 + sampleRate + (i + 1) * … … 244 246 245 247 246 for(int j = j1; j <= j2; j += sampleRate)248 for(int j = yOffset; j <= j2; j += sampleRate) 247 249 { 248 250 int i = i2; … … 266 268 267 269 268 for(int j = j1; j <= j2; j += sampleRate)270 for(int j = yOffset; j <= j2; j += sampleRate) 269 271 { 270 272 int i = i2; … … 289 291 290 292 // link Boarder Stripe 291 for(int j = j1- sampleRate; j < j2; j += sampleRate)293 for(int j = yOffset - sampleRate; j < j2; j += sampleRate) 292 294 { 293 295 model->addIndice(cnt); 294 model->addIndice(cnt + (j2 - j1+ sampleRate) / sampleRate );296 model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate ); 295 297 cnt++; 296 298 } … … 301 303 302 304 303 cnt += (j2- j1)/ sampleRate;305 cnt += (j2-yOffset)/ sampleRate; 304 306 // link 2nd BoarderStripe 305 for(int j = j1-sampleRate; j < j2; j += sampleRate)307 for(int j = yOffset-sampleRate; j < j2; j += sampleRate) 306 308 { 307 309 model->addIndice(cnt); 308 model->addIndice(cnt + (j2 - j1+ sampleRate) / sampleRate);310 model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate); 309 311 cnt++; 310 312 } … … 441 443 void HeightMap::load() 442 444 { 443 //Create a Dynamicly sized 2D-Array for Tiles 444 tiles = new Tile** [heightMap->h/tileSize]; 445 for(int i=0;i < heightMap->h/tileSize ; i++) 446 tiles [i]= new (Tile* [heightMap->w /tileSize ]); 447 448 //SetUp Arrays 449 for(int i = 0; i < (heightMap->h )/ tileSize; i ++) 450 { 451 for(int j = 0; j < (heightMap->w )/ tileSize; j ++) 452 { 453 454 tiles[i][j] = new Tile( i*tileSize , j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ; 445 // create a dynamicly sized 2D-array for tiles 446 this->tiles = new Tile**[this->heightMap->h / this->tileSize]; 447 448 for( int i = 0;i < heightMap->h / tileSize; i++) 449 this->tiles [i]= new Tile*[this->heightMap->w / this->tileSize]; 450 451 // setup arrays 452 for( int i = 0; i < this->heightMap->h / this->tileSize; i++) { 453 for( int j = 0; j < this->heightMap->w / this->tileSize; j++) { 454 this->tiles[i][j] = new Tile( i * tileSize , j * tileSize , (i+1) * tileSize, (j+1) * tileSize , this); 455 455 } 456 456 } -
trunk/src/lib/graphics/importer/height_map.h
r7498 r7499 109 109 110 110 private: 111 SDL_Surface* heightMap; 112 SDL_Surface* colorMap; 111 SDL_Surface* heightMap; //!< image of the height map 112 SDL_Surface* colorMap; //!< image of the color map 113 113 unsigned char* heights; 114 114 unsigned char* colors;
Note: See TracChangeset
for help on using the changeset viewer.