raylib icon indicating copy to clipboard operation
raylib copied to clipboard

[rcore] Screen/world-space related functions consistency

Open raysan5 opened this issue 2 years ago • 2 comments

Screen-to-world and world-to-screen related functions look a bit inconsistent in naming at this moment, they should be reviewed.

Recently, GetViewRay() (temporal name) was added (https://github.com/raysan5/raylib/pull/3709) to allow screen-to-world ray retrieval, mostly intended for mouse position to ray for a custom viewport.

Checking all related functions, they look a bit unconsistent in naming, also some functions could be missing:

// 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 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
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
RLAPI Matrix GetCameraMatrix(Camera camera);                      // Get camera transform matrix (view matrix)
RLAPI Matrix GetCameraMatrix2D(Camera2D camera);                  // Get camera 2d transform matrix

That naming should be probably reviewed for consistency (potential breaking change). Other frameworks/engines could be checked for reference (Unity API is usually very good at naming).

raysan5 avatar Feb 04 '24 11:02 raysan5

Some possible renames for consistency:

  • GetMouseRay() --> GetScreenToWorldRay()
  • GetViewRay()--> GetScreenToWorldRayEx()

Name seems more technically correct but maybe more confusing to users?

raysan5 avatar Feb 04 '24 11:02 raysan5

I believe the possible renames are good.

luis605 avatar Feb 13 '24 20:02 luis605

Unity has this methods: ScreenToWorldPoint, WorldToScreenPoint

https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html https://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html

WorldToScreenPoint corresponds to raylib GetWorldToScreen Do we want a GetScreenToWorld similar to unity ScreenToWorldPoint ?

aiafrasinei avatar Feb 20 '24 09:02 aiafrasinei

It's confusing to have an official example using a function that has not yet been released (Picking in 3d mode example).

Especially when the 'last time updated with raylib 4.0' that did not have the changed name.

I couldn't compile with w64devkit because it's using 5.0.

Dorifor avatar Jun 05 '24 21:06 Dorifor