Skip to content

Commit

Permalink
Screen space related functions consistency (#3830)
Browse files Browse the repository at this point in the history
* Screen/world-space related functions rename

* Update raylib_api.* by CI

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
aiafrasinei and github-actions[bot] committed Mar 7, 2024
1 parent fccdfa7 commit 3b7be85
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/core/core_3d_picking.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(void)
{
if (!collision.hit)
{
ray = GetMouseRay(GetMousePosition(), camera);
ray = GetScreenToWorldRay(GetMousePosition(), camera);

// Check collision between ray and box
collision = GetRayCollisionBox(ray,
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main(void)
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
// Check collision between ray and box
if (GetRayCollisionBox(GetMouseRay(GetMousePosition(), camera), bounds).hit) selected = !selected;
if (GetRayCollisionBox(GetScreenToWorldRay(GetMousePosition(), camera), bounds).hit) selected = !selected;
else selected = false;
}
//----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_mesh_picking.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(void)
Color cursorColor = WHITE;

// Get ray and test against objects
ray = GetMouseRay(GetMousePosition(), camera);
ray = GetScreenToWorldRay(GetMousePosition(), camera);

// Check ray collision against ground quad
RayCollision groundHitInfo = GetRayCollisionQuad(ray, g0, g1, g2, g3);
Expand Down
2 changes: 1 addition & 1 deletion examples/text/text_draw_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int main(void)
// Handle clicking the cube
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
Ray ray = GetMouseRay(GetMousePosition(), camera);
Ray ray = GetScreenToWorldRay(GetMousePosition(), camera);

// Check collision between ray and box
RayCollision collision = GetRayCollisionBox(ray,
Expand Down
4 changes: 2 additions & 2 deletions parser/output/raylib_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3872,7 +3872,7 @@
]
},
{
"name": "GetMouseRay",
"name": "GetScreenToWorldRay",
"description": "Get a ray trace from mouse position",
"returnType": "Ray",
"params": [
Expand All @@ -3887,7 +3887,7 @@
]
},
{
"name": "GetViewRay",
"name": "GetScreenToWorldRayEx",
"description": "Get a ray trace from mouse position in a viewport",
"returnType": "Ray",
"params": [
Expand Down
4 changes: 2 additions & 2 deletions parser/output/raylib_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ return {
}
},
{
name = "GetMouseRay",
name = "GetScreenToWorldRay",
description = "Get a ray trace from mouse position",
returnType = "Ray",
params = {
Expand All @@ -3644,7 +3644,7 @@ return {
}
},
{
name = "GetViewRay",
name = "GetScreenToWorldRayEx",
description = "Get a ray trace from mouse position in a viewport",
returnType = "Ray",
params = {
Expand Down
8 changes: 4 additions & 4 deletions parser/output/raylib_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1421,14 +1421,14 @@ Function 083: UnloadShader() (1 input parameters)
Return type: void
Description: Unload shader from GPU memory (VRAM)
Param[1]: shader (type: Shader)
Function 084: GetMouseRay() (2 input parameters)
Name: GetMouseRay
Function 084: GetScreenToWorldRay() (2 input parameters)
Name: GetScreenToWorldRay
Return type: Ray
Description: Get a ray trace from mouse position
Param[1]: mousePosition (type: Vector2)
Param[2]: camera (type: Camera)
Function 085: GetViewRay() (4 input parameters)
Name: GetViewRay
Function 085: GetScreenToWorldRayEx() (4 input parameters)
Name: GetScreenToWorldRayEx
Return type: Ray
Description: Get a ray trace from mouse position in a viewport
Param[1]: mousePosition (type: Vector2)
Expand Down
4 changes: 2 additions & 2 deletions parser/output/raylib_api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@
<Function name="UnloadShader" retType="void" paramCount="1" desc="Unload shader from GPU memory (VRAM)">
<Param type="Shader" name="shader" desc="" />
</Function>
<Function name="GetMouseRay" retType="Ray" paramCount="2" desc="Get a ray trace from mouse position">
<Function name="GetScreenToWorldRay" retType="Ray" paramCount="2" desc="Get a ray trace from mouse position">
<Param type="Vector2" name="mousePosition" desc="" />
<Param type="Camera" name="camera" desc="" />
</Function>
<Function name="GetViewRay" retType="Ray" paramCount="4" desc="Get a ray trace from mouse position in a viewport">
<Function name="GetScreenToWorldRayEx" retType="Ray" paramCount="4" desc="Get a ray trace from mouse position in a viewport">
<Param type="Vector2" name="mousePosition" desc="" />
<Param type="Camera" name="camera" desc="" />
<Param type="float" name="width" desc="" />
Expand Down
4 changes: 2 additions & 2 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,8 @@ RLAPI void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)

// 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 Ray GetScreenToWorldRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position
RLAPI Ray GetScreenToWorldRayEx(Vector2 mousePosition, Camera camera, float width, float height); // Get a ray trace from mouse position 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
6 changes: 3 additions & 3 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,13 +1407,13 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
//----------------------------------------------------------------------------------

// Get a ray trace from mouse position
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
Ray GetScreenToWorldRay(Vector2 mousePosition, Camera camera)
{
return GetViewRay(mousePosition, camera, (float)GetScreenWidth(), (float)GetScreenHeight());
return GetScreenToWorldRayEx(mousePosition, camera, (float)GetScreenWidth(), (float)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 GetScreenToWorldRayEx(Vector2 mousePosition, Camera camera, float width, float height)
{
Ray ray = { 0 };

Expand Down

0 comments on commit 3b7be85

Please sign in to comment.