screenToRay

fun View.screenToRay(xPx: Float, yPx: Float): Ray

Calculates a ray in world space going from the near-plane of the camera and through a point in view space.

Screen space is in Android device screen coordinates: TopLeft = (0, 0), BottomRight = (Screen Width, Screen Height). The device coordinate space is unaffected by the orientation of the device.

Return

A Ray from the camera near to far / infinity

Parameters

xPx

Horizontal screen coordinate in pixels where you want the world position. (0 = left, View Width = right) The x value is negative when the point is left of the View.getViewport, between 0 and the width of the View.getViewport width when the point is within the viewport, and greater than the width when the point is to the right of the viewport.

yPx

Vertical screen coordinate in pixels where you want the world position. (0 = top, View Height = bottom) The y value is negative when the point is above the View.getViewport, between 0 and the height of the View.getViewport height when the point is within the viewport, and greater than the height when the point is below the viewport.