diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 05:39:20 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-18 05:39:20 +0200 |
commit | f3da1b9c19ab0337ee7852951bb5502baeb21d3b (patch) | |
tree | a2d50f7e33c909272579e9665015fc6f613cfa0a /main | |
parent | 360472cea877b179ef529200a9789327b11cce59 (diff) |
fix unproject()
Diffstat (limited to 'main')
-rw-r--r-- | main/camera.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/main/camera.cpp b/main/camera.cpp index c3a3b2f7..5b8c4b52 100644 --- a/main/camera.cpp +++ b/main/camera.cpp @@ -56,8 +56,10 @@ void app::recalc_cursor_tile() global_coords app::pixel_to_tile(Vector2d position) const { + constexpr Vector2d pixel_size{dTILE_SIZE[0], dTILE_SIZE[1]}; + constexpr Vector2d half{.5, .5}; const Vector2d px = position - Vector2d{windowSize()}*.5 - _shader.camera_offset()*.5; - const Vector2d vec = tile_shader::unproject(px) / Vector2d{dTILE_SIZE[0]*.5, dTILE_SIZE[1]*.5} + Vector2d{.5, .5}; + const Vector2d vec = tile_shader::unproject(px) / pixel_size + half; const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]); return { x, y }; } |