Changeset 72

Show
Ignore:
Timestamp:
1.11.2009 12:35:25 (3 weeks ago)
Author:
blackhex
Message:
Location:
SoTerrain
Files:
1 removed
5 modified

Legend:

Unmodified
Added
Removed
  • SoTerrain/include/data/SbTexture2Tile.h

    r63 r72  
    6565    /* Attributes. */ 
    6666 
    67     /// 
     67    /// Offset in X direction in the underlaying texture that coresponds to X 
     68    /// coordinate of the tile. 
    6869    int32_t offsetX; 
    6970 
    70     /// 
     71    /// Offset in Y direction in the underlaying texture that coresponds to Y 
     72    /// coordinate of the tile. 
    7173    int32_t offsetY; 
    7274 
    73     /// 
     75    /// Width of a line in the underlaying texture. 
    7476    int32_t lineWidth; 
    7577 
    76     /// 
     78    /// Data of the underlaying texture. 
    7779    const unsigned char * data; 
    7880}; 
  • SoTerrain/include/data/SbTile.h

    r63 r72  
    7777 
    7878    /* Attributes. */ 
    79     /// 
     79    /// X coordinate of a left-down corner of the tile in heightmap coordinates. 
    8080    int32_t x; 
    8181 
    82     /// 
     82    /// Y coordinate of a left-down corner of the tile in heightmap coordinates. 
    8383    int32_t y; 
    8484 
    85     /// 
     85    /// Width of the tile in heightmap coordinates. 
    8686    int32_t width; 
    8787 
    88     /// 
     88    /// Height of the tile in heightmap coordinates. 
    8989    int32_t height; 
    9090 
    91     /// 
     91    /// Additional attributes that can be attached to tile. 
    9292    SbTileAttributes * attibutes; 
    9393 
  • SoTerrain/src/data/SbTexture2Tile.cpp

    r63 r72  
    2323/////////////////////////////////////////////////////////////////////////////// 
    2424 
     25// Standard includes. 
     26#include <assert.h> 
     27 
    2528// OpenGL includes. 
    2629#if defined(__WIN32__) || defined(_WIN32) 
     
    4043  const int32_t width, const int32_t height, const int32_t _lineWidth, const 
    4144  unsigned char * _data): 
    42   SbTile(x + (width >> 1), y + (height >> 2), width, height), 
    43   offsetX(x), offsetY(y), lineWidth(_lineWidth), data(_data) 
     45  SbTile(_offsetX, _offsetY, width, height), 
     46  offsetX(_offsetX), offsetY(_offsetY), lineWidth(_lineWidth), data(_data) 
    4447{ 
    4548  // Nothing. 
     
    5356unsigned char SbTexture2Tile::get(const int32_t x, const int32_t y) const 
    5457{ 
     58  assert(this->data); 
    5559  return this->data[((y + this->offsetY) * this->lineWidth) + 
    5660    (x + this->offsetX)]; 
     
    5963void SbTexture2Tile::GLRender() 
    6064{ 
     65  assert(this->data); 
     66 
    6167  // Render tile with quad strips. 
    62   for (int Y = this->y; Y < (this->y + this->height - 1); ++Y) 
     68  for (int Y = 0; Y < this->height; ++Y) 
    6369  { 
    6470    glBegin(GL_QUAD_STRIP); 
    65  
    66     // First two vertices of a quad strip. 
    67     glVertex3f(this->x, Y + 1, data[(Y + 1 + this->offsetY) * this->lineWidth 
    68       + this->x + this->offsetX] * 0.1f); 
    69     glVertex3f(this->x, Y, data[(Y + this->offsetY) * this->lineWidth + 
    70       + this->x + this->offsetX] * 0.1f); 
    71  
    72     // Other pairs of vertices in line. 
    73     for (int X = (this->x + 1); X < (this->x + this->width); ++X) 
     71    for (int X = 0; X <= this->width; ++X) 
    7472    { 
    75       glVertex3f(X, Y + 1, data[(Y + 1 + this->offsetY) * this->lineWidth + X 
    76         + this->offsetX] * 0.1f); 
    77       glVertex3f(X, Y, data[(Y + this->offsetY) * this->lineWidth + X 
    78         + this->offsetX] * 0.1f); 
     73      glVertex3f(this->x + X, this->y + Y + 1, data[(this->offsetY + Y + 1) * 
     74        this->lineWidth + this->offsetX + X] * 0.1f); 
     75      glVertex3f(this->x + X, this->y + Y, data[(this->offsetY + Y) * 
     76        this->lineWidth + this->offsetX + X] * 0.1f); 
    7977    } 
    8078    glEnd(); 
     
    8482SbBox3f SbTexture2Tile::computeBBox() 
    8583{ 
    86   SbBox3f bounds; 
     84  assert(this->data); 
    8785 
    8886  // Compute bounds by iterating over all pixels of tile. 
     87  SbBox3f bounds; 
    8988  for (int Y = this->y; Y <= (this->y + this->height); ++Y) 
    9089  { 
  • SoTerrain/src/data/SoTexture2TileCache.cpp

    r63 r72  
    5454  queued) 
    5555{ 
    56   DEBUG_MSG(x << " " << y << " " << width << " " << height << " " << resolution); 
    57  
    5856  if (queued) 
    5957  { 
  • SoTerrain/src/test/SoDummyTileCacheUser.cpp

    r59 r72  
    8585  int32_t x_step = width >> 1; 
    8686  int32_t y_step = height >> 1; 
    87   DEBUG_MSG("frame"); 
    8887  for (int32_t J = 0; J < 2; ++J) 
    8988  { 
     
    9796        y_step, x_step); 
    9897 
    99       // Render tile. 
     98      // Render the tile. 
    10099      if (tile) 
    101100      { 
    102         for (int32_t tile_y = 0; tile_y < y_step; ++tile_y) 
    103         { 
    104           glBegin(GL_QUAD_STRIP); 
    105           for (int32_t tile_x = 0; tile_x <= x_step; ++tile_x) 
    106           { 
    107             unsigned char height = tile->get(tile_x, tile_y); 
    108             //glColor3ub(height, 0, 0); 
    109             glVertex3f(tile_offset_x + tile_x, tile_offset_y + tile_y, height * 
    110               0.1); 
    111             height = tile->get(tile_x, tile_y + 1); 
    112             //glColor3ub(height, 0, 0); 
    113             glVertex3f(tile_offset_x + tile_x, tile_offset_y + tile_y + 1, 
    114               height * 0.1); 
    115           } 
    116           glEnd(); 
    117         } 
     101        tile->GLRender(); 
    118102      } 
    119103    }