From 8b84c999d284c69aba55825db909f90ed3768916 Mon Sep 17 00:00:00 2001 From: Fabrizio Pietrucci Date: Wed, 19 Mar 2025 19:48:04 +0100 Subject: [PATCH 1/5] Use logarithmic zoom scaling in 2d camera zoom examples --- examples/core/core_2d_camera.c | 4 +++- examples/core/core_2d_camera_mouse_zoom.c | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/core/core_2d_camera.c b/examples/core/core_2d_camera.c index 0a551f68b..11c15d448 100644 --- a/examples/core/core_2d_camera.c +++ b/examples/core/core_2d_camera.c @@ -14,6 +14,7 @@ ********************************************************************************************/ #include "raylib.h" +#include #define MAX_BUILDINGS 100 @@ -81,7 +82,8 @@ int main(void) else if (camera.rotation < -40) camera.rotation = -40; // Camera zoom controls - camera.zoom += ((float)GetMouseWheelMove()*0.05f); + // Uses log scaling to provide consistent zoom speed + camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.05f)); if (camera.zoom > 3.0f) camera.zoom = 3.0f; else if (camera.zoom < 0.1f) camera.zoom = 0.1f; diff --git a/examples/core/core_2d_camera_mouse_zoom.c b/examples/core/core_2d_camera_mouse_zoom.c index cfdaf15aa..31aa7bc6b 100644 --- a/examples/core/core_2d_camera_mouse_zoom.c +++ b/examples/core/core_2d_camera_mouse_zoom.c @@ -73,9 +73,9 @@ int main () camera.target = mouseWorldPos; // Zoom increment - float scaleFactor = 1.0f + (0.25f*fabsf(wheel)); - if (wheel < 0) scaleFactor = 1.0f/scaleFactor; - camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + // Uses log scaling to provide consistent zoom speed + float scale = 0.2f*wheel; + camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f); } } else @@ -96,10 +96,10 @@ int main () if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { // Zoom increment + // Uses log scaling to provide consistent zoom speed float deltaX = GetMouseDelta().x; - float scaleFactor = 1.0f + (0.01f*fabsf(deltaX)); - if (deltaX < 0) scaleFactor = 1.0f/scaleFactor; - camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); + float scale = 0.005f*deltaX; + camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f); } } //---------------------------------------------------------------------------------- @@ -143,4 +143,4 @@ int main () CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +} From e140aca1b5ce2595336aad4a2300033bd9a9a452 Mon Sep 17 00:00:00 2001 From: Fabrizio Pietrucci Date: Wed, 19 Mar 2025 20:19:19 +0100 Subject: [PATCH 2/5] Increase zoom factor in `core_2d_camera.c` This compensate for slower zoom speed due to log scaling --- examples/core/core_2d_camera.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/core/core_2d_camera.c b/examples/core/core_2d_camera.c index 11c15d448..07766e0fb 100644 --- a/examples/core/core_2d_camera.c +++ b/examples/core/core_2d_camera.c @@ -83,7 +83,7 @@ int main(void) // Camera zoom controls // Uses log scaling to provide consistent zoom speed - camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.05f)); + camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.1f)); if (camera.zoom > 3.0f) camera.zoom = 3.0f; else if (camera.zoom < 0.1f) camera.zoom = 0.1f; From 266fba11112580e9528c2be8ecceb2caae3b54f7 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 21 Mar 2025 17:07:55 +0100 Subject: [PATCH 3/5] Minor tweaks --- src/platforms/rcore_desktop_glfw.c | 12 ++++++++---- src/rcore.c | 2 +- src/rshapes.c | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 829ba582b..19ee78bf4 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1741,7 +1741,7 @@ static void ErrorCallback(int error, const char *description) } // GLFW3 WindowSize Callback, runs when window is resizedLastFrame -// NOTE: Window resizing not allowed by default +// NOTE: Window resizing not enabled by default, use SetConfigFlags() static void WindowSizeCallback(GLFWwindow *window, int width, int height) { // Reset viewport and projection matrix for new size @@ -1756,15 +1756,19 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height) // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale if (IsWindowState(FLAG_WINDOW_HIGHDPI)) { - width = (int)(width / GetWindowScaleDPI().x); - height = (int)(height / GetWindowScaleDPI().y); + width = (int)(width/GetWindowScaleDPI().x); + height = (int)(height/GetWindowScaleDPI().y); } + + // Set render size + CORE.Window.render.width = width; + CORE.Window.render.height = height; // Set current screen size CORE.Window.screen.width = width; CORE.Window.screen.height = height; - // NOTE: Postprocessing texture is not scaled to new size + // WARNING: If using a render texture, it is not scaled to new size } static void WindowPosCallback(GLFWwindow* window, int x, int y) { diff --git a/src/rcore.c b/src/rcore.c index 6c5bc2518..864c54b0f 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1119,7 +1119,7 @@ void BeginTextureMode(RenderTexture2D target) //rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?) // Setup current width/height for proper aspect ratio - // calculation when using BeginMode3D() + // calculation when using BeginTextureMode() CORE.Window.currentFbo.width = target.texture.width; CORE.Window.currentFbo.height = target.texture.height; CORE.Window.usingFbo = true; diff --git a/src/rshapes.c b/src/rshapes.c index fa15939f2..c739f4162 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -2239,7 +2239,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 // NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount) { - bool inside = false; + bool collision = false; if (pointCount > 2) { @@ -2248,12 +2248,12 @@ bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCoun if ((points[i].y > point.y) != (points[j].y > point.y) && (point.x < (points[j].x - points[i].x)*(point.y - points[i].y)/(points[j].y - points[i].y) + points[i].x)) { - inside = !inside; + collision = !collision; } } } - return inside; + return collision; } // Check collision between two rectangles From 46cd07d2c74742fc7fbd9b0f2fb25cd78cd81b4c Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 21 Mar 2025 17:17:45 +0100 Subject: [PATCH 4/5] WARNING: REVERTED CHANGE THAT BROKE BATCHING!!! #4849 I'm sorry... I did not detect this change was breaking batching... :( --- src/rlgl.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index f8e7651d1..d55ae82f2 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1459,9 +1459,6 @@ void rlBegin(int mode) // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode) { - // Get current binded texture to preserve it between draw modes change (QUADS <--> TRIANGLES) - int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId; - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, @@ -1484,16 +1481,13 @@ void rlBegin(int mode) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode; RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = currentTexture; // Preserve active texture + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId; } } // Finish vertex providing void rlEnd(void) { - // Reset texture to default - rlSetTexture(RLGL.State.defaultTextureId); - // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values, // as well as depth buffer bit-depth (16bit or 24bit or 32bit) // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) From 8e9c3ceb579079b8b0b2291adcf29b7d661c3b99 Mon Sep 17 00:00:00 2001 From: sleeptightAnsiC <91839286+sleeptightAnsiC@users.noreply.github.com> Date: Sat, 22 Mar 2025 21:20:17 +0100 Subject: [PATCH 5/5] [rcore] fix: TRACELOG upon successfully changing directory InitWindow() prints CWD during initialization, but ChangeDirectory() does not, which is quite confusing when you start messing with CWD. Now said function should log similar message. --- src/rcore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rcore.c b/src/rcore.c index 864c54b0f..4ccae395f 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -2354,6 +2354,7 @@ bool ChangeDirectory(const char *dir) bool result = CHDIR(dir); if (result != 0) TRACELOG(LOG_WARNING, "SYSTEM: Failed to change to directory: %s", dir); + else TRACELOG(LOG_INFO, "SYSTEM: Working Directory: %s", dir); return (result == 0); }