summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-08-25 18:52:11 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-08-25 18:52:11 +0100
commit9524e7ade9a40b471f4c2a903d6894f09fc0affd (patch)
tree3355d5b31591543b1aa7f54ab294097457333832
parent32934c0c1a0cae9eff31091b462341e9c10b5da3 (diff)
downloadabelian-sandpile-9524e7ade9a40b471f4c2a903d6894f09fc0affd.tar.gz
abelian-sandpile-9524e7ade9a40b471f4c2a903d6894f09fc0affd.tar.bz2
abelian-sandpile-9524e7ade9a40b471f4c2a903d6894f09fc0affd.zip
(main)+zoom in and out by keyboard,+translation by mouse
-rw-r--r--main.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/main.c b/main.c
index e9f7c8d..e798cdd 100644
--- a/main.c
+++ b/main.c
@@ -58,6 +58,28 @@ int main(void)
while (!WindowShouldClose())
{
step(&state);
+
+ if (IsKeyPressed(KEY_UP) || IsKeyDown(KEY_UP))
+ {
+ Vector2 world_pos = GetScreenToWorld2D(GetMousePosition(), camera);
+ camera.offset = GetMousePosition();
+ camera.target = world_pos;
+ camera.zoom += 0.125f;
+ }
+ if (IsKeyPressed(KEY_DOWN) || IsKeyDown(KEY_DOWN))
+ {
+ Vector2 world_pos = GetScreenToWorld2D(GetMousePosition(), camera);
+ camera.offset = GetMousePosition();
+ camera.target = world_pos;
+ camera.zoom -= 0.125f;
+ }
+
+ if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
+ {
+ Vector2 delta = Vector2Scale(GetMouseDelta(), -1.0f / camera.zoom);
+ camera.target = Vector2Add(camera.target, delta);
+ }
+
BeginDrawing();
ClearBackground(BLACK);
BeginMode2D(camera);