Changeset 6329 in orxonox.OLD for branches/height_map/src/lib/graphics/importer
- Timestamp:
- Dec 28, 2005, 1:51:28 PM (19 years ago)
- Location:
- branches/height_map/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map/src/lib/graphics/importer/height_map.cc
r6270 r6329 35 35 } 36 36 37 HeightMap::HeightMap(const char* height_map_name = NULL) 37 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel() 38 38 { 39 39 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); … … 43 43 PRINTF(0)("loading Image %s\n", height_map_name); 44 44 PRINTF(0)("width : %i\n", heightMap->w); 45 PRINTF(0)("h ight : %i\n", heightMap->h);45 PRINTF(0)("height : %i\n", heightMap->h); 46 46 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel); 47 47 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift); … … 54 54 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name); 55 55 56 57 generateNormalVectorField(); 58 59 60 //Defines 2 Materials (for testing only!) 61 this->tmp_mat = new Material(); 62 tmp_mat->setTransparency(1.0); 63 tmp_mat->setIllum(0.3); 64 tmp_mat->setDiffuse(0.55,0.4,0.2); 65 tmp_mat->setAmbient(0.6,0.4,0.2); 66 tmp_mat->setSpecular(0.02,0.02,0.02); 67 tmp_mat->setShininess(.1); 68 tmp_mat->setTransparency(1.0); 69 70 tmp_mat->diffuseTexture = NULL; 71 tmp_mat->ambientTexture = NULL; 72 tmp_mat->specularTexture = NULL; 73 74 this->red_mat = new Material(); 75 red_mat->setTransparency(1.0); 76 red_mat->setIllum(0.3); 77 red_mat->setDiffuse(0.55,0.1,0.1); 78 red_mat->setAmbient(0.55,0.1,0.1); 79 red_mat->setSpecular(0.02,0.02,0.02); 80 red_mat->setShininess(.1); 81 red_mat->setTransparency(1.0); 82 83 red_mat->diffuseTexture = NULL; 84 red_mat->ambientTexture = NULL; 85 red_mat->specularTexture = NULL; 56 57 generateNormalVectorField(); 58 59 shiftX = 0; 60 shiftY = 0; 61 shiftZ = 0; 86 62 87 63 } … … 96 72 PRINTF(0)("loading Image %s\n", height_map_name); 97 73 PRINTF(0)("width : %i\n", heightMap->w); 98 PRINTF(0)("h ight : %i\n", heightMap->h);74 PRINTF(0)("height : %i\n", heightMap->h); 99 75 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel); 100 76 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift); … … 108 84 109 85 110 generateNormalVectorField(); 111 112 113 //Defines 2 Materials (for testing only!) 114 this->tmp_mat = new Material("tmp"); 115 tmp_mat->setTransparency(1.0); 116 tmp_mat->setIllum(0.3); 117 tmp_mat->setDiffuse(1.0,1.0,1.0); 118 tmp_mat->setAmbient(1.0,1.0,1.0); 119 120 tmp_mat->setSpecular(0.0,0.00,0.00); 121 tmp_mat->setShininess(1.0); 122 123 124 125 126 this->red_mat = new Material("red"); 127 red_mat->setTransparency(1.0); 128 red_mat->setIllum(3); 129 red_mat->setDiffuse(0.55,0.1,0.1); 130 red_mat->setAmbient(0.55,0.1,0.1); 131 red_mat->setSpecular(0.0,0.0,0.0); 132 red_mat->setShininess(1.0); 133 red_mat->setTransparency(1.0); 134 135 // red_mat->diffuseTexture = NULL; 136 // red_mat->ambientTexture = NULL; 137 //red_mat->specularTexture = NULL; 138 139 if(false /*colour_map_name != NULL*/) 86 generateNormalVectorField(); 87 88 89 if(colour_map_name != NULL) 140 90 { 141 91 colourMap = IMG_Load(colour_map_name); … … 144 94 PRINTF(0)("loading Image %s\n", colour_map_name); 145 95 PRINTF(0)("width : %i\n", colourMap->w); 146 PRINTF(0)("h ight : %i\n", colourMap->h);96 PRINTF(0)("height : %i\n", colourMap->h); 147 97 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel); 148 98 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift); … … 154 104 else PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name); 155 105 156 const char* texture_name = "pictures/ground.tga"; 157 tmp_mat->setDiffuseMap(texture_name); 106 107 158 108 if(colourMap != NULL) 159 109 { 160 //colours = (unsigned char *) colourMap->pixels;161 hasColourMap = false;110 colours = (unsigned char *) colourMap->pixels; 111 hasColourMap = true; 162 112 } 163 else 164 { 165 hasColourMap = false; 166 167 113 else hasColourMap = false; 114 115 116 shiftX = 0; 117 shiftY = 0; 118 shiftZ = 0; 168 119 } 169 120 170 // tmp_mat->setAmbientMap(texture_name);171 //tmp_mat->setSpecularMap(texture_name);172 173 // red_mat->setDiffuseMap(texture_name);174 // red_mat->setAmbientMap(texture_name);175 //red_mat->setSpecularMap(texture_name);176 }177 178 121 179 122 } … … 185 128 void HeightMap::load() 186 129 { 187 188 189 190 tmp_mat->select();191 130 192 131 unsigned char height = 0; 193 132 int offset = 0; 194 133 int g = 0; 195 float old_r = 0.0f;196 float old_g = 0.0f; 197 float old_b = 0.0f;134 135 136 198 137 heights = (unsigned char*) heightMap->pixels; 199 bool colourChanged = true; 138 200 139 201 140 … … 205 144 SDL_LockSurface(heightMap); 206 145 207 208 146 209 147 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 210 148 { 211 212 tmp_mat->select();213 214 215 216 149 int j = 0; 217 150 218 151 float r; 152 float g; 153 float b; 219 154 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 220 155 { 221 if(false) 222 { 223 float r = (float)colours[3*j+2 + 3*i*(heightMap->w )]; 224 float g = (float)colours[3*j+1 + 3*i*(heightMap->w)]; 225 float b = (float)colours[3*j+0 + 3*i*(heightMap->w)]; 226 colourChanged = old_r != r || old_g != g || old_b != b; 227 old_r = r; 228 old_g = g; 229 old_b = b; 230 if(colourChanged) 231 { 232 tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0); 233 tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0); 234 tmp_mat->select(); 235 } 236 } 237 238 this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right 239 240 height = heights[j+sampleRate + i*(heightMap->w )]; 156 // To be fixed 157 r = (float)colours[3*j+2 + 3*i*(heightMap->w )]; 158 g = (float)colours[3*j+1 + 3*i*(heightMap->w)]; 159 b = (float)colours[3*j+0 + 3*i*(heightMap->w)]; 160 161 height = heights[j+sampleRate + i*(heightMap->w )]; 162 this->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j+sampleRate) + shiftZ); // Top Right 163 164 165 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x); 166 this->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef); 167 168 this->addColor(r/255.0,g/255.0,b/255.0); 169 170 171 } 172 173 174 j = (heightMap->w/sampleRate - sampleRate); 175 176 this->addVertex(scaleX*(heightMap->h -i)+ shiftX,-1000.0,scaleZ*(j+sampleRate)+ shiftZ); // Top Right 177 241 178 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x); 242 179 this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 243 244 this->addColor(0.5,0.5,0.5); 245 246 180 this->addColor(0.1,0.1,0.9); 181 182 183 184 185 } 186 187 SDL_UnlockSurface(heightMap); 188 189 190 int cnt = 0; 191 for(int i = 0 ; i < heightMap->h - 2*sampleRate ; i +=sampleRate) 192 { 193 194 for(int j = 0 ; j < heightMap->w - sampleRate ; j += sampleRate) 195 { 196 197 this->addIndice(cnt); 198 this->addIndice(cnt + (heightMap->w)/ sampleRate ); 199 cnt++; 200 247 201 } 248 249 j = (heightMap->w/sampleRate); 250 251 this->addVertex(scaleX*(heightMap->h -i),(double)(double)(-1000),scaleZ*(j+sampleRate)); // Top Right 252 253 height = heights[j+sampleRate + i*(heightMap->w )]; 254 this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x); 255 this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0); 256 257 this->addColor(0.5,0.5,0.5); 258 259 260 261 262 263 } 264 265 266 267 SDL_UnlockSurface(heightMap); 268 269 270 int cnt = 0; 271 for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate) 272 { 273 274 for(int j = 0 ; j < heightMap->w -sampleRate ; j += sampleRate) 275 { 276 277 this->addIndice(cnt); 278 this->addIndice(cnt+1 + (heightMap->w-sampleRate)/ sampleRate ); 279 cnt ++; 280 } 281 cnt++; 282 283 this->newStripe(); 202 203 cnt++; 204 this->newStripe(); 205 284 206 285 207 } 286 287 288 289 290 291 292 //this->planeModel(100,100, 100,100);293 208 294 209 this->finalize(); … … 317 232 { 318 233 SDL_LockSurface(heightMap); 319 for(int i = 0 ; i < heightMap->h - 1 ; i ++)320 { 321 for(int j = 0; j < heightMap->w - 1 ; j ++)234 for(int i = 0 ; i < heightMap->h - 1 ; i ++) 235 { 236 for(int j = 0; j < heightMap->w - 1 ; j ++) 322 237 { 323 238 324 239 325 240 delta = (int)heights[j + (i+1)*(heightMap->w )] - (int) heights[j + i*(heightMap->w )]; 326 Vector a = Vector(- 20.0,(float)delta,0.0f);241 Vector a = Vector(-scaleX,(float)delta*scaleY ,0.0f); 327 242 328 243 delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )]; 329 Vector b = Vector(0.0f,(float) delta ,20.0);244 Vector b = Vector(0.0f,(float) delta*scaleY ,scaleZ); 330 245 331 246 332 247 normalVectorField[i][j] = b.cross(a); 333 248 normalVectorField[i][j].normalize(); 334 249 335 250 } 336 251 } … … 341 256 } 342 257 343 void HeightMap::drawRect(int xBottom, int yBottom, int xTop, int yTop ) 344 { 345 int height = 0; 346 if(true) 347 { 348 349 height = heights[xTop + yTop*(heightMap->w )]; 350 glNormal3f(normalVectorField[yTop][xTop].y,normalVectorField[yTop][xTop].z,normalVectorField[yTop][xTop].x); 351 glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((xBottom/sampleRate)%8)/8.0+0.125); 352 glVertex3f(scaleX*(heightMap->h - yTop),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Top Right 353 354 height = heights[xBottom + yTop*(heightMap->w )]; 355 glNormal3f(normalVectorField[yTop][xBottom].y,normalVectorField[yTop][xBottom].z,normalVectorField[yTop][xBottom].x); 356 glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((xBottom/sampleRate)%8)/8.0+0.125); 357 glVertex3f(scaleX*(heightMap->h -(yTop)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Top Left 358 359 height = heights[xTop + (yBottom)*(heightMap->w )]; 360 glNormal3f(normalVectorField[yBottom][xTop].y,normalVectorField[yBottom][xTop].z,normalVectorField[yBottom][xTop].x); 361 glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((yBottom/sampleRate)%8)/8.0); 362 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Bottom Right 363 364 height = heights[xBottom + (yBottom)*(heightMap->w )]; 365 glNormal3f(normalVectorField[yBottom][xBottom].y,normalVectorField[yBottom][xBottom].z,normalVectorField[yBottom][xBottom].x); 366 glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((yBottom/sampleRate)%8)/8.0); 367 glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Bottom Left 368 369 370 371 } 372 else 373 { 374 // subdivide 375 } 376 377 } 378 379 380 void HeightMap::fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight) 381 { 382 383 int height = 0; 384 385 for(int i= xTopRight; i < xBottomLeft ; i+= sampleRate) 386 { 387 388 glBegin(GL_TRIANGLES); 389 390 height = heights[yBottomLeft + (i + sampleRate)*(heightMap->w )]; 391 glNormal3f(0,1,0); 392 glVertex3f(scaleX*(heightMap->h -i-sampleRate),scaleY*height,scaleZ*(yBottomLeft)); 393 394 height = heights[yBottomLeft + i*(heightMap->w )]; 395 glNormal3f(0,1,0); 396 glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft)); 397 398 height = heights[yBottomLeft + (i + sampleRate/2)*(heightMap->w )]; 399 glNormal3f(0,1,0); 400 glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft)); 401 402 403 404 glEnd(); 405 406 407 408 409 } 410 for(int j= yBottomLeft; j < yTopRight; j+= sampleRate) 411 { 412 glBegin(GL_TRIANGLES); 413 height = heights[j + (xBottomLeft+sampleRate)*(heightMap->w )]; 414 glNormal3f(-1,0,0); 415 glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j)); 416 417 height = heights[j + sampleRate/2 + (xBottomLeft + sampleRate)*(heightMap->w )]; 418 glNormal3f(-1,0,0); 419 glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2)); 420 421 height = heights[j + sampleRate + (xBottomLeft + sampleRate)*(heightMap->w )]; 422 glNormal3f(-1,0,0); 423 glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate)); 424 425 glEnd(); 426 } 427 } 258 259 260 428 261 429 262 void HeightMap::scale(Vector v) … … 434 267 } 435 268 436 // Accepts Coordinates relative to HeightMap 269 void HeightMap::shift(Vector v) 270 { 271 shiftX = v.x; 272 shiftY = v.y; 273 shiftZ = v.z; 274 } 275 276 437 277 float HeightMap::getHeight(float x, float y) 438 278 { -
branches/height_map/src/lib/graphics/importer/height_map.h
r6249 r6329 17 17 18 18 #define sampleRate 4 19 #define texRate 4 20 #define texRatef 4.0f 19 21 20 22 class SDL_Surface; … … 32 34 void load(const char*, int Mode); 33 35 void scale( Vector V); 34 float getHeight(float x, float y); // x,y relative to HeightMap 36 void shift (Vector V); 37 float getHeight(float x, float y); 35 38 HeightMap(); 36 39 HeightMap(const char*); … … 56 59 float scaleY ; 57 60 float scaleZ ; 61 float shiftX ; 62 float shiftY ; 63 float shiftZ ; 58 64 int cmScaleX; 59 65 int cmScaleY; 60 66 bool hasColourMap; 67 61 68 inline int abs(int val) 62 69 {
Note: See TracChangeset
for help on using the changeset viewer.