Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7469 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
May 1, 2006, 11:34:07 PM (19 years ago)
Author:
patrick
Message:

orxonox: introduced some new variable names, some code cleanup

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

Legend:

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

    r7468 r7469  
    3737 *  @param i1
    3838 */
    39 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm )
     39Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* heightMapReference )
    4040{
    4141  PRINTF(0)("Tile Constructor\n");
    42   highResModel = new VertexArrayModel();
    43   lowResModel  = new VertexArrayModel();
    44 
    45   this->load(i1, j1, i2, j2, hm, highResModel,4);
    46   this->load(i1, j1, i2, j2, hm, lowResModel, 8);
     42  this->highResModel = new VertexArrayModel();
     43  this->lowResModel  = new VertexArrayModel();
     44
     45  this->heightMapReference = heightMapReference;
     46
     47  // create high res model
     48  this->load(i1, j1, i2, j2, this->highResModel, 4);
     49  // create low res model
     50  this->load(i1, j1, i2, j2, this->lowResModel, 8);
    4751}
    4852
     
    5761
    5862
     63/**
     64 * this darws the tile in diefferent resolutions
     65 */
    5966void Tile::draw()
    6067{
     
    7380
    7481
    75 /*
    76 */
    77 void Tile::load(int i1, int j1, int i2, int j2, HeightMap* hm, VertexArrayModel* model, int Res)
    78 {
    79 
    80 #define heightMap hm->heightMap
    81         #define colours   hm->colours
    82         #define scaleX hm->scaleX
    83         #define scaleY hm->scaleY
    84         #define scaleZ hm->scaleZ
    85         #define shiftX hm->shiftX
    86         #define shiftY hm->shiftY
    87         #define shiftZ hm->shiftZ
    88         #define normalVectorField hm->normalVectorField
    89 
    90   heightMapReference = hm; // FIXME
    91 
    92   this->x = hm->offsetX + (heightMap->h - ((i1+i2)/2))*scaleX;
    93   this->z = hm->offsetZ + ((j1 + j2 )/2 ) * scaleZ;
    94 
    95   int sampleRate = Res;
     82/**
     83 * loads a tile
     84 */
     85void Tile::load(int i1, int j1, int i2, int j2, VertexArrayModel* model, int sampleRate)
     86{
     87
     88// #define heightMap this->heightMapReference->heightMap
     89#define colours   this->heightMapReference->colours
     90#define scaleX this->heightMapReference->scaleX
     91#define scaleY this->heightMapReference->scaleY
     92#define scaleZ this->heightMapReference->scaleZ
     93#define shiftX this->heightMapReference->shiftX
     94#define shiftY this->heightMapReference->shiftY
     95#define shiftZ this->heightMapReference->shiftZ
     96#define normalVectorField this->heightMapReference->normalVectorField
     97
     98  this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((i1 + i2) / 2)) * scaleX;
     99  this->z = this->heightMapReference->offsetZ + ((j1 + j2 ) / 2 ) * scaleZ;
    96100
    97101  float height = 0;
     
    105109
    106110
    107   if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
    108 
    109     SDL_LockSurface(heightMap);
    110   SDL_LockSurface(hm->colourMap);
     111  if(this->heightMapReference->heightMap != NULL && this->heightMapReference->heightMap->format->BitsPerPixel == 8 )
     112
     113  SDL_LockSurface(this->heightMapReference->heightMap);
     114  SDL_LockSurface(this->heightMapReference->colourMap);
    111115
    112116  for(int i = i1 ; i <= i2  ; i +=sampleRate)
     
    116120
    117121
    118     if(hm->hasColourMap)
    119     {
    120       r = colours[(3*w+2 + 3*i*(heightMap->w )) ];
    121       g = colours[(3*w+1 + 3*i*(heightMap->w)) ];
    122       b = colours[(3*w+0 + 3*i*(heightMap->w))];
     122    if(this->heightMapReference->hasColourMap)
     123    {
     124      r = colours[(3*w+2 + 3*i*(this->heightMapReference->heightMap->w )) ];
     125      g = colours[(3*w+1 + 3*i*(this->heightMapReference->heightMap->w)) ];
     126      b = colours[(3*w+0 + 3*i*(this->heightMapReference->heightMap->w))];
    123127    }
    124128
    125129    w = j1;
    126     model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    127     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);
    128     model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     130    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     131    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x);
     132    model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
    129133
    130134    model->addColor(r/255.0,g/255.0,b/255.0);
     
    135139
    136140      // To be fixed
    137       if(hm->hasColourMap)
     141      if(this->heightMapReference->hasColourMap)
    138142      {
    139         r = colours[(3*j+2 + 3*i*(heightMap->w )) ];
    140         g =  colours[(3*j+1 + 3*i*(heightMap->w)) ];
    141         b =  colours[(3*j+0 + 3*i*(heightMap->w))];
     143        r = colours[(3*j+2 + 3*i*(this->heightMapReference->heightMap->w )) ];
     144        g =  colours[(3*j+1 + 3*i*(this->heightMapReference->heightMap->w)) ];
     145        b =  colours[(3*j+0 + 3*i*(this->heightMapReference->heightMap->w))];
    142146      }
    143       height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    144       height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    145       height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    146       height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    147       height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     147      height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ];
     148      height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ];
     149      height +=  (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate   + (i+1)*(this->heightMapReference->heightMap->w ))];
     150      height +=  (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w )) ];
     151      height +=  (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ];
    148152      height=height/5.0;
    149153
    150       model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
    151       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);
    152       model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
    153 
    154       //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
     154      model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
     155      model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x);
     156      model->addTexCoor((float)(j) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
     157
     158      //PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %this->heightMapReference->h)/100.0);
    155159
    156160      model->addColor(r/255.0,g/255.0,b/255.0);
     
    159163
    160164
    161     model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
    162     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);
    163     model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
     165    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     166    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,normalVectorField[i% this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x);
     167    model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
    164168    model->addColor(r/255.0,g/255.0,b/255.0);
    165169
     
    170174
    171175
    172   SDL_UnlockSurface(heightMap);
     176  SDL_UnlockSurface(this->heightMapReference->heightMap);
    173177  int cnt = 0;
    174178  for(int i = i1   ; i < i2  ; i +=sampleRate)
     
    197201
    198202    // To be fixed
    199     if(hm->hasColourMap)
    200     {
    201       r = (float)colours[(3*j+2 + 3*i*(heightMap->w )) ];
    202       g = (float)colours[(3*j+1 + 3*i*(heightMap->w)) ];
    203       b = (float)colours[(3*j+0 + 3*i*(heightMap->w))];
    204     }
    205 
    206     model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    207     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);
    208     model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
     203    if(this->heightMapReference->hasColourMap)
     204    {
     205      r = (float)colours[(3*j+2 + 3*i*(this->heightMapReference->heightMap->w )) ];
     206      g = (float)colours[(3*j+1 + 3*i*(this->heightMapReference->heightMap->w)) ];
     207      b = (float)colours[(3*j+0 + 3*i*(this->heightMapReference->heightMap->w))];
     208    }
     209
     210    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     211    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].z,normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].x);
     212    model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %this->heightMapReference->heightMap->h)/(texRate));
    209213    model->addColor(r/255.0,g/255.0,b/255.0);
    210214
     
    214218  {
    215219    int i = i1;
    216     height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    217     height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    218     height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    219     height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w )) ];
    220     height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     220    height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ];
     221    height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ];
     222    height +=  (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate   + (i+1)*(this->heightMapReference->heightMap->w ))];
     223    height +=  (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w )) ];
     224    height +=  (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ];
    221225    height=height/5.0;
    222226
    223     model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    224     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);
    225     model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     227    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     228    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][j % this->heightMapReference->heightMap->w].y,normalVectorField[i % this->heightMapReference->heightMap->h][j% this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
     229    model->addTexCoor((float)j /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
    226230    model->addColor(r/255.0,g/255.0,b/255.0);
    227231
     
    235239
    236240    // To be fixed
    237     if(hm->hasColourMap)
    238     {
    239       r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
    240       g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
    241       b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
    242     }
    243 
    244     model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
    245     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);
    246     model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
     241    if(this->heightMapReference->hasColourMap)
     242    {
     243      r = (float)colours[3*j+2 + 3*i*(this->heightMapReference->heightMap->w )];
     244      g = (float)colours[3*j+1 + 3*i*(this->heightMapReference->heightMap->w)];
     245      b = (float)colours[3*j+0 + 3*i*(this->heightMapReference->heightMap->w)];
     246    }
     247
     248    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
     249    model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
     250    model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %this->heightMapReference->heightMap->h)/(texRate));
    247251    model->addColor(r/255.0,g/255.0,b/255.0);
    248252
     
    253257  {
    254258    int i = i2;
    255     height = (float)(unsigned char) hm->heights[(j +sampleRate+ i*(heightMap->w )) ];
    256     height += (float)(unsigned char) hm->heights[(j+ 1 + sampleRate + (i+1)*(heightMap->w )) ];
    257     height +=  (float) (unsigned char) hm->heights[(j -1+ sampleRate   + (i+1)*(heightMap->w ))];
    258     height +=  (float)(unsigned char)hm->heights[(j +sampleRate+ (i+2)*(heightMap->w ))];
    259     height +=  (float)(unsigned char)hm->heights[(j+sampleRate + (i)*(heightMap->w )) ];
     259    height = (float)(unsigned char) this->heightMapReference->heights[(j +sampleRate+ i*(this->heightMapReference->heightMap->w )) ];
     260    height += (float)(unsigned char) this->heightMapReference->heights[(j+ 1 + sampleRate + (i+1)*(this->heightMapReference->heightMap->w )) ];
     261    height +=  (float) (unsigned char) this->heightMapReference->heights[(j -1+ sampleRate   + (i+1)*(this->heightMapReference->heightMap->w ))];
     262    height +=  (float)(unsigned char)this->heightMapReference->heights[(j +sampleRate+ (i+2)*(this->heightMapReference->heightMap->w ))];
     263    height +=  (float)(unsigned char)this->heightMapReference->heights[(j+sampleRate + (i)*(this->heightMapReference->heightMap->w )) ];
    260264    height=height/5.0;
    261     model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
    262     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);
    263     model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
     265    model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
     266    model->addNormal(normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].y,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].z,normalVectorField[i%this->heightMapReference->heightMap->h][j%this->heightMapReference->heightMap->w].x);
     267    model->addTexCoor((float)j /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
    264268    model->addColor(r/255.0,g/255.0,b/255.0);
    265269
     
    300304
    301305
    302   SDL_UnlockSurface(hm->colourMap);
     306  SDL_UnlockSurface(this->heightMapReference->colourMap);
    303307
    304308  model->finalize();
     
    307311
    308312
    309 #undef heightMap
     313// #undef heightMap
    310314        #undef colours
    311315        #undef scaleX
     
    319323}
    320324
     325
    321326HeightMap::HeightMap()
    322327{
    323328}
     329
    324330
    325331HeightMap::HeightMap(const std::string& height_map_name = "")
  • trunk/src/lib/graphics/importer/height_map.h

    r7468 r7469  
    5252
    5353  private:
    54     void load(int i1, int j1, int i2, int i2, HeightMap* hm, VertexArrayModel* model, int Res);
     54    void load(int i1, int j1, int i2, int i2, VertexArrayModel* model, int Res);
    5555
    5656
     
    6464    VertexArrayModel*                          lowResModel;                       //!< low resolution model of the tile
    6565
    66     HeightMap*                                 heightMapReference;                             //!<
     66    HeightMap*                                 heightMapReference;                //!< reference to the heightmap this tile belongs to
    6767    int                                        highRes;                           //!<
    6868    int                                        lowRes;                            //!<
Note: See TracChangeset for help on using the changeset viewer.