Skip to content

Documentation / @ripl/3d / rayFromScreen

Function: rayFromScreen() ​

rayFromScreen(x, y, viewProjection, viewport): Ray | null

Defined in: 3d/src/math/projection.ts:86

Builds the world-space ray passing through a screen-space point.

Unprojects the near and far planes and joins them, which works for both perspective and orthographic projections — an orthographic ray is parallel to the view direction rather than fanning from an eye point, and this recovers that without a special case.

Parameters ​

ParameterTypeDescription
xnumberScreen-space x, in logical pixels.
ynumberScreen-space y.
viewProjectionMatrix4The view-projection matrix in use.
viewportViewportThe viewport the point was measured in.

Returns ​

Ray | null

The ray, or null when the view-projection matrix is singular.