diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/camera-offset.cpp | 17 | ||||
-rw-r--r-- | src/camera-offset.hpp | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index 46582539..27899b03 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -4,6 +4,18 @@ namespace floormat { +Vector2d with_shifted_camera_offset::get_offset(chunk_coords_ c) +{ + return tile_shader::project(Vector3d(Vector2d(c.x, c.y) * TILE_MAX_DIM, c.z) * dTILE_SIZE); +} + +with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c) : + _shader{shader}, _camera{shader.camera_offset()} +{ + auto offset = _camera + get_offset(c); + _shader.set_camera_offset(offset, float{1 << 24}); +} + with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c_, chunk_coords first_, chunk_coords last_) : _shader{shader}, _camera{shader.camera_offset()} @@ -11,8 +23,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun (void)last_; fm_assert(shader.depth_offset() == 0.f); - auto z = int{c_.z}; - auto offset = _camera + tile_shader::project((Vector3d(c_.x, c_.y, 0) * TILE_MAX_DIM20d + Vector3d(0, 0, z)) * dTILE_SIZE); + auto offset = _camera + get_offset(c_); auto pos = chunk_coords(c_) - first_; constexpr auto depth_start = -1 + 1.111e-16f; @@ -22,7 +33,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun printf("c=(%2hd %2hd %2hhd) pos=(%2d %2d) len=(%d %d) --> %d\n", c_.x, c_.y, c_.z, pos.x(), pos.y(), len.x(), len.y(), depth); #endif - auto z_offset = (z-chunk_z_min) * tile_shader::depth_value({}, tile_shader::z_depth_offset); + auto z_offset = (int{c_.z}-int{chunk_z_min}) * tile_shader::depth_value({}, tile_shader::z_depth_offset); auto d = depth * tile_shader::depth_tile_size + depth_start + z_offset; if (c_.z == chunk_z_max) diff --git a/src/camera-offset.hpp b/src/camera-offset.hpp index f3b64177..88a1a08a 100644 --- a/src/camera-offset.hpp +++ b/src/camera-offset.hpp @@ -9,8 +9,11 @@ struct tile_shader; struct with_shifted_camera_offset final { + explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c); explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c, chunk_coords first, chunk_coords last); ~with_shifted_camera_offset(); + + static Vector2d get_offset(chunk_coords_ c); private: tile_shader& _shader; // NOLINT Vector2d _camera; |