Update core_2d_camera_mouse_zoom.c

This commit is contained in:
Ray 2024-11-06 12:00:39 +01:00
parent b47fffb48b
commit a617e1e217

View file

@ -45,7 +45,7 @@ int main ()
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1; else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;
// Translate based on mouse right click // Translate based on mouse right click
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{ {
Vector2 delta = GetMouseDelta(); Vector2 delta = GetMouseDelta();
delta = Vector2Scale(delta, -1.0f/camera.zoom); delta = Vector2Scale(delta, -1.0f/camera.zoom);
@ -76,8 +76,8 @@ int main ()
} }
else else
{ {
// Zoom based on mouse left click // Zoom based on mouse right click
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
{ {
// Get the world point that is under the mouse // Get the world point that is under the mouse
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
@ -89,7 +89,7 @@ int main ()
// under the cursor to the screen space point under the cursor at any zoom // under the cursor to the screen space point under the cursor at any zoom
camera.target = mouseWorldPos; camera.target = mouseWorldPos;
} }
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{ {
// Zoom increment // Zoom increment
float deltaX = GetMouseDelta().x; float deltaX = GetMouseDelta().x;
@ -120,9 +120,15 @@ int main ()
EndMode2D(); EndMode2D();
// Draw mouse reference
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);
DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY); DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
if (zoomMode == 0) DrawText("Mouse right button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY); if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
else DrawText("Mouse right button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY); else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------