From 985a883fdaf01771fff30f23ba8c19f1f1a997df Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 25 Aug 2023 18:54:44 +0100 Subject: (main)~fixed bug with zooming out too far Stopped presenting the simulation after a while. --- main.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index e798cdd..9edb8bf 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,7 @@ int main(void) camera.zoom = 1.0f; InitWindow(state.window_len, state.window_len, "Abelian sand pile"); SetTargetFPS(60); + const float zoom = 0.125f; while (!WindowShouldClose()) { @@ -61,17 +62,23 @@ int main(void) if (IsKeyPressed(KEY_UP) || IsKeyDown(KEY_UP)) { - Vector2 world_pos = GetScreenToWorld2D(GetMousePosition(), camera); - camera.offset = GetMousePosition(); + Vector2 centre = {state.window_len / 2, state.window_len / 2}; + Vector2 world_pos = GetScreenToWorld2D(centre, camera); + camera.offset = centre; camera.target = world_pos; - camera.zoom += 0.125f; + camera.zoom += zoom; + if (camera.zoom < zoom) + camera.zoom = zoom; } if (IsKeyPressed(KEY_DOWN) || IsKeyDown(KEY_DOWN)) { - Vector2 world_pos = GetScreenToWorld2D(GetMousePosition(), camera); - camera.offset = GetMousePosition(); + Vector2 centre = {state.window_len / 2, state.window_len / 2}; + Vector2 world_pos = GetScreenToWorld2D(centre, camera); + camera.offset = centre; camera.target = world_pos; - camera.zoom -= 0.125f; + camera.zoom -= zoom; + if (camera.zoom < zoom) + camera.zoom = zoom; } if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) -- cgit v1.2.3-13-gbd6f