Skip to content

Conversation

capdevon
Copy link
Contributor

@capdevon capdevon commented Jun 6, 2025

This PR introduces a new public method, screenPointToRay(Vector2f click2d), to the Camera class. This method provides a highly efficient way to generate a picking Ray in world coordinates from a given 2D screen coordinate.

Motivation:

The ability to accurately and efficiently convert a 2D screen point (e.g., from a mouse click) into a 3D ray in world space is fundamental for various interactive features, such as:

  • Object Picking: Determining which 3D object a user has clicked on.
  • Raycasting: Performing intersections with geometry for game logic (e.g., shooting, selection).
  • Gizmo Manipulation: Interacting with 3D manipulation tools.

See https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Camera.ScreenPointToRay.html

usage example:

Ray pickingRay = cam.screenPointToRay(inputManager.getCursorPosition());

// Now 'pickingRay' can be used for intersection tests with 3D objects
// e.g., pickingRay.intersects(someSpatial.getWorldBound());

Edit:
add TestMousePick
image

@capdevon capdevon changed the title Camera: Add Optimized screenPointToRay(Vector2f) for Efficient Raycasting Camera: Add optimized screenPointToRay(Vector2f) for efficient raycasting Jun 6, 2025
@yaRnMcDonuts yaRnMcDonuts added this to the v3.9.0 milestone Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants