summaryrefslogtreecommitdiffhomepage
path: root/editor/camera.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-23 23:46:56 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-23 23:46:56 +0200
commit17283c55122234e7cc2dc352262b273d05aecff8 (patch)
treecbc8658fc02438779a9256b31c29a66aa5a80371 /editor/camera.cpp
parent0efe01d0e7286e9eb60c4739ae748c0cb6e7a51f (diff)
a
Diffstat (limited to 'editor/camera.cpp')
-rw-r--r--editor/camera.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/editor/camera.cpp b/editor/camera.cpp
index 52496762..0ae5a26d 100644
--- a/editor/camera.cpp
+++ b/editor/camera.cpp
@@ -1,5 +1,7 @@
#include "app.hpp"
#include "src/global-coords.hpp"
+#include "shaders/tile-shader.hpp"
+#include "main/floormat-main.hpp"
#include <Magnum/GL/DefaultFramebuffer.h>
namespace floormat {
@@ -38,32 +40,22 @@ void app::do_camera(flota dt)
return;
}
recalc_cursor_tile();
- if (_cursor_tile)
+ if (cursor.tile)
do_mouse_move(*_cursor_tile);
}
void app::reset_camera_offset()
{
- _shader.set_camera_offset(tile_shader::project({TILE_MAX_DIM*-.5*dTILE_SIZE[0], TILE_MAX_DIM*-.5*dTILE_SIZE[1], 0}));
+ M->shader().set_camera_offset(tile_shader::project({TILE_MAX_DIM*-.5*dTILE_SIZE[0], TILE_MAX_DIM*-.5*dTILE_SIZE[1], 0}));
recalc_cursor_tile();
}
void app::recalc_cursor_tile()
{
- if (_cursor_pixel && !_cursor_in_imgui)
- _cursor_tile = pixel_to_tile(Vector2d(*_cursor_pixel));
+ if (cursor.pixel && !cursor.in_imgui)
+ cursor.tile = M->pixel_to_tile(Vector2d(*cursor.pixel));
else
- _cursor_tile = std::nullopt;
-}
-
-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) / pixel_size + half;
- const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]);
- return { x, y };
+ cursor.tile = std::nullopt;
}
} // namespace floormat