Games101笔记 投影
Orthographic projection
simple way
-
center cuboid by translating
-
a cuboid \([l,r]\times[b,t]\times[f,n]\) to the canonical cube \([-1, 1]^3\)
-
Transformation matrix
Translate (center to origin)first, then scale (\(\frac{lenght/width/height}{2}\))
\[M_{ortho} = \left[ \begin{matrix} \frac{2}{r-l} & 0 & 0 & 0\\ 0 & \frac{2}{t-b} & 0 & 0\\ 0 & 0 & \frac{2}{n-f} & 0\\ 0 & 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} 1 & 0 & 0 & -\frac{r + l}{2}\\ 0 & 1 & 0 & -\frac{t + b}{2}\\ 0 & 0 & 1 & -\frac{n + f}{2}\\ 0 & 0 & 0 & 1 \end{matrix} \right] \]
\(\blacktriangleright\) OpenGL 投影后的坐标系是左手的,即屏幕右 \(X\) 正向, 上 \(Y\) 正向, 但是屏幕朝里面 \(Z\) 正向
Perspective projective
How to do perspective projection
-
squish the frustum into a cuboid \((n \rightarrow n, f\rightarrow f)~ (M_{persp\rightarrow ortho})\)
-
一些规定
- 近平面不变
- 远平面 \(Z\) 值不变
- 远平面的中心点不变
-
relationship between transformed points \((x', y', z')\) and original points \((x, y, z)\)
\(y' = \frac{n}{z}y\) \(x' = \frac{n}{z}x ~ (similar~to~y')\)
-
In homogeneous coordinates
\[\begin{pmatrix} x\\ y\\ z\\ 1 \end{pmatrix} \Rightarrow \begin{pmatrix} nx/z\\ ny/z\\ unknown\\ 1 \end{pmatrix} \times z == \begin{pmatrix} nx\\ ny\\ still~nuknown\\ z \end{pmatrix} \]\(\triangleright\) so squish \((persp \rightarrow ortho)\) does this
\[\begin{pmatrix} nx\\ ny\\ unknown\\ z \end{pmatrix} == M_{persp \rightarrow ortho}^{4\times 4} \begin{pmatrix} x\\ y\\ z\\ 1 \end{pmatrix} \]
-
\(\triangleright\) the third row is responsible to \(z'\)
- 在近平面上的任何点都不会变
\(\triangleright\) 由此可以得到第三行的形式必为 \((0~0~A~B)\)
- 在远平面上的点的 \(z\) 值不变
\(\triangleright\) 综上可以解出 \(A\) 和 \(B\)
- Do orthographic projection \((M_{ortho})\)
\(\blacktriangleright\) 最终于的结果也就是 \(M_{persp} = M_{ortho}M_{persp\rightarrow ortho}\)

浙公网安备 33010602011771号