- Timestamp:
- May 1, 2006, 11:34:07 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/height_map.cc
r7468 r7469 37 37 * @param i1 38 38 */ 39 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* h m)39 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* heightMapReference ) 40 40 { 41 41 PRINTF(0)("Tile Constructor\n"); 42 highResModel = new VertexArrayModel(); 43 lowResModel = new VertexArrayModel(); 44 45 this->load(i1, j1, i2, j2, hm, highResModel,4); 46 this->load(i1, j1, i2, j2, hm, lowResModel, 8); 42 this->highResModel = new VertexArrayModel(); 43 this->lowResModel = new VertexArrayModel(); 44 45 this->heightMapReference = heightMapReference; 46 47 // create high res model 48 this->load(i1, j1, i2, j2, this->highResModel, 4); 49 // create low res model 50 this->load(i1, j1, i2, j2, this->lowResModel, 8); 47 51 } 48 52 … … 57 61 58 62 63 /** 64 * this darws the tile in diefferent resolutions 65 */ 59 66 void Tile::draw() 60 67 { … … 73 80 74 81 75 /* 76 */ 77 void Tile::load(int i1, int j1, int i2, int j2, HeightMap* hm, VertexArrayModel* model, int Res) 78 { 79 80 #define heightMap hm->heightMap 81 #define colours hm->colours 82 #define scaleX hm->scaleX 83 #define scaleY hm->scaleY 84 #define scaleZ hm->scaleZ 85 #define shiftX hm->shiftX 86 #define shiftY hm->shiftY 87 #define shiftZ hm->shiftZ 88 #define normalVectorField hm->normalVectorField 89 90 heightMapReference = hm; // FIXME 91 92 this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX; 93 this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ; 94 95 int sampleRate = Res; 82 /** 83 * loads a tile 84 */ 85 void Tile::load(int i1, int j1, int i2, int j2, VertexArrayModel* model, int sampleRate) 86 { 87 88 // #define heightMap this->heightMapReference->heightMap 89 #define colours this->heightMapReference->colours 90 #define scaleX this->heightMapReference->scaleX 91 #define scaleY this->heightMapReference->scaleY 92 #define scaleZ this->heightMapReference->scaleZ 93 #define shiftX this->heightMapReference->shiftX 94 #define shiftY this->heightMapReference->shiftY 95 #define shiftZ this->heightMapReference->shiftZ 96 #define normalVectorField this->heightMapReference->normalVectorField 97 98 this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((i1 + i2) / 2)) * scaleX; 99 this->z = this->heightMapReference->offsetZ + ((j1 + j2 ) / 2 ) * scaleZ; 96 100 97 101 float height = 0; … … 105 109 106 110 107 if( heightMap != NULL &&heightMap->format->BitsPerPixel == 8 )108 109 SDL_LockSurface(heightMap);110 SDL_LockSurface( hm->colourMap);111 if(this->heightMapReference->heightMap != NULL && this->heightMapReference->heightMap->format->BitsPerPixel == 8 ) 112 113 SDL_LockSurface(this->heightMapReference->heightMap); 114 SDL_LockSurface(this->heightMapReference->colourMap); 111 115 112 116 for(int i = i1 ; i <= i2 ; i +=sampleRate) … … 116 120 117 121 118 if( hm->hasColourMap)119 { 120 r = colours[(3*w+2 + 3*i*( heightMap->w )) ];121 g = colours[(3*w+1 + 3*i*( heightMap->w)) ];122 b = colours[(3*w+0 + 3*i*( heightMap->w))];122 if(this->heightMapReference->hasColourMap) 123 { 124 r = colours[(3*w+2 + 3*i*(this->heightMapReference->heightMap->w )) ]; 125 g = colours[(3*w+1 + 3*i*(this->heightMapReference->heightMap->w)) ]; 126 b = colours[(3*w+0 + 3*i*(this->heightMapReference->heightMap->w))]; 123 127 } 124 128 125 129 w = j1; 126 model->addVertex(scaleX*( heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right127 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);128 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i % heightMap->h)/(texRate));130 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 131 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x); 132 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 129 133 130 134 model->addColor(r/255.0,g/255.0,b/255.0); … … 135 139 136 140 // To be fixed 137 if( hm->hasColourMap)141 if(this->heightMapReference->hasColourMap) 138 142 { 139 r = colours[(3*j+2 + 3*i*( heightMap->w )) ];140 g = colours[(3*j+1 + 3*i*( heightMap->w)) ];141 b = colours[(3*j+0 + 3*i*( heightMap->w))];143 r = colours[(3*j+2 + 3*i*(this->heightMapReference->heightMap->w )) ]; 144 g = colours[(3*j+1 + 3*i*(this->heightMapReference->heightMap->w)) ]; 145 b = colours[(3*j+0 + 3*i*(this->heightMapReference->heightMap->w))]; 142 146 } 143 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];144 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];145 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))];146 height += (float)(unsigned char) hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];147 height += (float)(unsigned char) hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];147 height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ]; 148 height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ]; 149 height += (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate + (i+1)*(this->heightMapReference->heightMap->w ))]; 150 height += (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w )) ]; 151 height += (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ]; 148 152 height=height/5.0; 149 153 150 model->addVertex(scaleX*( heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right151 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);152 model->addTexCoor((float)(j) /(texRate), (float)(i % heightMap->h)/(texRate));153 154 //PRINTF(0)("TexCoord: %f %f \n",(float)j / 100.0, (float)(i % heightMap->h)/100.0);154 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right 155 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x); 156 model->addTexCoor((float)(j) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 157 158 //PRINTF(0)("TexCoord: %f %f \n",(float)j / 100.0, (float)(i %this->heightMapReference->h)/100.0); 155 159 156 160 model->addColor(r/255.0,g/255.0,b/255.0); … … 159 163 160 164 161 model->addVertex(scaleX*( heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right162 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);163 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i % heightMap->h)/(texRate));165 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right 166 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,normalVectorField[i% this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x); 167 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 164 168 model->addColor(r/255.0,g/255.0,b/255.0); 165 169 … … 170 174 171 175 172 SDL_UnlockSurface( heightMap);176 SDL_UnlockSurface(this->heightMapReference->heightMap); 173 177 int cnt = 0; 174 178 for(int i = i1 ; i < i2 ; i +=sampleRate) … … 197 201 198 202 // To be fixed 199 if( hm->hasColourMap)200 { 201 r = (float)colours[(3*j+2 + 3*i*( heightMap->w )) ];202 g = (float)colours[(3*j+1 + 3*i*( heightMap->w)) ];203 b = (float)colours[(3*j+0 + 3*i*( heightMap->w))];204 } 205 206 model->addVertex(scaleX*( heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right207 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);208 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) % heightMap->h)/(texRate));203 if(this->heightMapReference->hasColourMap) 204 { 205 r = (float)colours[(3*j+2 + 3*i*(this->heightMapReference->heightMap->w )) ]; 206 g = (float)colours[(3*j+1 + 3*i*(this->heightMapReference->heightMap->w)) ]; 207 b = (float)colours[(3*j+0 + 3*i*(this->heightMapReference->heightMap->w))]; 208 } 209 210 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 211 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x); 212 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %this->heightMapReference->heightMap->h)/(texRate)); 209 213 model->addColor(r/255.0,g/255.0,b/255.0); 210 214 … … 214 218 { 215 219 int i = i1; 216 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];217 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];218 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))];219 height += (float)(unsigned char) hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];220 height += (float)(unsigned char) hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];220 height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ]; 221 height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ]; 222 height += (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate + (i+1)*(this->heightMapReference->heightMap->w ))]; 223 height += (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w )) ]; 224 height += (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ]; 221 225 height=height/5.0; 222 226 223 model->addVertex(scaleX*( heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right224 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);225 model->addTexCoor((float)j /(texRate), (float)(i % heightMap->h)/(texRate));227 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 228 model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j% this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x); 229 model->addTexCoor((float)j /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 226 230 model->addColor(r/255.0,g/255.0,b/255.0); 227 231 … … 235 239 236 240 // To be fixed 237 if( hm->hasColourMap)238 { 239 r = (float)colours[3*j+2 + 3*i*( heightMap->w )];240 g = (float)colours[3*j+1 + 3*i*( heightMap->w)];241 b = (float)colours[3*j+0 + 3*i*( heightMap->w)];242 } 243 244 model->addVertex(scaleX*( heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right245 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);246 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) % heightMap->h)/(texRate));241 if(this->heightMapReference->hasColourMap) 242 { 243 r = (float)colours[3*j+2 + 3*i*(this->heightMapReference->heightMap->w )]; 244 g = (float)colours[3*j+1 + 3*i*(this->heightMapReference->heightMap->w)]; 245 b = (float)colours[3*j+0 + 3*i*(this->heightMapReference->heightMap->w)]; 246 } 247 248 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right 249 model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x); 250 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %this->heightMapReference->heightMap->h)/(texRate)); 247 251 model->addColor(r/255.0,g/255.0,b/255.0); 248 252 … … 253 257 { 254 258 int i = i2; 255 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];256 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];257 height += (float) (unsigned char) hm->heights[(j -1+ sampleRate + (i+1)*(heightMap->w ))];258 height += (float)(unsigned char) hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];259 height += (float)(unsigned char) hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];259 height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ]; 260 height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ]; 261 height += (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate + (i+1)*(this->heightMapReference->heightMap->w ))]; 262 height += (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w ))]; 263 height += (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ]; 260 264 height=height/5.0; 261 model->addVertex(scaleX*( heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right262 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);263 model->addTexCoor((float)j /(texRate), (float)(i % heightMap->h)/(texRate));265 model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right 266 model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x); 267 model->addTexCoor((float)j /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate)); 264 268 model->addColor(r/255.0,g/255.0,b/255.0); 265 269 … … 300 304 301 305 302 SDL_UnlockSurface( hm->colourMap);306 SDL_UnlockSurface(this->heightMapReference->colourMap); 303 307 304 308 model->finalize(); … … 307 311 308 312 309 #undef heightMap313 // #undef heightMap 310 314 #undef colours 311 315 #undef scaleX … … 319 323 } 320 324 325 321 326 HeightMap::HeightMap() 322 327 { 323 328 } 329 324 330 325 331 HeightMap::HeightMap(const std::string& height_map_name = "") -
trunk/src/lib/graphics/importer/height_map.h
r7468 r7469 52 52 53 53 private: 54 void load(int i1, int j1, int i2, int i2, HeightMap* hm,VertexArrayModel* model, int Res);54 void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res); 55 55 56 56 … … 64 64 VertexArrayModel* lowResModel; //!< low resolution model of the tile 65 65 66 HeightMap* heightMapReference; //!<66 HeightMap* heightMapReference; //!< reference to the heightmap this tile belongs to 67 67 int highRes; //!< 68 68 int lowRes; //!<
Note: See TracChangeset
for help on using the changeset viewer.