Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7499 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
May 3, 2006, 10:45:46 AM (19 years ago)
Author:
patrick
Message:

orxonox: further work in variable renaming and code reformatting

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

Legend:

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

    r7498 r7499  
    3535/**
    3636 * default constructor
    37  *  @param i1
    38  */
    39 Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* heightMapReference )
    40 {
    41   PRINTF(4)("Tile Constructor\n");
     37 *  @param xOffset
     38 */
     39Tile::Tile(int xOffset, int yOffset, int i2, int j2, HeightMap* heightMapReference )
     40{
     41  PRINTF(0)("Tile Constructor\n");
    4242
    4343  this->highResModel = new VertexArrayModel();
     
    4747
    4848  // create high res model
    49   this->load(i1, j1, i2, j2, this->highResModel, 4);
     49  this->load(xOffset, yOffset, i2, j2, this->highResModel, 4);
    5050  // create low res model
    51   this->load(i1, j1, i2, j2, this->lowResModel, 8);
     51  this->load(xOffset, yOffset, i2, j2, this->lowResModel, 8);
    5252}
    5353
     
    8484 * loads a tile
    8585 */
    86 void Tile::load(int i1, int j1, int i2, int j2, VertexArrayModel* model, int sampleRate)
     86void Tile::load(int xOffset, int yOffset, int i2, int j2, VertexArrayModel* model, int sampleRate)
    8787{
    8888
     
    9999
    100100  //FIXME: OLD implementation
    101   this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((i1 + i2) / 2)) * scaleX;
    102   this->z = this->heightMapReference->offsetZ + ((j1 + j2 ) / 2 ) * scaleZ;
     101  this->x = this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX;
     102  this->z = this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ;
    103103  //NEW:
    104   this->setAbsCoor(this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((i1 + i2) / 2)) * scaleX,
     104  this->setAbsCoor(this->heightMapReference->offsetX + ( this->heightMapReference->heightMap->h - ((xOffset + i2) / 2)) * scaleX,
    105105                   0,
    106                    this->heightMapReference->offsetZ + ((j1 + j2 ) / 2 ) * scaleZ);
     106                   this->heightMapReference->offsetZ + ((yOffset + j2 ) / 2 ) * scaleZ);
    107107
    108108
     
    120120  SDL_LockSurface(this->heightMapReference->colorMap);
    121121
    122   for( int i = i1 ; i <= i2  ; i +=sampleRate)
     122  for( int i = xOffset ; i <= i2  ; i +=sampleRate)
    123123  {
    124124    int w = 0;
     
    132132    }
    133133
    134     w = j1;
     134    w = yOffset;
     135
     136    PRINTF(0)("Values: i = %i, w = %i\n", i, w);
    135137
    136138    // add a vertex to the list
    137     model->addVertex(scaleX*(this->heightMapReference->heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
     139    model->addVertex(scaleX * (this->heightMapReference->heightMap->h - i) + shiftX, shiftY, scaleZ * w + shiftZ); // Top Right
    138140    model->addNormal(normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].y,
    139141                     normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].z,
    140142                     normalVectorField[i % this->heightMapReference->heightMap->h][w % this->heightMapReference->heightMap->w].x);
    141     model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
     143    model->addTexCoor((float)(yOffset-sampleRate) /(texRate), (float)(i %this->heightMapReference->heightMap->h)/(texRate));
    142144    model->addColor(r/255.0f, g/255.0f, b/255.0f);
    143145
    144146
    145     for(int j = j1; j <= j2; j += sampleRate)
     147    for(int j = yOffset; j <= j2; j += sampleRate)
    146148    {
    147149      // adjust the colors acording to the color map
     
    185187  int cnt = 0;
    186188
    187   for( int i = i1; i < i2; i +=sampleRate)
    188   {
    189     for( int j = j1-sampleRate; j < j2  + 2 * sampleRate; j += sampleRate)
     189  for( int i = xOffset; i < i2; i +=sampleRate)
     190  {
     191    for( int j = yOffset-sampleRate; j < j2  + 2 * sampleRate; j += sampleRate)
    190192    {
    191193      model->addIndice(cnt);
    192       model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
     194      model->addIndice(cnt  + (j2 -yOffset + 3* sampleRate  )/ sampleRate );
    193195      cnt++;
    194196    }
    195197    model->newStripe();
    196198  }
    197   cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
    198 
    199   for( int j = j1; j <= j2; j += sampleRate)
    200   {
    201     int i = i1;
     199  cnt += (j2 -yOffset + 3* sampleRate)/ sampleRate;
     200
     201  for( int j = yOffset; j <= j2; j += sampleRate)
     202  {
     203    int i = xOffset;
    202204
    203205    // To be fixed
     
    220222
    221223
    222   for(int j = j1  ; j <= j2    ;  j += sampleRate)
    223   {
    224     int i = i1;
     224  for(int j = yOffset  ; j <= j2    ;  j += sampleRate)
     225  {
     226    int i = xOffset;
    225227    height =  (float)(unsigned char)this->heightMapReference->heights[j + sampleRate + i * this->heightMapReference->heightMap->w];
    226228    height += (float)(unsigned char)this->heightMapReference->heights[j + 1 + sampleRate + (i + 1) *
     
    244246
    245247
    246   for(int j = j1; j <= j2; j += sampleRate)
     248  for(int j = yOffset; j <= j2; j += sampleRate)
    247249  {
    248250    int i = i2;
     
    266268
    267269
    268   for(int j = j1; j <= j2; j += sampleRate)
     270  for(int j = yOffset; j <= j2; j += sampleRate)
    269271  {
    270272    int i = i2;
     
    289291
    290292  // link Boarder Stripe
    291   for(int j = j1 - sampleRate; j < j2; j += sampleRate)
     293  for(int j = yOffset - sampleRate; j < j2; j += sampleRate)
    292294  {
    293295    model->addIndice(cnt);
    294     model->addIndice(cnt + (j2 - j1 + sampleRate) / sampleRate );
     296    model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate );
    295297    cnt++;
    296298  }
     
    301303
    302304
    303   cnt += (j2-j1)/ sampleRate;
     305  cnt += (j2-yOffset)/ sampleRate;
    304306  // link 2nd BoarderStripe
    305   for(int j = j1-sampleRate; j < j2;  j += sampleRate)
     307  for(int j = yOffset-sampleRate; j < j2;  j += sampleRate)
    306308  {
    307309    model->addIndice(cnt);
    308     model->addIndice(cnt + (j2 - j1 + sampleRate) / sampleRate);
     310    model->addIndice(cnt + (j2 - yOffset + sampleRate) / sampleRate);
    309311    cnt++;
    310312  }
     
    441443void HeightMap::load()
    442444{
    443   //Create a Dynamicly sized 2D-Array for Tiles
    444   tiles =  new Tile** [heightMap->h/tileSize];
    445   for(int i=0;i <    heightMap->h/tileSize ; i++)
    446     tiles [i]= new (Tile* [heightMap->w /tileSize ]);
    447 
    448   //SetUp Arrays
    449   for(int i = 0; i < (heightMap->h  )/ tileSize; i ++)
    450   {
    451     for(int j = 0; j < (heightMap->w )/ tileSize; j ++)
    452     {
    453 
    454       tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
     445  // create a dynamicly sized 2D-array for tiles
     446  this->tiles =  new Tile**[this->heightMap->h / this->tileSize];
     447
     448  for( int i = 0;i < heightMap->h / tileSize; i++)
     449    this->tiles [i]= new Tile*[this->heightMap->w / this->tileSize];
     450
     451  // setup arrays
     452  for( int i = 0; i < this->heightMap->h / this->tileSize; i++)  {
     453    for( int j = 0; j < this->heightMap->w / this->tileSize; j++) {
     454      this->tiles[i][j] = new Tile( i * tileSize ,  j * tileSize , (i+1) * tileSize, (j+1) * tileSize , this);
    455455    }
    456456  }
  • trunk/src/lib/graphics/importer/height_map.h

    r7498 r7499  
    109109
    110110  private:
    111     SDL_Surface*                          heightMap;
    112     SDL_Surface*                          colorMap;
     111    SDL_Surface*                          heightMap;                          //!< image of the height map
     112    SDL_Surface*                          colorMap;                           //!< image of the color map
    113113    unsigned char*                        heights;
    114114    unsigned char*                        colors;
Note: See TracChangeset for help on using the changeset viewer.