Skip to content

Commit

Permalink
REVIEWED: GetScreenToWorldRayEx()
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Apr 3, 2024
1 parent 9070eb9 commit d30cfea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ RLAPI void UnloadShader(Shader shader); // Un
// Screen-space-related functions
#define GetMouseRay GetScreenToWorldRay // Compatibility hack for previous raylib versions
RLAPI Ray GetScreenToWorldRay(Vector2 position, Camera camera); // Get a ray trace from screen position (i.e mouse)
RLAPI Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, float width, float height); // Get a ray trace from screen position (i.e mouse) in a viewport
RLAPI Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height); // Get a ray trace from screen position (i.e mouse) in a viewport
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
Expand Down
8 changes: 4 additions & 4 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,18 +1419,18 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
// Get a ray trace from screen position (i.e mouse)
Ray GetScreenToWorldRay(Vector2 position, Camera camera)
{
return GetScreenToWorldRayEx(position, camera, (float)GetScreenWidth(), (float)GetScreenHeight());
return GetScreenToWorldRayEx(position, camera, GetScreenWidth(), GetScreenHeight());
}

// Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, float width, float height)
Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height)
{
Ray ray = { 0 };

// Calculate normalized device coordinates
// NOTE: y value is negative
float x = (2.0f*position.x)/width - 1.0f;
float y = 1.0f - (2.0f*position.y)/height;
float x = (2.0f*position.x)/(float)width - 1.0f;
float y = 1.0f - (2.0f*position.y)/(float)height;
float z = 1.0f;

// Store values in a vector
Expand Down

0 comments on commit d30cfea

Please sign in to comment.