4 篇文章 0 订阅

# 局部空间->世界空间

M m o d e l = [ 1 0 0 T x 0 1 0 T y 0 0 1 T z 0 0 0 1 ] [ cos ⁡ θ − sin ⁡ θ 0 0 sin ⁡ θ cos ⁡ θ 0 0 0 0 1 0 0 0 0 1 ] [ S x 0 0 0 0 S y 0 0 0 0 S z 0 0 0 0 1 ] M_{model}= \begin{bmatrix} 1 & 0 & 0 & T_{x} \\ 0 & 1 & 0 & T_{y} \\ 0 & 0 & 1 & T_{z} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} \cos{\theta} & -\sin{\theta} & 0 & 0 \\ \sin{\theta} & \cos{\theta} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} S_{x} & 0 & 0 & 0 \\ 0 & S_{y} & 0 & 0 \\ 0 & 0 & S_{z} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

# 世界空间->相机空间

• 坐标为 e ⃗ \vec{e}

• 观察方向 g ⃗ \vec{g}

• 向上方向 t ⃗ \vec{t}

• 将相机移动到坐标原点
• 旋转观察方向 g ⃗ \vec{g} 到-Z轴
• 旋转向上方向 t ⃗ \vec{t} 到Y轴
• 旋转( g ⃗ × t ⃗ \vec{g} \times \vec{t} )到X轴

T v i e w = [ 1 0 0 − x e 0 1 0 − y e 0 0 1 − z e 0 0 0 1 ] T_{view} = \begin{bmatrix} 1 & 0 & 0 & -x_{e} \\ 0 & 1 & 0 & -y_{e} \\ 0 & 0 & 1 & -z_{e} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

R θ = ( cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ) R_{\theta} = \begin{pmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \\ \end{pmatrix}

R − θ = ( cos ⁡ θ sin ⁡ θ − sin ⁡ θ cos ⁡ θ ) = R θ T R_{-\theta} = \begin{pmatrix} \cos{\theta} & \sin{\theta} \\ -\sin{\theta} & \cos{\theta} \\ \end{pmatrix} = R_{\theta}^\mathrm{T}

R θ T = R θ − 1 R_{\theta}^\mathrm{T} = R_{\theta}^{-1}

R v i e w − 1 = [ x g ⃗ × t ⃗ x t ⃗ x − g ⃗ 0 y g ⃗ × t ⃗ y t ⃗ y − g ⃗ 0 z g ⃗ × t ⃗ z t ⃗ z − g ⃗ 0 0 0 0 1 ] R_{view}^{-1} = \begin{bmatrix} x_{\vec{g} \times \vec{t}} & x_{\vec{t}} & x_{-\vec{g}} & 0 \\ y_{\vec{g} \times \vec{t}} & y_{\vec{t}} & y_{-\vec{g}} & 0 \\ z_{\vec{g} \times \vec{t}} & z_{\vec{t}} & z_{-\vec{g}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

R v i e w = ( R v i e w − 1 ) T = [ x g ⃗ × t ⃗ y g ⃗ × t ⃗ z g ⃗ × t ⃗ 0 x t ⃗ y t ⃗ z t ⃗ 0 x − g ⃗ y − g ⃗ z − g ⃗ 0 0 0 0 1 ] R_{view} = (R_{view}^{-1})^\mathrm{T} = \begin{bmatrix} x_{\vec{g} \times \vec{t}} & y_{\vec{g} \times \vec{t}} & z_{\vec{g} \times \vec{t}} & 0 \\ x_{\vec{t}} & y_{\vec{t}} & z_{\vec{t}} & 0 \\ x_{-\vec{g}} & y_{-\vec{g}} & z_{-\vec{g}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

M v i e w = R v i e w T v i e w = [ x g ⃗ × t ⃗ y g ⃗ × t ⃗ z g ⃗ × t ⃗ 0 x t ⃗ y t ⃗ z t ⃗ 0 x − g ⃗ y − g ⃗ z − g ⃗ 0 0 0 0 1 ] [ 1 0 0 − x e 0 1 0 − y e 0 0 1 − z e 0 0 0 1 ] M_{view} = R_{view}T_{view} = \begin{bmatrix} x_{\vec{g} \times \vec{t}} & y_{\vec{g} \times \vec{t}} & z_{\vec{g} \times \vec{t}} & 0 \\ x_{\vec{t}} & y_{\vec{t}} & z_{\vec{t}} & 0 \\ x_{-\vec{g}} & y_{-\vec{g}} & z_{-\vec{g}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -x_{e} \\ 0 & 1 & 0 & -y_{e} \\ 0 & 0 & 1 & -z_{e} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

# 相机空间->裁剪空间

## 正交投影

M o r t h o = [ 2 r − l 0 0 0 0 2 t − b 0 0 0 0 2 f − n 0 0 0 0 1 ] [ 1 0 0 − r + l 2 0 1 0 − t + b 2 0 0 1 − n + f 2 0 0 0 1 ] = [ 2 r − l 0 0 − r + l r − l 0 2 t − b 0 − t + b t − b 0 0 2 f − n − f + n f − n 0 0 0 1 ] M_{ortho} = \begin{bmatrix} \frac{2}{r-l} & 0 & 0 & 0 \\ 0 & \frac{2}{t-b} & 0 & 0 \\ 0 & 0 & \frac{2}{f-n} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} 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{bmatrix}= \begin{bmatrix} \frac{2}{r-l} & 0 & 0 & -\frac{r+l}{r-l} \\ 0 & \frac{2}{t-b} & 0 & -\frac{t+b}{t-b} \\ 0 & 0 & \frac{2}{f-n} & -\frac{f+n}{f-n} \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}

## 透视投影

• 首先，“压扁”视锥体成一个长方体（n->n,f->f）（ M p e r s p − > o r t h o M_{persp->ortho} ）；
• 然后，做正交投影操作（ M o r t h o M_{ortho} ，即上面的正交投影）。

y ′ = n z y y^{'} = \frac{n}{z}y

x ′ = n z x x^{'} = \frac{n}{z}x

M p e r s p − > o r t h o ( 4 × 4 ) ( x y z 1 ) = ( n z x n z y u n k n o w n 1 ) M_{persp->ortho}^{(4 \times 4)} \begin{pmatrix} x\\ y\\ z\\ 1\\ \end{pmatrix}= \begin{pmatrix} \frac{n}{z}x \\ \frac{n}{z}y \\ unknown \\ 1 \\ \end{pmatrix}

M p e r s p − > o r t h o ( 4 × 4 ) ( x y z 1 ) = ( n z x n z y u n k n o w n 1 ) = ( n x n y u n k n o w n z ) M_{persp->ortho}^{(4 \times 4)} \begin{pmatrix} x\\ y\\ z\\ 1\\ \end{pmatrix}= \begin{pmatrix} \frac{n}{z}x \\ \frac{n}{z}y \\ unknown \\ 1 \\ \end{pmatrix} = \begin{pmatrix} nx \\ ny \\ unknown \\ z \\ \end{pmatrix}

M p e r s p − > o r t h o = ( n 0 0 0 0 n 0 0 ? ? ? ? 0 0 1 0 ) M_{persp->ortho} = \begin{pmatrix} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ ? & ? & ? & ? \\ 0 & 0 & 1 & 0 \\ \end{pmatrix}

1. 近平面上的点的坐标都不会改变；

2. 远平面上的点，Z坐标不改变。

M p e r s p − > o r t h o ( x y n 1 ) = ( x y n 1 ) = ( n x n y n 2 n ) M_{persp->ortho} \begin{pmatrix} x \\ y \\ n \\ 1 \\ \end{pmatrix} = \begin{pmatrix} x \\ y \\ n \\ 1 \\ \end{pmatrix} = \begin{pmatrix} nx \\ ny \\ n^{2} \\ n \\ \end{pmatrix}

M p e r s p − > o r t h o ( x y z 1 ) = ( n x n y u n k n o w n z ) M_{persp->ortho} \begin{pmatrix} x\\ y\\ z\\ 1\\ \end{pmatrix}= \begin{pmatrix} nx \\ ny \\ unknown \\ z \\ \end{pmatrix}

( 0 , 0 , A , B ) ( x y n 1 ) = n 2 \left(0,0,A,B \right) \begin{pmatrix} x \\ y \\ n \\ 1 \\ \end{pmatrix} = n^{2}

A n + B = n 2 An+B = n^{2}

M p e r s p − > o r t h o ( 0 0 f 1 ) = ( 0 0 f 1 ) = ( 0 0 f 2 f ) M_{persp->ortho} \begin{pmatrix} 0 \\ 0 \\ f \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ f \\ 1 \\ \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ f^{2} \\ f \\ \end{pmatrix}

( 0 , 0 , A , B ) ( 0 0 f 1 ) = f 2 \left(0,0,A,B \right) \begin{pmatrix} 0 \\ 0 \\ f \\ 1 \\ \end{pmatrix} = f^{2}

A f + B = f 2 Af + B = f^{2}

{ A n + B = n 2 A f + B = f 2 ⇒ A = n + f B = − n f \begin{cases} An + B = n^{2} \\ Af + B = f^{2} \\ \end{cases} \Rightarrow \begin{matrix} A = n + f \\ B = -nf \\ \end{matrix}

M p e r s p − > o r t h o = [ n 0 0 0 0 n 0 0 0 0 n + f − n f 0 0 1 0 ] M_{persp->ortho} = \begin{bmatrix} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ 0 & 0 & n+f & -nf \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}

M p e r s p = M o r t h o M p e r s p − > o r t h o = [ 2 n r − l 0 l + r l − r 0 0 2 n t − b b + t b − t 0 0 0 f + n f − n 2 n f n − f 0 0 1 0 ] M_{persp} = M_{ortho}M_{persp->ortho} = \begin{bmatrix} \frac{2n}{r-l} & 0 & \frac{l+r}{l-r} & 0 \\ 0 & \frac{2n}{t-b} & \frac{b+t}{b-t} & 0 \\ 0 & 0 & \frac{f+n}{f-n} & \frac{2nf}{n-f} \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}

# 裁剪空间->窗口空间

1. 将NDC的中心平移到窗口的中心；
T v i e w p o r t = ( 1 0 0 w 2 0 1 0 h 2 0 0 1 0 0 0 0 1 ) T_{viewport} = \begin{pmatrix} 1 & 0 & 0 & \frac{w}{2} \\ 0 & 1 & 0 & \frac{h}{2} \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

2. 将NDC的大小缩放到屏幕的大小。

R v i e w p o r t = ( w 2 0 0 0 0 h 2 0 0 0 0 1 0 0 0 0 1 ) R_{viewport} = \begin{pmatrix} \frac{w}{2} & 0 & 0 & 0 \\ 0 & \frac{h}{2} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

M v i e w p o r t = R v i e w p o r t T v i e w p o r t = ( w 2 0 0 w 2 0 h 2 0 h 2 0 0 1 0 0 0 0 1 ) M_{viewport} = R_{viewport}T_{viewport} = \begin{pmatrix} \frac{w}{2} & 0 & 0 & \frac{w}{2} \\ 0 & \frac{h}{2} & 0 & \frac{h}{2} \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

{ A ( − 1 ) + B = 0 A ( 1 ) + B = 1 ⇒ { A = 1 2 B = 1 2 \begin{cases} A(-1) + B = 0 \\ A(1) + B = 1 \\ \end{cases} \Rightarrow \begin{cases} A = \frac{1}{2} \\ B = \frac{1}{2} \\ \end{cases}

M v i e w p o r t = ( w 2 0 0 w 2 0 h 2 0 h 2 0 0 1 2 1 2 0 0 0 1 ) M_{viewport} = \begin{pmatrix} \frac{w}{2} & 0 & 0 & \frac{w}{2} \\ 0 & \frac{h}{2} & 0 & \frac{h}{2} \\ 0 & 0 & \frac{1}{2} & \frac{1}{2} \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

# 参考

• [3] Steve Marschner and Peter Shirley，“Fundamentals of Computer Graphics”

03-13 687
05-08 748
11-23 3195
08-05 2635
06-07 2235
05-26 411
11-17 2404
07-24 758
03-07 3830
07-05 2978
10-26 717
07-16 3325
04-15 649

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

©️2022 CSDN 皮肤主题：大白 设计师：CSDN官方博客

longfeiah

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。