(main)+zoom in and out by keyboard,+translation by mouse
This commit is contained in:
22
main.c
22
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);
|
||||
|
||||
Reference in New Issue
Block a user