summaryrefslogtreecommitdiffhomepage
path: root/main/camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/camera.cpp')
-rw-r--r--main/camera.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/main/camera.cpp b/main/camera.cpp
index 967e1496..2bbadd00 100644
--- a/main/camera.cpp
+++ b/main/camera.cpp
@@ -5,7 +5,7 @@ namespace floormat {
void app::do_camera(float dt)
{
- constexpr float pixels_per_second = 512;
+ constexpr float pixels_per_second = 256;
if (keys[key::camera_up])
camera_offset += Vector2(0, 1) * dt * pixels_per_second;
else if (keys[key::camera_down])
@@ -23,7 +23,7 @@ void app::do_camera(float dt)
void app::reset_camera_offset()
{
- camera_offset = _shader.project({TILE_MAX_DIM*TILE_SIZE[0]/2.f, TILE_MAX_DIM*TILE_SIZE[1]/2.f, 0});
+ camera_offset = project({TILE_MAX_DIM*TILE_SIZE[0]/2.f, TILE_MAX_DIM*TILE_SIZE[1]/2.f, 0});
//camera_offset = {};
}
@@ -32,4 +32,23 @@ void app::update_window_scale(Vector2i sz)
_shader.set_scale(Vector2{sz});
}
+Vector2 app::pixel_to_tile(Vector2 position) const
+{
+ const auto px = position - Vector2{windowSize()}*.5f - camera_offset;
+ return unproject(px) / Vector2{TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f} + Vector2{.5f, .5f};
+}
+
+void app::draw_cursor_tile()
+{
+ if (_cursor_pos)
+ {
+ const auto tile = pixel_to_tile(Vector2(*_cursor_pos));
+ if (std::min(tile[0], tile[1]) >= 0 && std::max(tile[0], tile[1]) < (int)TILE_MAX_DIM)
+ {
+ const auto x = std::uint8_t(tile[0]), y = std::uint8_t(tile[1]);
+ draw_wireframe_quad({x, y});
+ }
+ }
+}
+
} // namespace floormat