diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 22:39:07 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 22:39:07 +0200 |
commit | 8929cfd3e06bb25d2c9b47cafb7481a741028c27 (patch) | |
tree | d04691bd8522d8ace1456131d05d0d62dd7d364f | |
parent | b2cc7ef52a230e909d25b54dd3f355823cb60a56 (diff) |
adjust camera speed with window size
-rw-r--r-- | main/camera.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/main/camera.cpp b/main/camera.cpp index 248b1c5d..fd31066e 100644 --- a/main/camera.cpp +++ b/main/camera.cpp @@ -5,19 +5,24 @@ namespace floormat { void app::do_camera(double dt) { - constexpr int pixels_per_second = 768; + constexpr double screens_per_second = 1; + const auto pixels_per_second = windowSize().length() / screens_per_second; auto camera_offset = _shader.camera_offset(); + Vector2d dir{}; if (keys[key::camera_up]) - camera_offset += Vector2d{0, 1} * dt * pixels_per_second; + dir += Vector2d{0, 1}; else if (keys[key::camera_down]) - camera_offset += Vector2d{0, -1} * dt * pixels_per_second; + dir += Vector2d{0, -1}; if (keys[key::camera_left]) - camera_offset += Vector2d{1, 0} * dt * pixels_per_second; + dir += Vector2d{1, 0}; else if (keys[key::camera_right]) - camera_offset += Vector2d{-1, 0} * dt * pixels_per_second; + dir += Vector2d{-1, 0}; + if (dir != Vector2d{}) { + camera_offset += dir.normalized() * dt * pixels_per_second; + const auto max_camera_offset = Vector2d(windowSize() * 10); camera_offset[0] = std::clamp(camera_offset[0], -max_camera_offset[0], max_camera_offset[0]); camera_offset[1] = std::clamp(camera_offset[1], -max_camera_offset[1], max_camera_offset[1]); |