Merge branch 'raysan5:master' into master

This commit is contained in:
Jon Daniel 2025-03-24 18:40:46 +01:00 committed by GitHub
commit e46afa295e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 23 deletions

View file

@ -14,6 +14,7 @@
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#include <math.h>
#define MAX_BUILDINGS 100 #define MAX_BUILDINGS 100
@ -81,7 +82,8 @@ int main(void)
else if (camera.rotation < -40) camera.rotation = -40; else if (camera.rotation < -40) camera.rotation = -40;
// Camera zoom controls // 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.1f));
if (camera.zoom > 3.0f) camera.zoom = 3.0f; if (camera.zoom > 3.0f) camera.zoom = 3.0f;
else if (camera.zoom < 0.1f) camera.zoom = 0.1f; else if (camera.zoom < 0.1f) camera.zoom = 0.1f;

View file

@ -73,9 +73,9 @@ int main ()
camera.target = mouseWorldPos; camera.target = mouseWorldPos;
// Zoom increment // Zoom increment
float scaleFactor = 1.0f + (0.25f*fabsf(wheel)); // Uses log scaling to provide consistent zoom speed
if (wheel < 0) scaleFactor = 1.0f/scaleFactor; float scale = 0.2f*wheel;
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f); camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f);
} }
} }
else else
@ -96,10 +96,10 @@ int main ()
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{ {
// Zoom increment // Zoom increment
// Uses log scaling to provide consistent zoom speed
float deltaX = GetMouseDelta().x; float deltaX = GetMouseDelta().x;
float scaleFactor = 1.0f + (0.01f*fabsf(deltaX)); float scale = 0.005f*deltaX;
if (deltaX < 0) scaleFactor = 1.0f/scaleFactor; camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f);
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
} }
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View file

@ -1741,7 +1741,7 @@ static void ErrorCallback(int error, const char *description)
} }
// GLFW3 WindowSize Callback, runs when window is resizedLastFrame // 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) static void WindowSizeCallback(GLFWwindow *window, int width, int height)
{ {
// Reset viewport and projection matrix for new size // Reset viewport and projection matrix for new size
@ -1760,11 +1760,15 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height)
height = (int)(height/GetWindowScaleDPI().y); height = (int)(height/GetWindowScaleDPI().y);
} }
// Set render size
CORE.Window.render.width = width;
CORE.Window.render.height = height;
// Set current screen size // Set current screen size
CORE.Window.screen.width = width; CORE.Window.screen.width = width;
CORE.Window.screen.height = height; 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) static void WindowPosCallback(GLFWwindow* window, int x, int y)
{ {

View file

@ -1119,7 +1119,7 @@ void BeginTextureMode(RenderTexture2D target)
//rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?) //rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?)
// Setup current width/height for proper aspect ratio // 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.width = target.texture.width;
CORE.Window.currentFbo.height = target.texture.height; CORE.Window.currentFbo.height = target.texture.height;
CORE.Window.usingFbo = true; CORE.Window.usingFbo = true;
@ -2354,6 +2354,7 @@ bool ChangeDirectory(const char *dir)
bool result = CHDIR(dir); bool result = CHDIR(dir);
if (result != 0) TRACELOG(LOG_WARNING, "SYSTEM: Failed to change to directory: %s", 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); return (result == 0);
} }

View file

@ -1459,9 +1459,6 @@ void rlBegin(int mode)
// NOTE: In all three cases, vertex are accumulated over default internal vertex buffer // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode) 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) if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
{ {
// Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, // 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].mode = mode;
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; 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 // Finish vertex providing
void rlEnd(void) void rlEnd(void)
{ {
// Reset texture to default
rlSetTexture(RLGL.State.defaultTextureId);
// NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values, // 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) // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)

View file

@ -2239,7 +2239,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php // NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount) bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount)
{ {
bool inside = false; bool collision = false;
if (pointCount > 2) 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) && 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)) (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 // Check collision between two rectangles