Examples
const center = pxToNdc(400, 300, 800, 600)
// center.x === 0 and center.y === 0Function
pxToNdc(x: number, y: number, width?: number, height?: number): Vector2Converts a pixel-space coordinate to normalized device coordinates (NDC).
Use this helper for coordinates measured from the top-left of a viewport.
The returned NDC coordinate uses the viewport center as (0, 0), X from
-1 on the left to 1 on the right, and Y increasing upward. The
conversion is xNdc = 2 * x / width - 1 and
yNdc = 1 - 2 * y / height.
width and height default to the browser viewport’s innerWidth and
innerHeight. The helper does not mutate its inputs and returns a new
Vector2. Use ndcToPx for the inverse conversion.
const center = pxToNdc(400, 300, 800, 600)
// center.x === 0 and center.y === 0