The viewport matrix maps the canonical view volume (normalized
device coordinates) to Julia (y=i, x=j, 1-indexed) pixel coordinates for
a given canvas \(\mathbf{h}\) and \(\mathbf{w}\).
- Input: Normalized device coordinates \((x_v, y_v, z_v) \in [-1,1]^3\)
- Parameters: canvas height and width (\(\mathbf{h}\) and \(\mathbf{w}\))
- Output:
- \(x_p \in
[0.5,\mathbf{w}+0.5]\)
- \(y_p \in [0.5,\mathbf{h}+0.5]\)
(Flipped)
- \(z_p \in [-1, 1]\)
We derived the scalar formulas for the coordinates to be: \[
\begin{align*}
x_p &= \frac{(x_v + 1)}{2}w + \frac{1}{2}\\
y_p &= \frac{(-y_v + 1)}{2}h + \frac{1}{2}\\
z_p &= z_v
\end{align*}
\]
Write the 4x4 viewport matrix that accomplishes this
transformation.
An orthographic projection matrix can be specified by giving two
opposite corners of the view volume.
- Input: Camera coordinates (\(x_c, y_c, z_c)\)
- Parameters: View volume dimensions: left and right
\(x\) extent (\(\ell, r\)), bottom and top \(y\) extent (\(b,
t\)), and near and far clipping planes (\(n, f\)).
- Output: normalized device coordinates \((x_v, y_v, z_v) \in [-1,1]^3\).
We can accomplish this with a sequence of simpler steps:
- Translate the bottom, left, near corner to the origin
- Scale the width, height, and depth of the volume each to 2
- Translate the center of the now-2x2x2 cube to the origin.
Write the 4x4 projection matrix that accomplishes this
transformation.
The camera matrix transforms world coordinates into a camera’s
local coordinate frame.
- Input: world coordinates \((x_w, y_w, z_w)\)
- Parameters: The orthonormal frame \(\vec{u}, \vec{v}, \vec{w}, \vec{e}\), in
which the camera’s position is canonical (we might have derived this
from eye, view, and
up inputs)
- Output: Camera coordinates \((x_c, y_c, z_c)\)
Write the matrix that accomplishes this transformation.