Changeset 5990 in orxonox.OLD for branches/height_map/src/lib
- Timestamp:
- Dec 8, 2005, 4:07:19 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/height_map/src/lib/graphics/importer/height_map.cc
r5989 r5990 35 35 { 36 36 this->setClassID(CL_HEIGHT_MAP, "HeightMap"); 37 heightMap = IMG_Load(height_map_name); 38 if(heightMap!=NULL) { 37 heightMap = IMG_Load(height_map_name); 38 if(heightMap!=NULL) { 39 39 40 PRINTF(0)("loading Image %s\n", height_map_name); 40 41 PRINTF(0)("width : %i\n", heightMap->w); 41 42 PRINTF(0)("hight : %i\n", heightMap->h); 42 43 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel); 43 44 44 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift); 45 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift); 46 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift); 47 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask); 48 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask); 45 49 } 46 50 47 51 else PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name); 48 52 } 49 53 … … 56 60 void HeightMap::load() 57 61 { 58 longheight = 0;62 unsigned int height = 0; 59 63 int offset = 0; 60 64 char * bmp = (char*) heightMap->pixels; 61 65 62 if(heightMap != NULL /* && heightMap->format->BitsPerPixel == 8 */)66 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 ) 63 67 { 64 SDL_LockSurface(heightMap); 65 for(int i = 0 ; i < heightMap->h ; i +=1) 66 { 67 for(int j = 0; j < heightMap->w ; j += 1) 68 { 69 70 // get local hight from heightMap 71 72 73 74 offset = bmp[j + i*(heightMap->w )]; 75 height = (unsigned int)heightMap->format->palette->colors[offset].r + 76 (unsigned int)heightMap->format->palette->colors[offset].g + 77 (unsigned int) heightMap->format->palette->colors[offset].b ; 68 SDL_LockSurface(heightMap); 69 for(int i = 0 ; i < heightMap->h ; i +=1) 70 { 71 for(int j = 0; j < heightMap->w ; j += 1) 72 { 73 // get local hight from heightMap 74 // This seems to work only on 8-Bit Grayscale-Bitmaps 75 height = bmp[j + i*(heightMap->w )]; 76 77 78 /*height = heightMap->format->palette->colors[offset].r + 79 heightMap->format->palette->colors[offset].g + 80 heightMap->format->palette->colors[offset].b ; */ 78 81 79 82 80 this->addVertex( 20*(heightMap->h - i) , (( height)/15) - 30 ,20*j);81 82 83 SDL_UnlockSurface(heightMap);83 this->addVertex( 20*(heightMap->h - i) , ((double)( 100-(double)offset)/5) - 50 ,20*j); 84 } 85 } 86 SDL_UnlockSurface(heightMap); 84 87 85 int c = (heightMap->w) ; 86 int g = 0; 88 int c = (heightMap->w) ; // One line 89 for(int i = 0; i < (heightMap->w) -1 ; i += 1) 90 { 91 for(int j = 0; j < (heightMap->h)/1 - 1; j++) 92 { 93 94 /* Two Triangles or ...*/ 95 96 //this->addFace (3, VERTEX_ONLY,j+1+i*c ,j + (i+1)*c, j + i*c ); 97 //this->addFace (3, VERTEX_ONLY,j + (i+1)*c +1 ,j + (i+1)*c,j+i*c +1 ); 98 99 /* ... one square*/ 87 100 88 for(int i = 0; i < (heightMap->w) -1 ; i += 1) 89 { 90 for(int j = 0; j < (heightMap->h)/1 - 1; j++) 91 { 92 //this->addFace (3, VERTEX_ONLY,j+1+i*c ,j + (i+1)*c, j + i*c ); 93 94 //this->addFace (3, VERTEX_ONLY,j + (i+1)*c +1 ,j + (i+1)*c,j+i*c +1 ); 95 this->addFace (4 ,VERTEX_ONLY,j+i*c,j+(i+1)*c ,j + (i+1)*c +1, j +i*c+1 ); 96 } 101 this->addFace (4 ,VERTEX_ONLY,j+i*c,j+(i+1)*c ,j + (i+1)*c +1, j +i*c+1 ); 102 } 97 103 98 104 99 105 100 106 } 101 107 102 108 103 } 109 }//if 104 110 else 105 111 { 106 //this->setName("HardCore"); 112 113 //make a cube 114 this->setName("HardCore"); 107 115 this->addVertex (-0.5, -0.5, 0.5); 108 116 this->addVertex (0.5, -0.5, 0.5);
Note: See TracChangeset
for help on using the changeset viewer.