diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-12 18:58:52 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-12 19:08:03 +0200 |
commit | 38efeacfd21be1c44d51b18fe9a11b0624a77cda (patch) | |
tree | ad6b8632d302836e968db0115a3357694c948d5c /src/camera-offset.cpp | |
parent | ee38547c4f22ed48572a605ca71f26bd374a90ba (diff) |
aaaa
Diffstat (limited to 'src/camera-offset.cpp')
-rw-r--r-- | src/camera-offset.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index de6f584d..ab547387 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -12,29 +12,26 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE; auto offset = _camera + tile_shader::project(Vector3d(c_.x, c_.y, 0) * chunk_size); - auto pos = Vector2d(chunk_coords(c_) - first_); - auto len = Vector2d(last_ - first_) + Vector2d(1, 1); - auto pos1 = pos.y() * len.x() + pos.x(); - auto z = c_.z - chunk_z_min; - constexpr auto depth_start = -1 + 1.111e-16; - - double chunk_offset, tile_offset; - - if (c_.z < chunk_z_max) - { - chunk_offset = depth_start + tile_shader::depth_chunk_size * pos1; - tile_offset = (double)tile_shader::depth_value({z, z}); - } - else - { - chunk_offset = 1; - tile_offset = 0; - } - - double depth_offset_ = chunk_offset + tile_offset; - auto depth_offset = (float)depth_offset_; - - _shader.set_camera_offset(offset, depth_offset); + auto z = (int)(c_.z - chunk_z_min); + auto pos = chunk_coords(c_) - first_; + auto len = (last_ - first_) + Vector2i(1, 1); + constexpr auto depth_start = -1 + 1.111e-16f; + + int depth = TILE_MAX_DIM * pos.x() + + (int)TILE_COUNT * len.x() * pos.y() + + z * (TILE_MAX_DIM+1); + +#if 1 + if (c_.z == 0) + 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 + + float d = depth * tile_shader::depth_tile_size + depth_start; + + if (c_.z == chunk_z_max) + d = 1; + + _shader.set_camera_offset(offset, d); } with_shifted_camera_offset::~with_shifted_camera_offset() |