From 4fced50fd17c12d11e8cd0a99a0f3531cc4daf43 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 19 Jul 2022 22:06:18 +0200 Subject: [PATCH] Reviewed example formating --- examples/Makefile | 2 +- examples/core/core_2d_camera_mouse_zoom.c | 165 ++++++++++---------- examples/core/core_2d_camera_mouse_zoom.png | Bin 0 -> 16175 bytes 3 files changed, 85 insertions(+), 82 deletions(-) create mode 100644 examples/core/core_2d_camera_mouse_zoom.png diff --git a/examples/Makefile b/examples/Makefile index 063ad52c1..0261a9aa8 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -375,7 +375,7 @@ CORE = \ core/core_input_gestures \ core/core_2d_camera \ core/core_2d_camera_platformer \ - core/core_2d_camera_mouse_zoom \ + core/core_2d_camera_mouse_zoom \ core/core_3d_camera_mode \ core/core_3d_camera_free \ core/core_3d_camera_first_person \ diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index 112d6152f..7bce1079b 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -2,100 +2,103 @@ * * raylib [core] example - 2d camera mouse zoom * -* This example has been created using raylib 1.5 (www.raylib.com) +* This example was originally created with raylib 4.2, last time updated for raylib 4.2 +* * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2022 Jeffery Myers * ********************************************************************************************/ - #include "raylib.h" -#include "rlgl.h" -#include "raymath.h"; +#include "rlgl.h" +#include "raymath.h" //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ int main () { - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera mouse zoom"); - - Camera2D camera = { 0 }; - camera.zoom = 1; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) - { - // translate based on right click - if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) - { - Vector2 delta = GetMouseDelta(); - delta = Vector2Scale(delta, -1.0f / camera.zoom); - - camera.target = Vector2Add(camera.target, delta); - } - - // zoom based on wheel - float wheel = GetMouseWheelMove(); - if (wheel != 0) - { - // get the world point that is under the mouse - Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); - - // set the offset to where the mouse is - camera.offset = GetMousePosition(); - - // set the target to match, so that the camera maps the world space point under the cursor to the screen space point under the cursor at any zoom - camera.target = mouseWorldPos; - - // zoom - const float zoomIncrement = 0.125f; - - camera.zoom += wheel * zoomIncrement; - if (camera.zoom < zoomIncrement) - camera.zoom = zoomIncrement; - } - - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - BeginDrawing(); - ClearBackground(BLACK); - - BeginMode2D(camera); - - // draw the 3d grid, rotated 90 degrees and centered around 0,0 just so we have something in the XY plane - rlPushMatrix(); - rlTranslatef(0, 25 * 50, 0); - rlRotatef(90, 1, 0, 0); - DrawGrid(100, 50); - rlPopMatrix(); - - // draw a thing - DrawCircle(100, 100, 50, YELLOW); - EndMode2D(); - - DrawText("Right drag to move, mouse wheel to zoom", 2, 2, 20, WHITE); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization + // Initialization //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - return 0; + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera mouse zoom"); + + Camera2D camera = { 0 }; + camera.zoom = 1.0f; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Translate based on mouse right click + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) + { + Vector2 delta = GetMouseDelta(); + delta = Vector2Scale(delta, -1.0f/camera.zoom); + + camera.target = Vector2Add(camera.target, delta); + } + + // Zoom based on mouse wheel + float wheel = GetMouseWheelMove(); + if (wheel != 0) + { + // Get the world point that is under the mouse + Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera); + + // Set the offset to where the mouse is + camera.offset = GetMousePosition(); + + // Set the target to match, so that the camera maps the world space point + // under the cursor to the screen space point under the cursor at any zoom + camera.target = mouseWorldPos; + + // Zoom increment + const float zoomIncrement = 0.125f; + + camera.zoom += (wheel*zoomIncrement); + if (camera.zoom < zoomIncrement) camera.zoom = zoomIncrement; + } + + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + ClearBackground(BLACK); + + BeginMode2D(camera); + + // Draw the 3d grid, rotated 90 degrees and centered around 0,0 + // just so we have something in the XY plane + rlPushMatrix(); + rlTranslatef(0, 25*50, 0); + rlRotatef(90, 1, 0, 0); + DrawGrid(100, 50); + rlPopMatrix(); + + // Draw a reference circle + DrawCircle(100, 100, 50, YELLOW); + + EndMode2D(); + + DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + return 0; } \ No newline at end of file diff --git a/examples/core/core_2d_camera_mouse_zoom.png b/examples/core/core_2d_camera_mouse_zoom.png new file mode 100644 index 0000000000000000000000000000000000000000..b920d5c7bd471f7ec062394d8eefae4f634f1ef1 GIT binary patch literal 16175 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYU_8XZ#=yWJp1k%11B2Z+PZ!6KinwHkrvJ>H z-{0T=U%%k4LCBl+>(|TkYO}E|I+S1%YbY=`%Cc-zpUw)LWb1aBi2f^k>tfeiK(la0M?2QoN% zun}brZkKV%wH^4t-FQ)Q!o?6J$yEn2lzwa(7NJ zVR6GkybxnrEIZ-i5i?v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