The 2D layer · function

worldToNdc

The affine for a 2D world seen through a camera.

Explained in Sprites and tilemaps.

function worldToNdc(camera: Camera2D, viewportWidth: number, viewportHeight: number, out: Affine2D): Affine2D
import { worldToNdc } from '@driftengine/ui2d';

Parameters

ParameterTypeDescription
cameraCamera2D
viewportWidthnumber
viewportHeightnumber
outAffine2D

In depth

y counts upward, which is the opposite of screenToNdc below and is deliberate: a 2D world is a world, and a caller placing a platform above a floor should not have to subtract. A screen-space overlay is the other convention because that is the one every layout system already uses, and the two are different enough that sharing one would make each caller wrong half the time.

Rotation turns the camera, so the world turns the other way: at rotation = +π/2 the camera has tilted its head anticlockwise and what was to its right is now above it.