Ticket #472: 472.patch

File 472.patch, 2.7 KB (added by JubJub, 2 years ago)
  • source/graphics/Terrain.cpp

     
    340340           + zf  * ((1 - xf) * h01 + xf * h11))); 
    341341} 
    342342 
     343CFixed_23_8 CTerrain::GetExactGroundLevelFixed(CFixed_23_8 x, CFixed_23_8 z) const 
     344{ 
     345    // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) 
     346    const ssize_t xi = clamp((ssize_t)(x/CELL_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); 
     347    const ssize_t zi = clamp((ssize_t)(z/CELL_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); 
     348 
     349    const CFixed_23_8 xf = clamp((x/CELL_SIZE)-CFixed_23_8::FromInt(xi), CFixed_23_8::FromInt(0), CFixed_23_8::FromInt(1)); 
     350    const CFixed_23_8 zf = clamp((z/CELL_SIZE)-CFixed_23_8::FromInt(zi), CFixed_23_8::FromInt(0), CFixed_23_8::FromInt(1)); 
     351 
     352    u16 h00 = m_Heightmap[zi*m_MapSize + xi]; 
     353    u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; 
     354    u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; 
     355    u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; 
     356    // Linearly interpolate 
     357    return (((CFixed_23_8::FromInt(1) - zf).Multiply((CFixed_23_8::FromInt(1) - xf) * h00 + xf * h10) 
     358               + zf.Multiply((CFixed_23_8::FromInt(1) - xf) * h01 + xf * h11))/HEIGHT_UNITS_PER_METRE); 
     359} 
     360 
    343361/////////////////////////////////////////////////////////////////////////////// 
    344362// Resize: resize this terrain to the given size (in patches per side) 
    345363void CTerrain::Resize(ssize_t size) 
  • source/graphics/Terrain.h

     
    2323#define INCLUDED_TERRAIN 
    2424 
    2525#include "maths/Vector3D.h" 
     26#include "maths/Fixed.h" 
    2627#include "graphics/SColor.h" 
    2728#include "lib/sysdep/cpu.h" 
    2829 
     
    8081 
    8182    float GetVertexGroundLevel(ssize_t i, ssize_t j) const; 
    8283    float GetExactGroundLevel(float x, float z) const; 
     84    CFixed_23_8 GetExactGroundLevelFixed(CFixed_23_8 x, CFixed_23_8 z) const; 
    8385    float GetExactGroundLevel(const CVector2D& v) const; 
    8486 
    8587    float GetSlope(float x, float z) const ; 
  • source/simulation2/components/CCmpTerrain.cpp

     
    6060 
    6161    virtual entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z) 
    6262    { 
    63         float height = m_Terrain->GetExactGroundLevel(x.ToFloat(), z.ToFloat()); 
    64         // TODO: get rid of floats 
    65  
    66         return entity_pos_t::FromFloat(height); 
     63        return m_Terrain->GetExactGroundLevelFixed(x, z); 
    6764    } 
    6865 
    6966    virtual float GetGroundLevel(float x, float z)