diff options
| author | Ray <[email protected]> | 2024-02-04 11:53:04 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2024-02-04 11:53:04 +0100 |
| commit | d34956b197caa485ba81dcf24cdc9601b87eab43 (patch) | |
| tree | e8b17aecc994a6343a96c5b078009a41526cc437 /src | |
| parent | c31559101a9fa565545a3ab5046e3a0554a891dc (diff) | |
| parent | 250d89b6211d893a4f55732a08b67bad834d5576 (diff) | |
| download | raylib-d34956b197caa485ba81dcf24cdc9601b87eab43.tar.gz raylib-d34956b197caa485ba81dcf24cdc9601b87eab43.zip | |
Merge branch 'master' of https://github.com/raysan5/raylib
Diffstat (limited to 'src')
| -rw-r--r-- | src/raylib.h | 1 | ||||
| -rw-r--r-- | src/rcore.c | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/raylib.h b/src/raylib.h index 4c4b191c..e2404a32 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1050,6 +1050,7 @@ RLAPI void UnloadShader(Shader shader); // Un // Screen-space-related functions RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position +RLAPI Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height); // Get a ray trace from mouse position in a viewport RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix) RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position diff --git a/src/rcore.c b/src/rcore.c index 784b9b62..48c863f5 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1404,14 +1404,20 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture) //---------------------------------------------------------------------------------- // Get a ray trace from mouse position -Ray GetMouseRay(Vector2 mouse, Camera camera) +Ray GetMouseRay(Vector2 mousePosition, Camera camera) +{ + return GetViewRay(mousePosition, camera, GetScreenWidth(), GetScreenHeight()); +} + +// Get a ray trace from the mouse position within a specific section of the screen +Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height) { Ray ray = { 0 }; // Calculate normalized device coordinates // NOTE: y value is negative - float x = (2.0f*mouse.x)/(float)GetScreenWidth() - 1.0f; - float y = 1.0f - (2.0f*mouse.y)/(float)GetScreenHeight(); + float x = (2.0f*mousePosition.x)/width - 1.0f; + float y = 1.0f - (2.0f*mousePosition.y)/height; float z = 1.0f; // Store values in a vector @@ -1425,11 +1431,11 @@ Ray GetMouseRay(Vector2 mouse, Camera camera) if (camera.projection == CAMERA_PERSPECTIVE) { // Calculate projection matrix from perspective - matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); } else if (camera.projection == CAMERA_ORTHOGRAPHIC) { - double aspect = (double)CORE.Window.screen.width/(double)CORE.Window.screen.height; + double aspect = (double)width/(double)height; double top = camera.fovy/2.0; double right = top*aspect; |
