diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-08-25 18:54:44 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-08-25 18:54:44 +0100 |
commit | 985a883fdaf01771fff30f23ba8c19f1f1a997df (patch) | |
tree | 5604d93e9d76087e9e460b6bc2666868807bfd0c | |
parent | 9524e7ade9a40b471f4c2a903d6894f09fc0affd (diff) | |
download | abelian-sandpile-985a883fdaf01771fff30f23ba8c19f1f1a997df.tar.gz abelian-sandpile-985a883fdaf01771fff30f23ba8c19f1f1a997df.tar.bz2 abelian-sandpile-985a883fdaf01771fff30f23ba8c19f1f1a997df.zip |
(main)~fixed bug with zooming out too far
Stopped presenting the simulation after a while.
-rw-r--r-- | main.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -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)) |