Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5990 in orxonox.OLD


Ignore:
Timestamp:
Dec 8, 2005, 4:07:19 PM (18 years ago)
Author:
bottac
Message:

Now, HeightMap seems to set the height of its vertices correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/height_map/src/lib/graphics/importer/height_map.cc

    r5989 r5990  
    3535{
    3636   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       
    3940                 PRINTF(0)("loading Image %s\n", height_map_name);
    4041                 PRINTF(0)("width : %i\n", heightMap->w);
    4142                 PRINTF(0)("hight : %i\n", heightMap->h);
    4243                 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);           
    4549                }
    4650                 
    47             else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
     51     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    4852}
    4953
     
    5660void HeightMap::load()
    5761{
    58  long height = 0;
     62 unsigned int height = 0;
    5963 int offset = 0;
    6064 char *  bmp = (char*) heightMap->pixels;
    6165
    62   if(heightMap != NULL /* && heightMap->format->BitsPerPixel == 8 */)
     66  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    6367        {
    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 ; */
    7881                                       
    7982                                       
    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);
    8487
    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*/
    87100
    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            }
    97103                               
    98104                       
    99105                               
    100                         }
     106        }
    101107               
    102108
    103         }
     109        }//if
    104110  else
    105111        {
    106   //this->setName("HardCore");
     112
     113  //make a cube
     114  this->setName("HardCore");
    107115  this->addVertex (-0.5, -0.5, 0.5);
    108116  this->addVertex (0.5, -0.5, 0.5);
Note: See TracChangeset for help on using the changeset viewer.