summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-29 22:15:27 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-29 22:32:46 +0100
commit9c5027215e1052adb0131362207b78ec89822985 (patch)
treead928799caedab4fa497802e8981db9dc66fcc76 /src
parent2659fae8c838601282b9b90d5e0dc8b1da3f3f2b (diff)
fix z value discontinuity on chunk boundaries
Diffstat (limited to 'src')
-rw-r--r--src/camera-offset.cpp14
-rw-r--r--src/camera-offset.hpp6
2 files changed, 12 insertions, 8 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index 335a9b65..7c5be7f3 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -6,18 +6,22 @@ namespace floormat {
static_assert(sizeof(short) == 2);
-with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, short x, short y) :
+with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords c, chunk_coords first, chunk_coords last) :
_shader{shader},
- _offset{shader.camera_offset()}
+ _camera{shader.camera_offset()},
+ _depth{shader.depth_offset()}
{
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
- const auto offset = _offset + tile_shader::project(Vector3d(x, y, 0) * chunk_size);
- _shader.set_camera_offset(offset);
+ const auto offset = _camera + tile_shader::project(Vector3d(c.x, c.y, 0) * chunk_size);
+ const auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
+ const float depth_offset = _depth + shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
+
+ _shader.set_camera_offset(offset, depth_offset);
}
with_shifted_camera_offset::~with_shifted_camera_offset()
{
- _shader.set_camera_offset(_offset);
+ _shader.set_camera_offset(_camera, _depth);
}
} // namespace floormat
diff --git a/src/camera-offset.hpp b/src/camera-offset.hpp
index 0a44ee30..ef098694 100644
--- a/src/camera-offset.hpp
+++ b/src/camera-offset.hpp
@@ -9,12 +9,12 @@ struct tile_shader;
struct with_shifted_camera_offset final
{
- explicit with_shifted_camera_offset(tile_shader& shader, short x, short y);
- explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords c) : with_shifted_camera_offset(shader, c.x, c.y) {}
+ explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords c, chunk_coords first, chunk_coords last);
~with_shifted_camera_offset();
private:
tile_shader& _shader; // NOLINT
- Vector2d _offset;
+ Vector2d _camera;
+ float _depth;
};
} // namespace floormat