diff options
author | x2048 <codeforsmile@gmail.com> | 2023-03-11 14:10:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 14:10:26 +0100 |
commit | 705195b43e620d305bf83b3796699faadb2314ef (patch) | |
tree | 4df8a624217f329cb77a5a42e79d63b820e99e43 /src/util/numeric.h | |
parent | 1de8a1e962098b94154111c7aafe18c4aab74fc9 (diff) | |
download | minetest-705195b43e620d305bf83b3796699faadb2314ef.tar.xz |
Scale culler steps proportionally to the mesh sizes (#13250)
Diffstat (limited to 'src/util/numeric.h')
-rw-r--r-- | src/util/numeric.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h index f0d4fe482..1aeed9ce2 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -151,10 +151,22 @@ struct MeshGrid { u32 getCellVolume() const { return cell_size * cell_size * cell_size; } + /// @brief returns coordinate of mesh cell given coordinate of a map block + s16 getCellPos(s16 p) const + { + return (p - (p < 0) * (cell_size - 1)) / cell_size; + } + + /// @brief returns position of mesh cell in the grid given position of a map block + v3s16 getCellPos(v3s16 block_pos) const + { + return v3s16(getCellPos(block_pos.X), getCellPos(block_pos.Y), getCellPos(block_pos.Z)); + } + /// @brief returns closest step of the grid smaller than p s16 getMeshPos(s16 p) const { - return ((p - (p < 0) * (cell_size - 1)) / cell_size * cell_size); + return getCellPos(p) * cell_size; } /// @brief Returns coordinates of the origin of the grid cell containing p |