Ticket #472: 472.patch
| File 472.patch, 2.7 KB (added by JubJub, 2 years ago) |
|---|
-
source/graphics/Terrain.cpp
340 340 + zf * ((1 - xf) * h01 + xf * h11))); 341 341 } 342 342 343 CFixed_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 343 361 /////////////////////////////////////////////////////////////////////////////// 344 362 // Resize: resize this terrain to the given size (in patches per side) 345 363 void CTerrain::Resize(ssize_t size) -
source/graphics/Terrain.h
23 23 #define INCLUDED_TERRAIN 24 24 25 25 #include "maths/Vector3D.h" 26 #include "maths/Fixed.h" 26 27 #include "graphics/SColor.h" 27 28 #include "lib/sysdep/cpu.h" 28 29 … … 80 81 81 82 float GetVertexGroundLevel(ssize_t i, ssize_t j) const; 82 83 float GetExactGroundLevel(float x, float z) const; 84 CFixed_23_8 GetExactGroundLevelFixed(CFixed_23_8 x, CFixed_23_8 z) const; 83 85 float GetExactGroundLevel(const CVector2D& v) const; 84 86 85 87 float GetSlope(float x, float z) const ; -
source/simulation2/components/CCmpTerrain.cpp
60 60 61 61 virtual entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z) 62 62 { 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); 67 64 } 68 65 69 66 virtual float GetGroundLevel(float x, float z)
