Posted on

Table of Contents

Camera Transformation

To define a camera, consider:

  • Position e\mathbf{e}
  • Gaze direction (look-at) g\mathbf{g}
  • Up direction, perpendicular to the look-at direction t\mathbf{t}

We establish the camera as the origin, with up at Y\mathbf{Y} and look-at towards Z\mathbf{-Z}. This approach enables us to transform everything in relation to the camera's position and orientation. Consequently, we construct a Camera Transform Matrix Mview\mathbf{M}_{view} to translate e\mathbf{e} to the origin, rotate g\mathbf{g} towards Z\mathbf{-Z}, and rotate g×t\mathbf{g} \times \mathbf{t} towards X\mathbf{X}. Mview=RviewTview \mathbf{M}_{view} = \mathbf{R}_{view} \mathbf{T}_{view} Although direct rotation might seem complex, we can apply reverse rotation: Rview1=[xg×txtxg0yg×tytyg0zg×tztzg00001] \mathbf{R}_{view}^{-1}= \begin{bmatrix} x_{g\times t} & x_t & x_{-g} & 0 \cr y_{g\times t} & y_t & y_{-g} & 0 \cr z_{g\times t} & z_t & z_{-g} & 0 \cr 0 & 0& 0& 1 \end{bmatrix} Given that the rotation matrix is orthogonal: Rview=(Rview1)1=(Rview1)T=[xg×tyg×tzg×t0xtytzt0xgygzg00001] \mathbf{R}_{view} = (\mathbf{R}_{view}^{-1})^{-1} = (\mathbf{R}_{view}^{-1})^T = \begin{bmatrix} x_{g\times t} & y_{g\times t}& z_{g\times t} & 0 \cr x_t & y_t & z_t & 0 \cr x_{-g} & y_{-g} & z_{-g} & 0 \cr 0 & 0& 0& 1 \end{bmatrix} Thus, by transforming the object with Mview\mathbf{M}_{view}, the objects' appearance remains consistent from the camera's viewpoint.

Projection Transformation

projection

(a) Orthographic projection. (b) Perspective project. (c) Perspective with hidden lines.

Orthographic projection

In general, for a cuboid, we first translate it to the centre. Then, we use the parameters left, right, bottom, top, far, and near to define its dimensions as [l,r]×[b,t]×[f,n][l,r] \times [b,t] \times [f,n]. This allows us to transform it into a canonical cube of dimensions [1,1]3[-1,1]^3. Mortho=[2rl00002tb00002nf00001][100r+l2010t+b2001n+f20001] \mathbf{M}_{ortho}= \begin{bmatrix} \frac{2}{r-l} & 0 & 0 & 0 \cr 0 & \frac{2}{t-b} & 0 & 0 \cr 0 & 0 & \frac{2}{n-f} & 0 \cr 0 & 0& 0& 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -\frac{r+l}{2} \cr 0 & 1 & 0 & -\frac{t+b}{2} \cr 0 & 0 & 1 & -\frac{n+f}{2} \cr 0 & 0& 0& 1 \end{bmatrix}

Perspective Projection

Recall: [x,y,z,1]T=[kx,ky,kz,k]T=[xz,yz,z2,z]T[x,y,z,1]^T = [kx,ky,kz,k]^T=[xz,yz,z^2,z]^T in homogeneous coordinates.

persp2ortho

For perspective projection, we start by transforming the frustum into a cuboid, which is then followed by an orthographic projection. This involves:

  • Keep near plate the same
  • Keep z value of far plate the same
  • Keep the centre of far plate the same.

Through similarity, the projection on the x and y axes can be represented as: x=nzx x'=\frac{n}{z}x

y=nzy y'=\frac{n}{z}y So we can have part of our Mper\mathbf{M}_{per}: Mperothro=[n0000n00####0010] \mathbf{M}_{per\to othro} = \begin{bmatrix} n & 0 & 0 & 0 \cr 0 & n & 0 & 0 \cr \# & \# & \# & \# \cr 0 & 0 & 1 & 0 \end{bmatrix} Based on our rule, we need near plate and the centre of far plate remain the same. Mperothr[x,y,n,1]T=[x,y,n,1]T==[nx,ny,n2,n]T \mathbf{M}_{per\to othr}[x,y,n,1]^T=[x,y,n,1]^T == [nx,ny,n^2,n]^T

Mperothr[0,0,f,1]T=[0,0,f,1]T==[0,0,f2,f]T \mathbf{M}_{per\to othr}[0,0,f,1]^T=[0,0,f,1]^T == [0,0,f^2,f]^T

Solve, it: Mperothr=[n0000n0000n+ffn0010] \mathbf{M}_{per\to othr} = \begin{bmatrix} n & 0 & 0 & 0 \cr 0 & n & 0 & 0 \cr 0 & 0 & n+f & -fn \cr 0 & 0& 1& 0 \end{bmatrix} Then, we can have: Mper=MothrMperothr \mathbf{M}_{per}=\mathbf{M}_{othr}\mathbf{M}_{per\to othr} The refined explanation for the Perspective to Orthographic projection transformation is as follows: R=MperothrR=[xyz1][n0000n0000n+ffn0010]=[nzxnzyn+fnfz1] \mathbf{R}'=\mathbf{M}_{per\to othr}\mathbf{R}= \begin{bmatrix} x \cr y \cr z \cr 1 \end{bmatrix} \begin{bmatrix} n & 0 & 0 & 0 \cr 0 & n & 0 & 0 \cr 0 & 0 & n+f & -fn \cr 0 & 0& 1& 0 \end{bmatrix}= \begin{bmatrix} \frac{n}{z}x \cr \frac{n}{z}y \cr n+f -\frac{nf}{z} \cr 1 \end{bmatrix} Specifically, when zz equals the near nn or far ff plane distances, the transformed zz' coordinate remains unchanged. However, for values of zz between nn and ff, zz' becomes smaller, approaching ff. This transformation, therefore, compresses the depth dimension, making objects appear further away as they move closer to the far plane.

z-axis