Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6579 in orxonox.OLD for branches


Ignore:
Timestamp:
Jan 18, 2006, 3:55:37 PM (18 years ago)
Author:
bottac
Message:

HeightMap may now be loaded from a .oxw .

Location:
branches/height_map_merge/src
Files:
3 edited

Legend:

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

    r6494 r6579  
    3030#endif
    3131
    32 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm )
     32Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm ) 
    3333{
    3434
     
    3737lowResModel  = new VertexArrayModel();
    3838
    39 this->load(i1,j1,i2,j2,hm,highResModel,4);
    40 this->load(i1,j1,i2,j2,hm,lowResModel, 32);
     39this->load(i1,j1,i2,j2,hm,highResModel,2);
     40this->load(i1,j1,i2,j2,hm,lowResModel, 8);
    4141}
    4242
     
    5454void Tile::draw()
    5555{
    56  lowResModel->draw();
     56 lowResModel->draw(); 
    5757}
    5858
     
    7171void Tile::load(int i1, int j1, int i2, int j2, HeightMap* hm, VertexArrayModel* model, int Res)
    7272{
    73 
    74         #define heightMap hm->heightMap
    75         #define colours   hm->colours
    76         #define scaleX hm->scaleX
    77         #define scaleY hm->scaleY
    78         #define scaleZ hm->scaleZ
    79         #define shiftX hm->shiftX
    80         #define shiftY hm->shiftY
    81         #define shiftZ hm->shiftZ
    82         #define normalVectorField hm->normalVectorField
    83 
    84         int sampleRate = Res;
    85 
    86         unsigned char height = 0;
    87         int offset = 0;
    88 
    89         float r = 0.0;
    90         float g = 0.0;
    91         float b = 0.0;
    92 
    93 
     73       
     74        #define heightMap hm->heightMap
     75        #define colours   hm->colours
     76        #define scaleX hm->scaleX
     77        #define scaleY hm->scaleY
     78        #define scaleZ hm->scaleZ
     79        #define shiftX hm->shiftX
     80        #define shiftY hm->shiftY
     81        #define shiftZ hm->shiftZ
     82        #define normalVectorField hm->normalVectorField
     83       
     84        int sampleRate = Res;
     85       
     86         float height = 0;
     87        int offset = 0;
     88       
     89        float r = 0.0;
     90        float g = 0.0;
     91        float b = 0.0;
     92
     93 
    9494PRINTF(0)("loadin * \n");
    95 
     95 
    9696 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    97 
    98         SDL_LockSurface(heightMap);
    99 
    100         for(int i = i1 ; i <= i2  ; i +=sampleRate)
    101         {
    102                 int w = 0;
    103 
    104 
    105 
    106                  if(hm->hasColourMap)
    107                  {
    108                  r = (float)colours[3*w+2 + 3*i*(heightMap->w )];
    109                  g = (float)colours[3*w+1 + 3*i*(heightMap->w)];
    110                  b = (float)colours[3*w+0 + 3*i*(heightMap->w)];
    111                  }
    112 
    113                 w = j1;
    114                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    115                 model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
    116                 model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
    117                 model->addColor(r/255.0,g/255.0,b/255.0);
    118 
    119             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    120             {
    121 
    122 
    123                  // To be fixed
    124                  if(hm->hasColourMap)
    125                  {
    126                  r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    127                  g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    128                  b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    129                  }
    130                 height =  hm->heights[j+sampleRate + i*(heightMap->w )];
    131                 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
    132                 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    133                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
    134 
    135                 model->addColor(r/255.0,g/255.0,b/255.0);
    136 
    137 
    138                 w = j;
    139             }
    140 
    141 
    142                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    143                 model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
    144                 model->addTexCoor((((w+sampleRate)/sampleRate)%4)/4.0,(((i+ sampleRate)/sampleRate)%4)/4.0);
    145                 model->addColor(r/255.0,g/255.0,b/255.0);
    146 
    147         }
    148 
    149 
    150 
    151 
    152 
    153         SDL_UnlockSurface(heightMap);
    154         int cnt = 0;
    155         for(int i = i1   ; i < i2  ; i +=sampleRate)
    156         {
    157 
    158             for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
    159             {
    160 
    161                 model->addIndice(cnt);
    162                 model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
    163                 cnt++;
    164 
    165             }
    166 
    167 
    168 
    169                  model->newStripe();
    170 
    171 
    172         }
    173          cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
    174 
    175                 for(int j = j1 ; j <= j2    ;  j += sampleRate)
    176             {
    177                 int i = i1;
    178 
    179                  // To be fixed
    180                  if(hm->hasColourMap)
    181                  {
    182                  r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    183                  g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    184                  b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    185                  }
    186 
    187                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    188                 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    189                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i - sampleRate)/sampleRate)%texRate)/texRatef);
    190                 model->addColor(r/255.0,g/255.0,b/255.0);
    191 
    192             }
    193 
    194                 for(int j = j1  ; j <= j2    ;  j += sampleRate)
    195             {
    196                 int i = i1;
    197                 height =  hm->heights[j+sampleRate + i*(heightMap->w )];
    198                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    199                 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    200                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i)/sampleRate)%texRate)/texRatef);
    201                 model->addColor(r/255.0,g/255.0,b/255.0);
    202 
    203             }
    204 
    205 
    206 
    207             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    208             {
    209                 int i = i2;
    210 
    211                  // To be fixed
    212                  if(hm->hasColourMap)
    213                  {
    214                  r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    215                  g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    216                  b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    217                  }
    218 
    219                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    220                 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    221                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
    222                 model->addColor(r/255.0,g/255.0,b/255.0);
    223 
    224             }
    225 
    226 
    227             for(int j = j1 ; j <= j2    ;  j += sampleRate)
    228             {
    229                 int i = i2;
    230                 height =  hm->heights[j+sampleRate + i*(heightMap->w )];
    231                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    232                 model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
    233                 model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
    234                 model->addColor(r/255.0,g/255.0,b/255.0);
    235 
    236             }
    237 
    238 
    239 
    240 
    241          // link Boarder Stripe
    242             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    243             {
    244 
    245                 model->addIndice(cnt);
    246                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    247                 cnt++;
    248 
    249             }
    250 
    251                 cnt++;
    252 
    253                  model->newStripe();
    254 
    255 
    256 
    257 
    258 
    259          cnt += (j2-j1)/ sampleRate;
    260 
    261         // link 2nd BoarderStripe
    262             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    263             {
    264 
    265                 model->addIndice(cnt);
    266                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    267                 cnt++;
    268 
    269             }
    270 
    271 
    272 
    273          model->finalize();
    274 
    275 
    276 
    277 
    278         #undef heightMap
    279         #undef colours
    280         #undef scaleX
    281         #undef scaleY
    282         #undef scaleZ
    283         #undef shiftX
    284         #undef shiftY
    285         #undef shiftZ
    286         #undef normalVectorField
    287 
     97       
     98        SDL_LockSurface(heightMap);
     99
     100        for(int i = i1 ; i <= i2  ; i +=sampleRate)
     101        {
     102                int w = 0;
     103
     104               
     105               
     106                 if(hm->hasColourMap)
     107                 {
     108                 r = (float)colours[3*w+2 + 3*i*(heightMap->w )];
     109                 g = (float)colours[3*w+1 + 3*i*(heightMap->w)];
     110                 b = (float)colours[3*w+0 + 3*i*(heightMap->w)];
     111                 }
     112               
     113                w = j1;
     114                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     115                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
     116                model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
     117                model->addColor(r/255.0,g/255.0,b/255.0);
     118               
     119            for(int j = j1  ; j <= j2    ;  j += sampleRate)
     120            {
     121           
     122           
     123                 // To be fixed
     124                 if(hm->hasColourMap)
     125                 {
     126                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     127                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     128                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     129                 }
     130                height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
     131                height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
     132                height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
     133                height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
     134                height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
     135               
     136                height=height/5.0;
     137               
     138                model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right     
     139                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
     140                model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     141               
     142                //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
     143               
     144                model->addColor(r/255.0,g/255.0,b/255.0);
     145                w = j;
     146            }
     147               
     148               
     149                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     150                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
     151                model->addTexCoor((((w+sampleRate)/sampleRate))/4.0,(((i+ sampleRate)/sampleRate))/4.0);
     152                model->addColor(r/255.0,g/255.0,b/255.0);
     153               
     154        }
     155       
     156       
     157       
     158
     159
     160        SDL_UnlockSurface(heightMap);
     161        int cnt = 0;
     162        for(int i = i1   ; i < i2  ; i +=sampleRate)
     163        {
     164               
     165            for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
     166            {
     167               
     168                model->addIndice(cnt);
     169                model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
     170                cnt++;
     171               
     172            }
     173               
     174               
     175               
     176                 model->newStripe();   
     177               
     178               
     179        }
     180         cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
     181       
     182                for(int j = j1 ; j <= j2    ;  j += sampleRate)
     183            {
     184                int i = i1;
     185           
     186                 // To be fixed
     187                 if(hm->hasColourMap)
     188                 {
     189                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     190                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     191                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     192                 }
     193               
     194                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     195                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
     196                model->addTexCoor(((j/sampleRate))/texRatef,(((i - sampleRate)/sampleRate))/texRatef);
     197                model->addColor(r/255.0,g/255.0,b/255.0);               
     198       
     199            }
     200
     201                for(int j = j1  ; j <= j2    ;  j += sampleRate)
     202            {
     203                int i = i1;
     204                height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
     205                height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
     206                height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
     207                height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
     208                height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
     209                height=height/5.0;
     210               
     211                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
     212                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
     213                model->addTexCoor(((j/sampleRate))/texRatef,(((i)/sampleRate))/texRatef);
     214                model->addColor(r/255.0,g/255.0,b/255.0);
     215           
     216            }
     217           
     218               
     219           
     220            for(int j = j1  ; j <= j2    ;  j += sampleRate)
     221            {
     222                int i = i2;
     223           
     224                 // To be fixed
     225                 if(hm->hasColourMap)
     226                 {
     227                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     228                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     229                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     230                 }
     231               
     232                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     233                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
     234                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
     235                model->addColor(r/255.0,g/255.0,b/255.0);               
     236       
     237            }
     238                   
     239           
     240            for(int j = j1 ; j <= j2    ;  j += sampleRate)
     241            {
     242                int i = i2;
     243                        height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
     244                height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
     245                height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
     246                height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
     247                height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
     248                height=height/5.0;
     249                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right     
     250                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
     251                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
     252                model->addColor(r/255.0,g/255.0,b/255.0);
     253           
     254            }
     255           
     256
     257       
     258       
     259         // link Boarder Stripe
     260            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     261            {
     262               
     263                model->addIndice(cnt);
     264                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     265                cnt++;
     266               
     267            }
     268               
     269                cnt++;
     270               
     271                 model->newStripe();   
     272               
     273               
     274       
     275       
     276       
     277         cnt += (j2-j1)/ sampleRate;
     278       
     279        // link 2nd BoarderStripe
     280            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     281            {
     282               
     283                model->addIndice(cnt);
     284                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     285                cnt++;
     286               
     287            }
     288         
     289           
     290       
     291         model->finalize();
     292         
     293         
     294         
     295         
     296        #undef heightMap
     297        #undef colours   
     298        #undef scaleX
     299        #undef scaleY
     300        #undef scaleZ
     301        #undef shiftX
     302        #undef shiftY
     303        #undef shiftZ
     304        #undef normalVectorField
     305         
    288306}
    289307
     
    299317   if(heightMap!=NULL) {
    300318
    301                 PRINTF(0)("loading Image %s\n", height_map_name);
    302                 PRINTF(0)("width : %i\n", heightMap->w);
    303                 PRINTF(0)("height : %i\n", heightMap->h);
    304                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    305                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    306                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    307                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    308                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    309                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    310                 }
     319                PRINTF(0)("loading Image %s\n", height_map_name);
     320                PRINTF(0)("width : %i\n", heightMap->w);
     321                PRINTF(0)("height : %i\n", heightMap->h);
     322                PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     323                PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     324                PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     325                PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     326                PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     327                PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     328                }
    311329
    312330     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
    313331
    314 
     332       
    315333  generateNormalVectorField();
    316334
     
    328346   if(heightMap!=NULL) {
    329347
    330                 PRINTF(0)("loading Image %s\n", height_map_name);
    331                 PRINTF(0)("width : %i\n", heightMap->w);
    332                 PRINTF(0)("height : %i\n", heightMap->h);
    333                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    334                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    335                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    336                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    337                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    338                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    339                 }
     348                PRINTF(0)("loading Image %s\n", height_map_name);
     349                PRINTF(0)("width : %i\n", heightMap->w);
     350                PRINTF(0)("height : %i\n", heightMap->h);
     351                PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     352                PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     353                PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     354                PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     355                PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     356                PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     357                }
    340358
    341359     else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
     
    349367  colourMap = IMG_Load(colour_map_name);
    350368  }
     369 
    351370  if(colourMap != NULL)
    352                 {
    353                 PRINTF(0)("loading Image %s\n", colour_map_name);
    354                 PRINTF(0)("width : %i\n", colourMap->w);
    355                 PRINTF(0)("height : %i\n", colourMap->h);
    356                 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
    357                 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
    358                 PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
    359                 PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
    360                 PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
    361                 PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
    362                 }
    363                 else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
    364 
    365 
    366 
     371                {
     372                PRINTF(0)("loading Image %s\n", colour_map_name);
     373                PRINTF(0)("width : %i\n", colourMap->w);
     374                PRINTF(0)("height : %i\n", colourMap->h);
     375                PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
     376                PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
     377                PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
     378                PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
     379                PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
     380                PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
     381                }
     382                else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
     383
     384                 
     385                   
    367386  if(colourMap != NULL)
    368387  {
     
    371390  }
    372391  else hasColourMap = false;
    373 
    374 
    375    heights  = (unsigned char*) heightMap->pixels;
     392 
     393       
     394  heights  = (unsigned char*) heightMap->pixels;
    376395
    377396
     
    379398HeightMap::~HeightMap()
    380399{
    381         delete heightMap;
     400        delete heightMap;
    382401}
    383402
     
    393412for(int i = 0; i < (heightMap->h - tileSize )/ tileSize; i ++)
    394413{
    395         for(int j = 0; j < (heightMap->w - tileSize )/ tileSize; j ++)
    396         {
    397 
    398         tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
    399         }
    400 }
    401 
    402 }
    403 
    404 
    405 void HeightMap::draw()
     414        for(int j = 0; j < (heightMap->w - tileSize )/ tileSize; j ++)
     415        {
     416         
     417        tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
     418        }
     419}
     420
     421}
     422
     423
     424void HeightMap::draw() 
    406425{
    407426const PNode* camera = State::getCamera();
     
    409428
    410429int i_min = 1;
    411 int i_max = (heightMap->h - tileSize)/ tileSize;
     430int i_max = (heightMap->h - tileSize )/ tileSize;
    412431int j_min = 1;
    413432int j_max= (heightMap->w - tileSize) / tileSize;
    414433
    415 // calc i_min , i_max j_min and j_maxt
     434// calc i_min , i_max j_min and j_maxt 
    416435
    417436int centerX =  (int)((heightMap->h - ((v.x - shiftX)/ (float)scaleX ))/ tileSize);
     
    426445
    427446
    428 for(int i = 1; i <  i_min        ; i ++)
    429 {
    430         for(int j = 1; j < j_max ; j++)
    431         {
    432 
    433         tiles[i][j]->drawLowRes();
    434         }
    435 }
    436 for(int i = i_min; i <  i_max    ; i ++)
    437 {
    438         for(int j = j_min; j < j_max ; j++)
    439         {
    440 
    441         tiles[i][j]->drawHighRes();
    442         }
    443 }
    444 
    445 for(int i = i_max; i <  (heightMap->h -tileSize)/tileSize        ; i ++)
    446 {
    447         for(int j = 1; j < j_max ; j++)
    448         {
    449 
    450         tiles[i][j]->drawLowRes();
    451         }
     447for(int i = 1; i <  i_min        ; i ++)
     448{
     449        for(int j = 1; j < j_max ; j++)
     450        {
     451               
     452        tiles[i][j]->drawLowRes();
     453        }       
     454} 
     455for(int i = i_min; i <  i_max    ; i ++)
     456{
     457        for(int j = j_min; j < j_max ; j++)
     458        {
     459               
     460        tiles[i][j]->drawHighRes();
     461        }       
     462}
     463
     464for(int i = i_max; i <  (heightMap->h -tileSize)/tileSize        ; i ++)
     465{
     466        for(int j = 1; j < j_max ; j++)
     467        {
     468               
     469        tiles[i][j]->drawLowRes();
     470        }       
    452471}
    453472
     
    455474for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++ )
    456475{
    457         for(int j = 1; j < j_min; j++)
    458         {
    459         tiles[i][j]->drawLowRes();
    460         }
    461 }
    462 for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++)
    463 {
    464         for(int j = j_max; j < (heightMap->w -tileSize)/tileSize; j++ )
    465         {
    466         tiles[i][j]->drawLowRes();
    467         }
     476        for(int j = 1; j < j_min; j++)
     477        {
     478        tiles[i][j]->drawLowRes();
     479        }
     480}
     481for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++) 
     482{
     483        for(int j = j_max; j < (heightMap->w -tileSize)/tileSize; j++ )
     484        {
     485        tiles[i][j]->drawLowRes();
     486        }
    468487}
    469488
     
    484503
    485504if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    486         {
    487         SDL_LockSurface(heightMap);
    488         for(int i = 0 ; i < heightMap->h - 1  ; i ++)
    489         {
    490             for(int j = 0; j < heightMap->w  - 1  ;  j ++)
    491             {
    492 
    493 
    494                 delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
    495                 Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
    496 
    497                 delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
    498                 Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
    499 
    500 
    501                 normalVectorField[i][j] = b.cross(a);
    502                 normalVectorField[i][j].normalize();
    503 
    504              }
    505         }
    506         SDL_UnlockSurface(heightMap);
     505        {
     506        SDL_LockSurface(heightMap);
     507        for(int i = 0 ; i < heightMap->h - 1  ; i ++)
     508        {
     509            for(int j = 0; j < heightMap->w  - 1  ;  j ++)
     510            {
     511
     512
     513                delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
     514                Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
     515
     516                delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
     517                Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
     518
     519
     520                normalVectorField[i][j] = b.cross(a);
     521                normalVectorField[i][j].normalize();
     522                 
     523             }
     524        }
     525        SDL_UnlockSurface(heightMap);
    507526
    508527}
  • branches/height_map_merge/src/lib/graphics/importer/height_map.h

    r6494 r6579  
    1717
    1818
    19 #define texRate      4
     19#define texRate      22
    2020#define texRatef     4.0f
    21 #define tileSize     64
     21#define tileSize     32
    2222
    2323class SDL_Surface;
  • branches/height_map_merge/src/world_entities/terrain.cc

    r6496 r6579  
    4343  this->loadParams(root);
    4444
     45   this->heightMapMaterial = new Material();
     46   heightMapMaterial->setTransparency(1.0);
     47   heightMapMaterial->setIllum(0.2);
     48
     49   heightMapMaterial->setDiffuse(1.0,1.0,1.0);
     50   heightMapMaterial->setAmbient(1.0,1.0,1.0 );
     51   heightMapMaterial->setSpecular(1.0,1.0,1.0);
     52   heightMapMaterial->setShininess(.5);
     53   heightMapMaterial->setTransparency(1.0);
     54
     55   heightMapMaterial->diffuseTexture = NULL;
     56   heightMapMaterial->ambientTexture = NULL;
     57   heightMapMaterial->specularTexture = NULL;
     58 
     59   const  char* texture_name = "pictures/ground.tga";
     60   heightMapMaterial->setDiffuseMap(texture_name);
     61   heightMapMaterial->setAmbientMap(texture_name);
     62   heightMapMaterial->setSpecularMap(texture_name);     
     63   
    4564//  if (this->model != NULL)
    4665    //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f);
     
    135154
    136155  this->heightMap = new HeightMap(hmName, hmColorName);
     156  heightMap->scale(Vector(23.0f,3.5f,23.0f));
     157  heightMap->shift(Vector(-1000.0,-90.0,-4000.0));
     158  heightMap->load();
    137159  delete[] hmName;
    138160  delete[] hmColorName;
     
    187209    this->vegetation->draw();
    188210
    189   if(this->heightMap != NULL)
    190     this->heightMap->draw();
     211  if(this->heightMap)
     212        {
     213        this->heightMapMaterial->select();
     214       
     215   
     216        // glEnable(GL_LIGHTING);
     217        glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
     218        glEnable (GL_COLOR_MATERIAL) ;
     219        this->heightMap->draw();
     220        }
    191221  glPopMatrix();
    192222
Note: See TracChangeset for help on using the changeset viewer.