Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7467 in orxonox.OLD


Ignore:
Timestamp:
May 1, 2006, 10:46:01 PM (18 years ago)
Author:
patrick
Message:

orxonox: auto reformat of the height map source file.

Location:
trunk/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r7221 r7467  
    3030#endif
    3131
     32
    3233Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm )
    3334{
    34 
    35 PRINTF(0)("Tile Constructor\n");
    36 highResModel = new VertexArrayModel();
    37 lowResModel  = new VertexArrayModel();
    38 
    39 this->load(i1,j1,i2,j2,hm,highResModel,4);
    40 this->load(i1,j1,i2,j2,hm,lowResModel, 8);
    41 }
    42 
    43 Tile::Tile()
    44 {
    45 PRINTF(0)("ooops *********************************************************************************************************************************************************************************************************** \n");
     35  PRINTF(0)("Tile Constructor\n");
     36  highResModel = new VertexArrayModel();
     37  lowResModel  = new VertexArrayModel();
     38
     39  this->load(i1,j1,i2,j2,hm,highResModel,4);
     40  this->load(i1,j1,i2,j2,hm,lowResModel, 8);
    4641}
    4742
    4843Tile::~Tile()
    4944{
    50  delete highResModel;
    51  delete lowResModel;
     45  delete highResModel;
     46  delete lowResModel;
    5247}
    5348
    5449void Tile::draw()
    5550{
    56          // This Draws the LOD's
    57                                                                 //FIXME
    58     float cameraDistance = (State::getCameraNode()->getAbsCoor() - Vector(this->x, hmref->offsetY , this->z) ).len();
    59         if(cameraDistance < 0) cameraDistance = -cameraDistance;
    60     if(cameraDistance > 5000 )
    61     {
    62      return;
    63     }
    64     else if (cameraDistance >= 1000 )
    65     {
    66       this->drawLowRes();
    67     }
    68     else
    69     {
    70       this->drawHighRes();
    71     }
     51  // This Draws the LOD's
     52  //FIXME
     53  float cameraDistance = (State::getCameraNode()->getAbsCoor() - Vector(this->x, hmref->offsetY , this->z) ).len();
     54  if(cameraDistance < 0)
     55    cameraDistance = -cameraDistance;
     56  if(cameraDistance > 5000 )
     57  {
     58    return;
     59  }
     60  else if (cameraDistance >= 1000 )
     61  {
     62    this->drawLowRes();
     63  }
     64  else
     65  {
     66    this->drawHighRes();
     67  }
    7268}
    7369
    7470void Tile::drawHighRes()
    7571{
    76  highResModel->draw();
     72  highResModel->draw();
    7773}
    7874
    7975void Tile::drawLowRes()
    8076{
    81  lowResModel->draw();
     77  lowResModel->draw();
    8278}
    8379
     
    8783{
    8884
    89         #define heightMap hm->heightMap
     85#define heightMap hm->heightMap
    9086        #define colours   hm->colours
    9187        #define scaleX hm->scaleX
     
    9793        #define normalVectorField hm->normalVectorField
    9894
    99         hmref = hm; // FIXME
    100 
    101         this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX;
    102         this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ;
    103 
    104         int sampleRate = Res;
    105 
    106         float height = 0;
    107         int offset = 0;
    108 
    109         float r = 0.0;
    110         float g = 0.0;
    111         float b = 0.0;
    112 
    113 
    114 
    115 
    116  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    117 
    118         SDL_LockSurface(heightMap);
    119         SDL_LockSurface(hm->colourMap);
    120 
    121         for(int i = i1 ; i <= i2  ; i +=sampleRate)
    122         {
    123                 int w = 0;
    124 
    125 
    126 
    127                  if(hm->hasColourMap)
    128                  {
    129                  r = colours[(3*w+2 + 3*i*(heightMap->w )) ];
    130                  g = colours[(3*w+1 + 3*i*(heightMap->w)) ];
    131                  b = colours[(3*w+0 + 3*i*(heightMap->w))];
    132                  }
    133 
    134                 w = j1;
    135                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    136                 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);
    137                 model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    138 
    139                 model->addColor(r/255.0,g/255.0,b/255.0);
    140 
    141             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    142             {
    143 
    144 
    145                  // To be fixed
    146                  if(hm->hasColourMap)
    147                  {
    148                  r = colours[(3*j+2 + 3*i*(heightMap->w )) ];
    149                  g =  colours[(3*j+1 + 3*i*(heightMap->w)) ];
    150                  b =  colours[(3*j+0 + 3*i*(heightMap->w))];
    151                  }
    152                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    153                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    154                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    155                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    156                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    157                 height=height/5.0;
    158 
    159                 model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
    160                 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);
    161                 model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
    162 
    163                 //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
    164 
    165                 model->addColor(r/255.0,g/255.0,b/255.0);
    166                 w = j;
    167             }
    168 
    169 
    170                 model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    171                 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);
    172                 model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
    173                 model->addColor(r/255.0,g/255.0,b/255.0);
    174 
    175         }
    176 
    177 
    178 
    179 
    180 
    181         SDL_UnlockSurface(heightMap);
    182         int cnt = 0;
    183         for(int i = i1   ; i < i2  ; i +=sampleRate)
    184         {
    185 
    186             for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
    187             {
    188 
    189                 model->addIndice(cnt);
    190                 model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
    191                 cnt++;
    192 
    193             }
    194 
    195 
    196 
    197                  model->newStripe();
    198 
    199 
    200         }
    201          cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
    202 
    203                 for(int j = j1 ; j <= j2    ;  j += sampleRate)
    204             {
    205                 int i = i1;
    206 
    207                  // To be fixed
    208                  if(hm->hasColourMap)
    209                  {
    210                  r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ];
    211                  g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ];
    212                  b = (float)colours[(3*j+0 + 3*i*(heightMap->w))];
    213                  }
    214 
    215                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    216                 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);
    217                 model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
    218                 model->addColor(r/255.0,g/255.0,b/255.0);
    219 
    220             }
    221 
    222                 for(int j = j1  ; j <= j2    ;  j += sampleRate)
    223             {
    224                 int i = i1;
    225                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    226                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    227                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    228                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    229                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    230                 height=height/5.0;
    231 
    232                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    233                 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);
    234                 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    235                 model->addColor(r/255.0,g/255.0,b/255.0);
    236 
    237             }
    238 
    239 
    240 
    241             for(int j = j1  ; j <= j2    ;  j += sampleRate)
    242             {
    243                 int i = i2;
    244 
    245                  // To be fixed
    246                  if(hm->hasColourMap)
    247                  {
    248                  r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    249                  g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    250                  b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    251                  }
    252 
    253                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    254                 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);
    255                 model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
    256                 model->addColor(r/255.0,g/255.0,b/255.0);
    257 
    258             }
    259 
    260 
    261             for(int j = j1 ; j <= j2    ;  j += sampleRate)
    262             {
    263                 int i = i2;
    264                 height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    265                 height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    266                 height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    267                 height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];
    268                 height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
    269                 height=height/5.0;
    270                 model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    271                 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);
    272                 model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
    273                 model->addColor(r/255.0,g/255.0,b/255.0);
    274 
    275             }
    276 
    277 
    278 
    279 
    280          // link Boarder Stripe
    281             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    282             {
    283 
    284                 model->addIndice(cnt);
    285                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    286                 cnt++;
    287 
    288             }
    289 
    290                 cnt++;
    291 
    292                  model->newStripe();
    293 
    294 
    295 
    296 
    297 
    298          cnt += (j2-j1)/ sampleRate;
    299 
    300         // link 2nd BoarderStripe
    301             for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
    302             {
    303 
    304                 model->addIndice(cnt);
    305                 model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
    306                 cnt++;
    307 
    308             }
    309 
    310 
    311             SDL_UnlockSurface(hm->colourMap);
    312 
    313          model->finalize();
    314 
    315 
    316 
    317 
    318         #undef heightMap
     95  hmref = hm; // FIXME
     96
     97  this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX;
     98  this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ;
     99
     100  int sampleRate = Res;
     101
     102  float height = 0;
     103  int offset = 0;
     104
     105  float r = 0.0;
     106  float g = 0.0;
     107  float b = 0.0;
     108
     109
     110
     111
     112  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
     113
     114    SDL_LockSurface(heightMap);
     115  SDL_LockSurface(hm->colourMap);
     116
     117  for(int i = i1 ; i <= i2  ; i +=sampleRate)
     118  {
     119    int w = 0;
     120
     121
     122
     123    if(hm->hasColourMap)
     124    {
     125      r = colours[(3*w+2 + 3*i*(heightMap->w )) ];
     126      g = colours[(3*w+1 + 3*i*(heightMap->w)) ];
     127      b = colours[(3*w+0 + 3*i*(heightMap->w))];
     128    }
     129
     130    w = j1;
     131    model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     132    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);
     133    model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     134
     135    model->addColor(r/255.0,g/255.0,b/255.0);
     136
     137    for(int j = j1  ; j <= j2    ;  j += sampleRate)
     138    {
     139
     140
     141      // To be fixed
     142      if(hm->hasColourMap)
     143      {
     144        r = colours[(3*j+2 + 3*i*(heightMap->w )) ];
     145        g =  colours[(3*j+1 + 3*i*(heightMap->w)) ];
     146        b =  colours[(3*j+0 + 3*i*(heightMap->w))];
     147      }
     148      height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     149      height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     150      height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     151      height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
     152      height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     153      height=height/5.0;
     154
     155      model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
     156      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);
     157      model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
     158
     159      //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
     160
     161      model->addColor(r/255.0,g/255.0,b/255.0);
     162      w = j;
     163    }
     164
     165
     166    model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     167    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);
     168    model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     169    model->addColor(r/255.0,g/255.0,b/255.0);
     170
     171  }
     172
     173
     174
     175
     176
     177  SDL_UnlockSurface(heightMap);
     178  int cnt = 0;
     179  for(int i = i1   ; i < i2  ; i +=sampleRate)
     180  {
     181
     182    for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
     183    {
     184
     185      model->addIndice(cnt);
     186      model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
     187      cnt++;
     188
     189    }
     190
     191
     192
     193    model->newStripe();
     194
     195
     196  }
     197  cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
     198
     199  for(int j = j1 ; j <= j2    ;  j += sampleRate)
     200  {
     201    int i = i1;
     202
     203    // To be fixed
     204    if(hm->hasColourMap)
     205    {
     206      r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ];
     207      g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ];
     208      b = (float)colours[(3*j+0 + 3*i*(heightMap->w))];
     209    }
     210
     211    model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     212    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);
     213    model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
     214    model->addColor(r/255.0,g/255.0,b/255.0);
     215
     216  }
     217
     218  for(int j = j1  ; j <= j2    ;  j += sampleRate)
     219  {
     220    int i = i1;
     221    height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     222    height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     223    height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     224    height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
     225    height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     226    height=height/5.0;
     227
     228    model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     229    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);
     230    model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     231    model->addColor(r/255.0,g/255.0,b/255.0);
     232
     233  }
     234
     235
     236
     237  for(int j = j1  ; j <= j2    ;  j += sampleRate)
     238  {
     239    int i = i2;
     240
     241    // To be fixed
     242    if(hm->hasColourMap)
     243    {
     244      r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
     245      g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
     246      b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
     247    }
     248
     249    model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     250    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);
     251    model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
     252    model->addColor(r/255.0,g/255.0,b/255.0);
     253
     254  }
     255
     256
     257  for(int j = j1 ; j <= j2    ;  j += sampleRate)
     258  {
     259    int i = i2;
     260    height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
     261    height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
     262    height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
     263    height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];
     264    height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     265    height=height/5.0;
     266    model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     267    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);
     268    model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     269    model->addColor(r/255.0,g/255.0,b/255.0);
     270
     271  }
     272
     273
     274
     275
     276  // link Boarder Stripe
     277  for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     278  {
     279
     280    model->addIndice(cnt);
     281    model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     282    cnt++;
     283
     284  }
     285
     286  cnt++;
     287
     288  model->newStripe();
     289
     290
     291
     292
     293
     294  cnt += (j2-j1)/ sampleRate;
     295
     296  // link 2nd BoarderStripe
     297  for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
     298  {
     299
     300    model->addIndice(cnt);
     301    model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
     302    cnt++;
     303
     304  }
     305
     306
     307  SDL_UnlockSurface(hm->colourMap);
     308
     309  model->finalize();
     310
     311
     312
     313
     314#undef heightMap
    319315        #undef colours
    320316        #undef scaleX
     
    330326HeightMap::HeightMap()
    331327{
    332 
    333328}
    334329
    335330HeightMap::HeightMap(const std::string& height_map_name = "")
    336   : VertexArrayModel()
    337 {
    338    this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    339    heightMap =  IMG_Load(height_map_name.c_str());
    340    if(heightMap!=NULL) {
    341 
    342      PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    343                  PRINTF(0)("width : %i\n", heightMap->w);
    344                  PRINTF(0)("height : %i\n", heightMap->h);
    345                  PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    346                  PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    347                  PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    348                  PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    349                  PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    350                  PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    351                 }
    352 
    353                 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
     331    : VertexArrayModel()
     332{
     333  this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     334  heightMap =  IMG_Load(height_map_name.c_str());
     335  if(heightMap!=NULL)
     336  {
     337
     338    PRINTF(0)("loading Image %s\n", height_map_name.c_str());
     339    PRINTF(0)("width : %i\n", heightMap->w);
     340    PRINTF(0)("height : %i\n", heightMap->h);
     341    PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     342    PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     343    PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     344    PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     345    PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     346    PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     347  }
     348
     349  else
     350    PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
    354351
    355352
     
    363360
    364361HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL)
    365   : VertexArrayModel()
    366 {
    367 this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    368 
    369    heightMap =  IMG_Load(height_map_name.c_str());
    370    if(heightMap!=NULL) {
    371 
    372      PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    373                  PRINTF(0)("width : %i\n", heightMap->w);
    374                  PRINTF(0)("height : %i\n", heightMap->h);
    375                  PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
    376                  PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
    377                  PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
    378                  PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
    379                  PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
    380                  PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
    381                 }
    382 
    383                 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
    384 
    385 
    386     generateNormalVectorField();
     362    : VertexArrayModel()
     363{
     364  this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     365
     366  heightMap =  IMG_Load(height_map_name.c_str());
     367  if(heightMap!=NULL)
     368  {
     369
     370    PRINTF(0)("loading Image %s\n", height_map_name.c_str());
     371    PRINTF(0)("width : %i\n", heightMap->w);
     372    PRINTF(0)("height : %i\n", heightMap->h);
     373    PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
     374    PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
     375    PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
     376    PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
     377    PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
     378    PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
     379  }
     380
     381  else
     382    PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
     383
     384
     385  generateNormalVectorField();
    387386
    388387  colourMap=NULL;
     
    393392
    394393  if(colourMap != NULL)
    395                 {
    396                   PRINTF(0)("loading Image %s\n", colour_map_name.c_str());
    397                  PRINTF(0)("width : %i\n", colourMap->w);
    398                  PRINTF(0)("height : %i\n", colourMap->h);
    399                  PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
    400                  PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
    401                  PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
    402                  PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
    403                  PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
    404                  PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
    405                  }
    406                  else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
     394  {
     395    PRINTF(0)("loading Image %s\n", colour_map_name.c_str());
     396    PRINTF(0)("width : %i\n", colourMap->w);
     397    PRINTF(0)("height : %i\n", colourMap->h);
     398    PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
     399    PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
     400    PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
     401    PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
     402    PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
     403    PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
     404  }
     405  else
     406    PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
    407407
    408408
     
    410410  if(colourMap != NULL)
    411411  {
    412   colours = (unsigned char *) colourMap->pixels;
    413   hasColourMap = true;
    414   }
    415   else hasColourMap = false;
     412    colours = (unsigned char *) colourMap->pixels;
     413    hasColourMap = true;
     414  }
     415  else
     416    hasColourMap = false;
    416417
    417418
     
    425426HeightMap::~HeightMap()
    426427{
    427         delete heightMap;
    428         delete colourMap;
    429 
    430 
    431         for(int i=0;i <    heightMap->h/tileSize ; i++)
    432         {
    433         for(int j = 0; j < heightMap->w/ tileSize; j++)
    434         {
    435          delete tiles [i][j];
    436         }
    437         }
    438         for(int i=0;i <    heightMap->h/tileSize ; i++)
    439         delete[] tiles[i];
    440         delete[] tiles;
    441 
    442 
    443 
    444 
    445 
    446 for(int i=0;i<heightMap->h;i++)
    447 delete[] normalVectorField [i];
    448 delete[] normalVectorField;
     428  delete heightMap;
     429  delete colourMap;
     430
     431
     432  for(int i=0;i <    heightMap->h/tileSize ; i++)
     433  {
     434    for(int j = 0; j < heightMap->w/ tileSize; j++)
     435    {
     436      delete tiles [i][j];
     437    }
     438  }
     439  for(int i=0;i <    heightMap->h/tileSize ; i++)
     440    delete[] tiles[i];
     441  delete[] tiles;
     442
     443
     444
     445
     446
     447  for(int i=0;i<heightMap->h;i++)
     448    delete[] normalVectorField [i];
     449  delete[] normalVectorField;
    449450
    450451
     
    459460{
    460461
    461 //Create a Dynamicly sized 2D-Array for Tiles
    462 tiles =  new Tile** [heightMap->h/tileSize];
    463 for(int i=0;i <    heightMap->h/tileSize ; i++)
    464 tiles [i]= new (Tile* [heightMap->w /tileSize ]);
    465 
    466 //SetUp Arrays
    467 for(int i = 0; i < (heightMap->h  )/ tileSize; i ++)
    468 {
    469         for(int j = 0; j < (heightMap->w )/ tileSize; j ++)
    470         {
    471 
    472          tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
    473         }
    474 }
     462  //Create a Dynamicly sized 2D-Array for Tiles
     463  tiles =  new Tile** [heightMap->h/tileSize];
     464  for(int i=0;i <    heightMap->h/tileSize ; i++)
     465    tiles [i]= new (Tile* [heightMap->w /tileSize ]);
     466
     467  //SetUp Arrays
     468  for(int i = 0; i < (heightMap->h  )/ tileSize; i ++)
     469  {
     470    for(int j = 0; j < (heightMap->w )/ tileSize; j ++)
     471    {
     472
     473      tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
     474    }
     475  }
    475476
    476477}
     
    479480void HeightMap::draw()
    480481{
    481 const PNode* camera = State::getCameraNode();
    482 Vector v = camera->getAbsCoor();
    483 
    484 int i_min = 0;
    485 int i_max = (heightMap->h )/ tileSize;
    486 int j_min = 0;
    487 int j_max= (heightMap->w  ) / tileSize;
    488 
    489 
    490 
    491 for(int i = 0; i <  i_max        ; i ++)
    492 {
    493         for(int j = 0; j < j_max ; j++)
    494         {
    495          tiles[i][j]->draw();
    496         }
    497 }
     482  const PNode* camera = State::getCameraNode();
     483  Vector v = camera->getAbsCoor();
     484
     485  int i_min = 0;
     486  int i_max = (heightMap->h )/ tileSize;
     487  int j_min = 0;
     488  int j_max= (heightMap->w  ) / tileSize;
     489
     490
     491
     492  for(int i = 0; i <  i_max        ; i ++)
     493  {
     494    for(int j = 0; j < j_max ; j++)
     495    {
     496      tiles[i][j]->draw();
     497    }
     498  }
    498499
    499500}
    500501void HeightMap::generateNormalVectorField()
    501502{
    502 int delta = 1;
    503 heights  = (unsigned char*) heightMap->pixels;
    504 
    505 //Create a Dynamicly sized 2D-Array to store our normals
    506 normalVectorField =  new Vector* [heightMap->h];
    507 for(int i=0;i<heightMap->h;i++)
    508 normalVectorField [i]= new (Vector [heightMap->w]);
    509 
    510 
    511 
    512 
    513 // Initialize
    514 for(int i=0; i< heightMap->h; i++)
    515 {
    516         for(int j = 0; j> heightMap->w; j++)
    517         {
    518         Vector v = Vector(0.0, 1.0, 0.0);
    519          normalVectorField[i][j] = v;
    520         }
    521 }
    522 
    523 // !!! Does not yet calculate the normals of some border points!!!!!
    524 
    525 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    526         {
    527         SDL_LockSurface(heightMap);
    528         for(int i = 0 ; i < heightMap->h - 1  ; i ++)
    529         {
    530             for(int j = 0; j < heightMap->w  - 1  ;  j ++)
    531             {
    532 
    533 
    534                 delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
    535                 Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
    536 
    537                 delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
    538                 Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
    539 
    540 
    541                  normalVectorField[i][j] = b.cross(a);
    542                  normalVectorField[i][j].normalize();
    543 
    544              }
    545         }
    546         SDL_UnlockSurface(heightMap);
    547 
    548 }
     503  int delta = 1;
     504  heights  = (unsigned char*) heightMap->pixels;
     505
     506  //Create a Dynamicly sized 2D-Array to store our normals
     507  normalVectorField =  new Vector* [heightMap->h];
     508  for(int i=0;i<heightMap->h;i++)
     509    normalVectorField [i]= new (Vector [heightMap->w]);
     510
     511
     512
     513
     514  // Initialize
     515  for(int i=0; i< heightMap->h; i++)
     516  {
     517    for(int j = 0; j> heightMap->w; j++)
     518    {
     519      Vector v = Vector(0.0, 1.0, 0.0);
     520      normalVectorField[i][j] = v;
     521    }
     522  }
     523
     524  // !!! Does not yet calculate the normals of some border points!!!!!
     525
     526  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
     527  {
     528    SDL_LockSurface(heightMap);
     529    for(int i = 0 ; i < heightMap->h - 1  ; i ++)
     530    {
     531      for(int j = 0; j < heightMap->w  - 1  ;  j ++)
     532      {
     533
     534
     535        delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
     536        Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
     537
     538        delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
     539        Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
     540
     541
     542        normalVectorField[i][j] = b.cross(a);
     543        normalVectorField[i][j].normalize();
     544
     545      }
     546    }
     547    SDL_UnlockSurface(heightMap);
     548
     549  }
    549550
    550551
     
    556557void HeightMap::scale(Vector v)
    557558{
    558  scaleX = v.x;
    559  scaleY = v.y;
    560  scaleZ = v.z;
    561  generateNormalVectorField();
     559  scaleX = v.x;
     560  scaleY = v.y;
     561  scaleZ = v.z;
     562  generateNormalVectorField();
    562563}
    563564
    564565void HeightMap::setAbsCoor(Vector v)
    565566{
    566  offsetX = v.x;
    567  offsetY = v.y;
    568  offsetZ  = v.z;
     567  offsetX = v.x;
     568  offsetY = v.y;
     569  offsetZ  = v.z;
    569570}
    570571
     
    573574{
    574575
    575  x -= offsetX;
    576  y -= offsetZ;
    577 
    578 
    579  int xInt = (int)x / scaleX;  x -= (float)((int)x); xInt = heightMap->h - xInt;
    580  int yInt = (int)y / scaleZ;    y -= (float) ((int) y); /*yInt = heightMap->w - yInt;*/
    581 
    582  //PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y);
    583 
    584  if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return 0;
    585  if( y >= 0.5*x)
    586  {
    587         // Check for ...
    588  }
    589 
    590  float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
    591 
    592 
    593  float a = normalVectorField[(xInt)][yInt].x;
    594  float b = normalVectorField [(xInt)][yInt].z;
    595  float c = normalVectorField [(xInt)][yInt].y;
    596 
    597  PRINTF(0)("a: %f \n" ,a);
     576  x -= offsetX;
     577  y -= offsetZ;
     578
     579
     580  int xInt = (int)x / scaleX;
     581  x -= (float)((int)x);
     582  xInt = heightMap->h - xInt;
     583  int yInt = (int)y / scaleZ;
     584  y -= (float) ((int) y); /*yInt = heightMap->w - yInt;*/
     585
     586  //PRINTF(0)("xInt: %i, yInt: %i, x: %f, y: %f\n", xInt, yInt, x, y);
     587
     588  if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  )
     589    return 0;
     590  if( y >= 0.5*x)
     591  {
     592    // Check for ...
     593  }
     594
     595  float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
     596
     597
     598  float a = normalVectorField[(xInt)][yInt].x;
     599  float b = normalVectorField [(xInt)][yInt].z;
     600  float c = normalVectorField [(xInt)][yInt].y;
     601
     602  PRINTF(0)("a: %f \n" ,a);
    598603  PRINTF(0)("b: %f \n" ,b);
    599    PRINTF(0)("c: %f \n" ,c);
    600 
    601  height -= ( (a/c)*(x) + (b/c)*(y));
    602 
    603  PRINTF(0)("height: %f \n" ,height );
    604  return (height + offsetZ);
    605 }
     604  PRINTF(0)("c: %f \n" ,c);
     605
     606  height -= ( (a/c)*(x) + (b/c)*(y));
     607
     608  PRINTF(0)("height: %f \n" ,height );
     609  return (height + offsetZ);
     610}
  • trunk/src/lib/graphics/importer/height_map.h

    r7466 r7467  
    3535{
    3636  public:
    37     Tile();
    3837    Tile(int i1, int j1, int i2, int j2, HeightMap* hm) ;
    3938    virtual ~Tile();
Note: See TracChangeset for help on using the changeset viewer.