Module gfx.math.proj

NDC agnostic projection matrices. Each projection can be parameterized with a NDC configuration. NDC defines how the clip space will translate to screen coordinates. Note that after transformation by a projection matrix, X, Y and Z vertex coordinates must be divided by W to obtain coordinates in final NDC space. NDC has two components (XYClip and ZClip) that will affect how the coordinates are transformed in the final normalized clipping space. XYClip affects only X and Y (X always to the right, Y either upwards or downwards for leftHanded and rightHanded respectively), and ZClip affects Z depth range.

Functions

NameDescription
frustum(ndc, l, r, b, t, n, f) Build an frustum perspective projection matrix with NDC and DepthClip selected at runtime
frustum_LH_01(l, r, b, t, n, f) Build a perspective projection matrix with left-hand NDC and [0 .. 1] depth clipping
frustum_LH_M11(l, r, b, t, n, f) Build a perspective projection matrix with left-hand NDC and [-1 .. 1] depth clipping
frustum_RH_01(l, r, b, t, n, f) Build a perspective projection matrix with right-hand NDC and [0 .. 1] depth clipping
frustum_RH_M11(l, r, b, t, n, f) Build a perspective projection matrix with right-hand NDC and [0 .. 1] depth clipping
ndc(xy, z) Build NDC from XYClip and ZClip
ortho(ndc, l, r, b, t, n, f) Build an orthographic projection matrix with NDC determined at runtime
ortho_LH_01(l, r, b, t, n, f) Build an orthographic projection matrix with left-hand NDC and [0 .. 1] depth clipping
ortho_LH_M11(l, r, b, t, n, f) Build an orthographic projection matrix with left-hand NDC and [-1 .. 1] depth clipping
ortho_RH_01(l, r, b, t, n, f) Build an orthographic projection matrix with right-hand NDC and [0 .. 1] depth clipping
ortho_RH_M11(l, r, b, t, n, f) Build an orthographic projection matrix with right-hand NDC and [-1 .. 1] depth clipping
perspective(ndc, fovx, aspect, near, far) Build a perspective projection matrix with NDC selected at run-time.
perspective_LH_01(fovx, aspect, near, far) Build a perspective projection matrix with left-hand NDC and [0 .. 1] depth clipping
perspective_LH_M11(fovx, aspect, near, far) Build a perspective projection matrix with left-hand NDC and [-1 .. 1] depth clipping
perspective_RH_01(fovx, aspect, near, far) Build a perspective projection matrix with right-hand NDC and [0 .. 1] depth clipping
perspective_RH_M11(fovx, aspect, near, far) Build a perspective projection matrix with right-hand NDC and [-1 .. 1] depth clipping
xyClip(ndc) Get XYClip from NDC
zClip(ndc) Get ZClip from NDC

Enums

NameDescription
NDC NDC aggregates both XYClip and ZClip
XYClip Determines whether the default projection matrices will project to a clip space where Y points upwards (left hand NDC) or downwards (right hand NDC). Default is right hand NDC, but can be changed by setting version(GfxMathLeftHandNDC) X-Y clip space spans from [-1 .. 1] in both cases.
ZClip Determines whether the default projection matrices will project to a clip space whose depth range is [0 .. 1] or [-1 .. 1]. Default is [0 .. 1] but can be changed by setting version(GfxMathDepthMinusOneToOne) Z points into the screen in both cases.

Aliases

NameTypeDescription
defFrustum frustumCT!defNdc Build an frustum perspective projection matrix with default NDC and DepthClip
defOrtho orthoCT!defNdc Build an orthographic projection matrix with default NDC
defPerspective perspectiveCT!defNdc Build a perspective projection matrix with default NDC and DepthClip
frustumCT frustum_RH_01 Build an frustum perspective projection matrix with NDC set at compile-time.
orthoCT ortho_RH_01 Build an orthographic projection matrix with NDC set at compile-time.
perspectiveCT perspective_RH_01 Build an perspective projection matrix with NDC set at compile-time.