Ticket #1986: terrain.diff

File terrain.diff, 651 bytes (added by sanderd17, 11 years ago)
  • source/graphics/Terrain.cpp

     
    133133    ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1);
    134134    u16 height = m_Heightmap[hj*m_MapSize + hi];
    135135    pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE;
    136     pos.Y = fixed::FromInt(height) / (int)HEIGHT_UNITS_PER_METRE;
     136    // divide height by 2 to avoid overflows when height is between 2^15 and 2^16.
     137    pos.Y = fixed::FromInt(height >> 1) / ((int)HEIGHT_UNITS_PER_METRE >> 1);
    137138    pos.Z = fixed::FromInt(j) * (int)TERRAIN_TILE_SIZE;
    138139}
    139140