Function ortho_RH_01

Build an orthographic projection matrix with right-hand NDC and [0 .. 1] depth clipping

Mat4!T ortho_RH_01(T) (
  in T l,
  in T r,
  in T b,
  in T t,
  in T n,
  in T f
);

Parameters

NameDescription
l X position of the left plane
r X position of the right plane
b Y position of the bottom plane
t Y position of the top plane
n distance from origin to near plane (in Z-)
f distance from origin to far plane (in Z-)

Returns

an affine matrix that maps from eye coordinates to NDC.

Example

import gfx.math.approx : approxUlp;
const m = ortho_RH_01(3f, 5f, -2f, 7f, 1f, 10f);
const vl = vec(3f, -2f, -1f, 1f);
const vh = vec(5f, 7f, -10f, 1f);
const vc = vec(4f, 2.5f, -5.5f, 1f);

assert(approxUlp( m * vl, vec(-1f, 1f, 0f, 1f) ));
assert(approxUlp( m * vh, vec(1f, -1f, 1f, 1f) ));
assert(approxUlp( m * vc, vec(0f, 0f, 0.5f, 1f) ));