diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/1_1.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/1_1.png" index 0ae48949f5..1f53ad4e13 100644 Binary files "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/1_1.png" and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/1_1.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/2_1.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/2_1.png" index e707787ee1..2984b6756f 100644 Binary files "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/2_1.png" and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/2_1.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_1.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_1.png" new file mode 100644 index 0000000000..51fcf29f19 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_1.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_2.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_2.png" new file mode 100644 index 0000000000..f805b94582 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/3_2.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_1.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_1.png" new file mode 100644 index 0000000000..08c5ad459f Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_1.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_2.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_2.png" new file mode 100644 index 0000000000..cead1bdf1a Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_2.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_3.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_3.png" new file mode 100644 index 0000000000..270e4d045d Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_3.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_4.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_4.png" new file mode 100644 index 0000000000..350dadd00a Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_4.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_5.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_5.png" new file mode 100644 index 0000000000..58823e0f00 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_5.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_6.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_6.png" new file mode 100644 index 0000000000..424de0ded8 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_6.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_7.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_7.png" new file mode 100644 index 0000000000..72736dddda Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_7.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_8.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_8.png" new file mode 100644 index 0000000000..71619f6310 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/4_8.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_1.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_1.png" new file mode 100644 index 0000000000..e08286a5d9 Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_1.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_2.png" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_2.png" new file mode 100644 index 0000000000..3a25e29b7e Binary files /dev/null and "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/HW0_2.png" differ diff --git "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/index.html" "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/index.html" index 6b8842571d..0a91a26e0a 100644 --- "a/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/index.html" +++ "b/2023/10/25/CG-GAMES101-\347\216\260\344\273\243\350\256\241\347\256\227\346\234\272\345\233\276\345\275\242\345\255\246\345\205\245\351\227\250-\351\227\253\344\273\244\347\220\252\357\274\2101\357\274\211/index.html" @@ -336,7 +336,10 @@
What is Computer Graphics? 图形学的应用:
构建右手坐标系:
Matrix 矩阵
Matrix-Matrix Multiplication 矩阵乘法
-一般不满足交换律(一般不满足 $AB\= BA$)
+一般不满足交换律(一般不满足 $AB\ne BA$)
满足结合律和分配律:
2D Transform 二维变换
+Scale Transform 缩放
+等比缩放:
+用矩阵乘法表示:
+Scale (Non-Uniform) 任意缩放
+Reflection Matrix 镜像
+Horizontal reflection 水平镜像:
+用矩阵乘法表示:
+Shear Matrix 斜切:
+ +Hints:
+Rotation Matrix 旋转
+旋转相反的角等于矩阵的逆,等于矩阵的转置:
+旋转矩阵是正交矩阵。
+Linear Transforms = Matrices 线性变换 = 矩阵
+简写为:
+Translation 平移
+Why Homogeneous Coordinates 为什么引入齐次坐标
+因此,平移变换不是线性变换!
+But we don’t want translation to be a special case 但我们不希望平移变换成为特例
+Is there a unified way to represent all transformations? (and what’s the cost?) 用统一的方式描述所有变换?(代价是什么?)
+Solution: Homogenous Coordinates 解决办法:齐次坐标
+Add a third coordinate (w-coordinate) 增加一个维度
+Matrix representation of translations 用矩阵描述所有变换
+Valid operation if w-coordinate of result is 1 or 0 所增加维度的值不是 1 就是 0,这是因为:
+因此定义,在齐次坐标中:
+Affine Transformation 仿射变换
+Affine map = linear map + translation 仿射变换 = 线性变换 + 平移
+Using homogenous coordinates: 使用齐次坐标
+2D Transformations 2D 变换
+Scale 缩放
+Rotation 旋转
+Translation 平移
+Inverse Transform 逆变换
+Composing Transforms 复合变换
+Sequence of affine transforms $A_1, A_2, A_3, …$ 对于仿射变换序列 $A_1, A_2, A_3, …$
+预乘 $n$ 个矩阵以获得表示组合变换的单个矩阵。
+Decomposing Complex Transforms 分解复合变换
+ +How to rotate around a given point $c$? 如何绕空间任意一点 $c$ 旋转?
+3D Transforms
+Use homogeneous coordinates again 再次使用齐次坐标:
+In general, $(x, y, z, w) (w \ne 0)$ is the 3D point:
+3D Transformations 3D 变换
+Use $4\times 4$ matrices for affine transformations 使用 $4\times 4$ 齐次坐标表示:
+先应用线性变换,再平移。
+Viewing (观测) transformation
+3D Transformations 3D 变换
+Rotation around $x$-, $y$-, or $z$-axis 沿 $x$、$y$、$z$ 轴旋转:
+ +Compose any 3D rotation from $\mathbf{R}_x$, $\mathbf{R}_y$, $\mathbf{R}_z$? 让 $\mathbf{R}_x$, $\mathbf{R}_y$, $\mathbf{R}_z$ 构成任意三维旋转?
+Rodrigues’ Rotation Formula 罗德里格斯轮换公式
+绕轴 $n$ 旋转角度 $\alpha$:
+View / Camera Transformation 视图变换
+Key observation 重点观察
+How about that we always transform the camera to 不如我们总是把相机变成
+Transform the camera by $M_{view}$
+$M_{view}$ in math? $M_{view}=R_{view}T_{view}$
+Translates $e$ to origin
+$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}$
+Rotates $g$ to $-Z$、Rotates $t$ to $Y$、Rotates ($g \times t$) To $X$
+Difficult to write! 将 $g$ 旋转到 $-Z$ 轴、将 $t$ 旋转到 $Y$ 轴、将 ($g \times t$) 旋转到 $X$ 轴,描述成矩阵是很复杂的!
+考虑求其逆变换
+$R_{view}^{-1}=\begin{bmatrix}x_{\hat{g}\times\hat{t}}&x_{t}&x_{-g}&0\\y_{\hat{g}\times\hat{t}}&y_{t}&y_{-g}&0\\z_{\hat{g}\times\hat{t}}&z_{t}&z_{-g}&0\\0&0&0&1\end{bmatrix}$
+由于旋转矩阵是正交矩阵,其逆为它的转置,因此易求得 $R_{view}$
+$R_{view}=\begin{bmatrix}x_{\hat{g}\times\hat{t}}&y_{\hat{g}\times\hat{t}}&z_{\hat{g}\times\hat{t}}&0\\x_t&y_t&z_t&0\\x_{-g}&y_{-g}&z_{-g}&0\\0&0&0&1\end{bmatrix}$
+Summary 总结
+Also known as ModelView Transformation 也称为 ModelView 变换
+Projection Transformation 投影变换
+Orthographic Projection 正交投影
+A simple way of understanding 简单的理解方法
+In General
+We want to map a cuboid $[l, r]\times [b, t]\times [f, n]$ to the “canonical” cube $[-1, 1]^3$
+我们想把长方体 $[l,r]\times[b,t]\times[f,n]$ 映射到“规范(正则、规范、标准)” 的立方体 $[-1,1]^3$
+Slightly different orders (to the “simple way”)
+$r,l,t,b,n,f$ 的定义如下所示:
+ +Transformation matrix?
+Translate (center to origin) first, then scale (length/width/height to 2) 首先平移(中心到原点),然后缩放(长度/宽度/高度到 2)
+$M_{ortho}=\begin{bmatrix}\frac2{r-l}&0&0&0\\0&\frac2{t-b}&0&0\\0&0&\frac2{n-f}&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}$
+Caveat
+Perspective Projection 透视投影
+How to do perspective projection 如何进行透视投影
+First “squish” the frustum into a cuboid ($n \to n$, $f \to f$) ($M_{persp\to ortho}$)
+首先将截头体“压扁”成长方体($n\to n$,$f\to f$)($M_{persp\to ortho}$)
+Do orthographic projection ($M_{ortho}$, already known!) 做正交投影($M_{ortho}$,已经知道了!)
+In order to find a transformation 为了找到变换(推导出矩阵 $M_{persp\to ortho}$)
+Recall the key idea: Find the relationship between transformed points $(x’, y’,z’)$ and the original points $(x, y, z)$
+回想关键思想:找到转换之间的关系点 $(x’, y’,z’)$ 和原始点 $(x, y, z)$
+$y^{\prime}=\frac nzy$
+$x^{\prime}=\frac nzx$
+In homogeneous coordinates, 齐次坐标下,
+$\begin{pmatrix}x\\y\\z\\1\end{pmatrix}\Rightarrow\begin{pmatrix}nx/z\\ny/z\\\text{unknown}\\1\end{pmatrix}==\begin{pmatrix}nx\\ny\\\text{still unknown}\\z\end{pmatrix}$
+So the “squish” (persp to ortho) projection does this 所以“挤压”(透视到正交)投影可以做到这一点
+$M_{persp\to ortho}^{(4\times4)}\begin{pmatrix}x\\y\\z\\1\end{pmatrix}=\begin{pmatrix}nx\\ny\\\text{unknown}\\z\end{pmatrix}$
+Already good enough to figure out part of $M_{persp\to ortho}$ 可以求得 $M_{persp\to ortho}$ 的一部分:
+$M_{persp\to ortho}=\begin{pmatrix}n&0&0&0\\0&n&0&0\\?&?&?&?\\0&0&1&0\end{pmatrix}$
+Observation: the third row is responsible for $z’$ 观察:第三排负责 $z’$
+Any point on the near plane will not change 近平面上的任何点都不会改变
+Any point’s z on the far plane will not change 远平面上的任何点的 $z$ 都不会改变
+Any point on the near plane will not change 近平面上的任何点都不会改变
+$M_{persp\to ortho}^{(4\times4)}\begin{pmatrix}x\\y\\z\\1\end{pmatrix}=\begin{pmatrix}nx\\ny\\\text{unknown}\\z\end{pmatrix}\overset{\text{replace z with n}}{\operatorname*{\to}}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}\Rightarrow\begin{pmatrix}x\\y\\n\\1\end{pmatrix}==\begin{pmatrix}nx\\ny\\n^2\\n\end{pmatrix}$
+So the third row must be of the form $(0\ 0\ A\ B)$ 所以第三行的形式必须是$(0\ 0\ A\ B)$
+$\begin{pmatrix}0&0&A&B\end{pmatrix}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}=n^2$
+What do we have now?
+$\begin{pmatrix}0&0&A&B\end{pmatrix}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}=n^2\to An+B=n^2$
+Any point’s z on the far plane will not change 近平面上的任何点都不会改变
+$\begin{pmatrix}0\\0\\f\\1\end{pmatrix}\Rightarrow\begin{pmatrix}0\\0\\f\\1\end{pmatrix}==\begin{pmatrix}0\\0\\f^2\\f\end{pmatrix}\quad\to\quad Af+B=f^2$
+Solve for $A$ and $B$
+$\begin{aligned}An+B&=n^2\\Af+B&=f^2\end{aligned}\quad\to\quad\begin{aligned}A&=n+f\\B&=-nf\end{aligned}$
+Finally, every entry in $M_{persp\to ortho}$ is known!
+What’s next?
+环境配置
+WSL2 下:
+
|
配置环境变量:
+
|
MobaXterm 下配置 wsl2:
+ +开跑!
+ +安装库:
+
|
Windows 下的 VSCode,安装 wsl 插件,点击左下角,连接 wsl。
+ +打开作业模板,有如下命令:
+mkdir build
: 创建名为 build 的文件夹。cd build
: 移动到 build 文件夹下。cmake ..
: 注意其中 ’..’ 表示上一级目录,若为 ’.’ 则表示当前目录。make
: 编译程序,错误提示会显示在终端中。./Transformation
:若上一步无错误,则可运行程序(这里 Transformation 为可执行文件名,可参照 CMakeLists.txt 中修改)。写一个 compile.sh
便于编译:
|
修改权限:
+
|
开跑!
+
|
作业
+示例代码
+
|
题目
+给定一个点 $P=(2,1)$, 将该点绕原点先逆时针旋转 $45^\circ$,再平移
$(1,2)$,计算出变换后点的坐标(要求用齐次坐标进行计算)。
$P$ 以齐次坐标的表示形式为 $(2, 1, 1)^T$
+旋转矩阵为 $R(\pi/4)=\begin{bmatrix}
\cos \pi/4 & -\sin \pi/4 & 0 \\
\sin \pi/4 & \cos \pi/4 & 0 \\
0 & 0 & 1
\end{bmatrix}$
平移矩阵 $T(1, 2)=\begin{bmatrix}
1 & 0 & 1 \\
0 & 1 & 2 \\
0 & 0 & 1
\end{bmatrix}$
最终坐标为 $TRP$。
+
|
|
What is Computer Graphics? 图形学的应用:
Viedo Games 游戏
Movies 电影特效
Animations 动画
Design 设计
Visualization 可视化
Visual Reality 虚拟现实
Digital Illustration 数字化描述
Simulation 模拟
Graphical User Interfaces, GUI 图形用户接口
Typography 字体
Why study Computer Graphics?
Course Topics(mainly 4 parts)
Rasterization 光栅化
Curves and Meshes 曲线和模型
Ray Tracing 光线追踪
Animation / Simulation 动画 / 模拟
计算机图形学、计算机视觉、数字图像处理的区别:
A Swift and Brutal Introduction to Linear Algebra! 一份对线性代数的迅速且直接的介绍!
Graphics’ Dependencies 图形相关的依赖项
Basic mathematics 基础数学
Basic physics 基础物理学
Misc 杂项
Signal processing 信号处理
Numerical analysis 数值分析
And a bit of aesthetics 还有一点美学
This Course
Vectors
通常被写作 $\vec{a}$ 或 $\boldsymbol{a}$
向量的长度被写作 $\left|\left|\vec{a}\right|\right|$
向量的归一化,方向不变,长度设为 1:$\hat{a}=\vec{a}/|\vec{a}|$
Cartesian Coordinates 笛卡尔坐标系
Dot (scalar) Product 向量点乘
对于 Unit Vectors 单位向量:
性质:
交换律:$\vec{a}\cdot\vec{b}=\vec{b}\cdot\vec{a}$
分配律:$\vec{a}\cdot(\vec{b}+\vec{c})=\vec{a}\cdot\vec{b}+\vec{a}\cdot\vec{c}$
结合律:$(k\vec{a})\cdot\vec{b}=\vec{a}\cdot(k\vec{b})=k(\vec{a}\cdot\vec{b})$
Dot Product in Cartesian Coordinates 笛卡尔坐标系下的向量点乘
Component-wise multiplication, then adding up 分量逐个相乘,然后求和
In 2D
In 3D
Dot Product in Graphics 向量点乘在图形学中的应用
Finding projection of one vector on another 找到一个向量在另一个向量上的投影。
Measure how close two directions are 测量两个方向之间的接近程度
Cross (vector) Product 矢量积
性质:
对于右手坐标系:
不满足交换律:$\vec{a}\times\vec{b}=-\vec{b}\times\vec{a}$
跟自身叉乘为零向量:$\vec{a}\times\vec{a}=\vec{0}$
满足分配律:
$\vec{a}\times(\vec{b}+\vec{c})=\vec{a}\times\vec{b}+\vec{a}\times\vec{c}$
$\vec{a}\times(k\vec{b})=k(\vec{a}\times\vec{b})$
Cross Product: Cartesian Formula? 矢量积在笛卡尔坐标系中
$A^*$ 是 $\vec{a}$ 的伴随矩阵(伴随矩阵 - 维基百科,自由的百科全书 (wikipedia.org))
Cross Product in Graphics 矢量积在图形学中的应用
Orthonormal Bases / Coordinate Frames 正交基 / 坐标系
构建右手坐标系:
Matrix 矩阵
Matrix-Matrix Multiplication 矩阵乘法
一般不满足交换律(一般不满足 $AB\= BA$)
满足结合律和分配律:
Identity Matrix 单位矩阵
Vector multiplication in Matrix form 向量与矩阵相乘
What is Computer Graphics? 图形学的应用:
Viedo Games 游戏
Movies 电影特效
Animations 动画
Design 设计
Visualization 可视化
Visual Reality 虚拟现实
Digital Illustration 数字化描述
Simulation 模拟
Graphical User Interfaces, GUI 图形用户接口
Typography 字体
Why study Computer Graphics?
Course Topics(mainly 4 parts)
Rasterization 光栅化
Curves and Meshes 曲线和模型
Ray Tracing 光线追踪
Animation / Simulation 动画 / 模拟
计算机图形学、计算机视觉、数字图像处理的区别:
A Swift and Brutal Introduction to Linear Algebra! 一份对线性代数的迅速且直接的介绍!
Graphics’ Dependencies 图形相关的依赖项
Basic mathematics 基础数学
Basic physics 基础物理学
Misc 杂项
Signal processing 信号处理
Numerical analysis 数值分析
And a bit of aesthetics 还有一点美学
This Course
Vectors
通常被写作 $\vec{a}$ 或 $\boldsymbol{a}$
向量的长度被写作 $\left|\left|\vec{a}\right|\right|$
向量的归一化,方向不变,长度设为 1:$\hat{a}=\vec{a}/|\vec{a}|$
Cartesian Coordinates 笛卡尔坐标系
Dot (scalar) Product 向量点乘
对于 Unit Vectors 单位向量:
性质:
交换律:$\vec{a}\cdot\vec{b}=\vec{b}\cdot\vec{a}$
分配律:$\vec{a}\cdot(\vec{b}+\vec{c})=\vec{a}\cdot\vec{b}+\vec{a}\cdot\vec{c}$
结合律:$(k\vec{a})\cdot\vec{b}=\vec{a}\cdot(k\vec{b})=k(\vec{a}\cdot\vec{b})$
Dot Product in Cartesian Coordinates 笛卡尔坐标系下的向量点乘
Component-wise multiplication, then adding up 分量逐个相乘,然后求和
In 2D
In 3D
Dot Product in Graphics 向量点乘在图形学中的应用
Finding projection of one vector on another 找到一个向量在另一个向量上的投影。
Measure how close two directions are 测量两个方向之间的接近程度
Cross (vector) Product 矢量积
性质:
对于右手坐标系:
不满足交换律:$\vec{a}\times\vec{b}=-\vec{b}\times\vec{a}$
跟自身叉乘为零向量:$\vec{a}\times\vec{a}=\vec{0}$
满足分配律:
$\vec{a}\times(\vec{b}+\vec{c})=\vec{a}\times\vec{b}+\vec{a}\times\vec{c}$
$\vec{a}\times(k\vec{b})=k(\vec{a}\times\vec{b})$
Cross Product: Cartesian Formula? 矢量积在笛卡尔坐标系中
$A^*$ 是 $\vec{a}$ 的伴随矩阵(伴随矩阵 - 维基百科,自由的百科全书 (wikipedia.org))
Cross Product in Graphics 矢量积在图形学中的应用
Orthonormal Bases / Coordinate Frames 正交基 / 坐标系
构建右手坐标系:
Matrix 矩阵
Matrix-Matrix Multiplication 矩阵乘法
一般不满足交换律(一般不满足 $AB\ne BA$)
满足结合律和分配律:
Identity Matrix 单位矩阵
Vector multiplication in Matrix form 向量与矩阵相乘
2D Transform 二维变换
Scale Transform 缩放
等比缩放:
用矩阵乘法表示:
Scale (Non-Uniform) 任意缩放
Reflection Matrix 镜像
Horizontal reflection 水平镜像:
用矩阵乘法表示:
Shear Matrix 斜切:
Hints:
Rotation Matrix 旋转
旋转相反的角等于矩阵的逆,等于矩阵的转置:
旋转矩阵是正交矩阵。
Linear Transforms = Matrices 线性变换 = 矩阵
简写为:
Translation 平移
Why Homogeneous Coordinates 为什么引入齐次坐标
因此,平移变换不是线性变换!
But we don’t want translation to be a special case 但我们不希望平移变换成为特例
Is there a unified way to represent all transformations? (and what’s the cost?) 用统一的方式描述所有变换?(代价是什么?)
Solution: Homogenous Coordinates 解决办法:齐次坐标
Add a third coordinate (w-coordinate) 增加一个维度
Matrix representation of translations 用矩阵描述所有变换
Valid operation if w-coordinate of result is 1 or 0 所增加维度的值不是 1 就是 0,这是因为:
因此定义,在齐次坐标中:
Affine Transformation 仿射变换
Affine map = linear map + translation 仿射变换 = 线性变换 + 平移
Using homogenous coordinates: 使用齐次坐标
2D Transformations 2D 变换
Scale 缩放
Rotation 旋转
Translation 平移
Inverse Transform 逆变换
Composing Transforms 复合变换
Sequence of affine transforms $A_1, A_2, A_3, …$ 对于仿射变换序列 $A_1, A_2, A_3, …$
预乘 $n$ 个矩阵以获得表示组合变换的单个矩阵。
Decomposing Complex Transforms 分解复合变换
How to rotate around a given point $c$? 如何绕空间任意一点 $c$ 旋转?
3D Transforms
Use homogeneous coordinates again 再次使用齐次坐标:
In general, $(x, y, z, w) (w \ne 0)$ is the 3D point:
3D Transformations 3D 变换
Use $4\times 4$ matrices for affine transformations 使用 $4\times 4$ 齐次坐标表示:
先应用线性变换,再平移。
Viewing (观测) transformation
3D Transformations 3D 变换
Rotation around $x$-, $y$-, or $z$-axis 沿 $x$、$y$、$z$ 轴旋转:
Compose any 3D rotation from $\mathbf{R}_x$, $\mathbf{R}_y$, $\mathbf{R}_z$? 让 $\mathbf{R}_x$, $\mathbf{R}_y$, $\mathbf{R}_z$ 构成任意三维旋转?
Rodrigues’ Rotation Formula 罗德里格斯轮换公式
绕轴 $n$ 旋转角度 $\alpha$:
View / Camera Transformation 视图变换
Key observation 重点观察
How about that we always transform the camera to 不如我们总是把相机变成
Transform the camera by $M_{view}$
$M_{view}$ in math? $M_{view}=R_{view}T_{view}$
Translates $e$ to origin
$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}$
Rotates $g$ to $-Z$、Rotates $t$ to $Y$、Rotates ($g \times t$) To $X$
Difficult to write! 将 $g$ 旋转到 $-Z$ 轴、将 $t$ 旋转到 $Y$ 轴、将 ($g \times t$) 旋转到 $X$ 轴,描述成矩阵是很复杂的!
考虑求其逆变换
$R_{view}^{-1}=\begin{bmatrix}x_{\hat{g}\times\hat{t}}&x_{t}&x_{-g}&0\\y_{\hat{g}\times\hat{t}}&y_{t}&y_{-g}&0\\z_{\hat{g}\times\hat{t}}&z_{t}&z_{-g}&0\\0&0&0&1\end{bmatrix}$
由于旋转矩阵是正交矩阵,其逆为它的转置,因此易求得 $R_{view}$
$R_{view}=\begin{bmatrix}x_{\hat{g}\times\hat{t}}&y_{\hat{g}\times\hat{t}}&z_{\hat{g}\times\hat{t}}&0\\x_t&y_t&z_t&0\\x_{-g}&y_{-g}&z_{-g}&0\\0&0&0&1\end{bmatrix}$
Summary 总结
Also known as ModelView Transformation 也称为 ModelView 变换
Projection Transformation 投影变换
Orthographic Projection 正交投影
A simple way of understanding 简单的理解方法
In General
We want to map a cuboid $[l, r]\times [b, t]\times [f, n]$ to the “canonical” cube $[-1, 1]^3$
我们想把长方体 $[l,r]\times[b,t]\times[f,n]$ 映射到“规范(正则、规范、标准)” 的立方体 $[-1,1]^3$
Slightly different orders (to the “simple way”)
$r,l,t,b,n,f$ 的定义如下所示:
Transformation matrix?
Translate (center to origin) first, then scale (length/width/height to 2) 首先平移(中心到原点),然后缩放(长度/宽度/高度到 2)
$M_{ortho}=\begin{bmatrix}\frac2{r-l}&0&0&0\\0&\frac2{t-b}&0&0\\0&0&\frac2{n-f}&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}$
Caveat
Perspective Projection 透视投影
How to do perspective projection 如何进行透视投影
First “squish” the frustum into a cuboid ($n \to n$, $f \to f$) ($M_{persp\to ortho}$)
首先将截头体“压扁”成长方体($n\to n$,$f\to f$)($M_{persp\to ortho}$)
Do orthographic projection ($M_{ortho}$, already known!) 做正交投影($M_{ortho}$,已经知道了!)
In order to find a transformation 为了找到变换(推导出矩阵 $M_{persp\to ortho}$)
Recall the key idea: Find the relationship between transformed points $(x’, y’,z’)$ and the original points $(x, y, z)$
回想关键思想:找到转换之间的关系点 $(x’, y’,z’)$ 和原始点 $(x, y, z)$
$y^{\prime}=\frac nzy$
$x^{\prime}=\frac nzx$
In homogeneous coordinates, 齐次坐标下,
$\begin{pmatrix}x\\y\\z\\1\end{pmatrix}\Rightarrow\begin{pmatrix}nx/z\\ny/z\\\text{unknown}\\1\end{pmatrix}==\begin{pmatrix}nx\\ny\\\text{still unknown}\\z\end{pmatrix}$
So the “squish” (persp to ortho) projection does this 所以“挤压”(透视到正交)投影可以做到这一点
$M_{persp\to ortho}^{(4\times4)}\begin{pmatrix}x\\y\\z\\1\end{pmatrix}=\begin{pmatrix}nx\\ny\\\text{unknown}\\z\end{pmatrix}$
Already good enough to figure out part of $M_{persp\to ortho}$ 可以求得 $M_{persp\to ortho}$ 的一部分:
$M_{persp\to ortho}=\begin{pmatrix}n&0&0&0\\0&n&0&0\\?&?&?&?\\0&0&1&0\end{pmatrix}$
Observation: the third row is responsible for $z’$ 观察:第三排负责 $z’$
Any point on the near plane will not change 近平面上的任何点都不会改变
Any point’s z on the far plane will not change 远平面上的任何点的 $z$ 都不会改变
Any point on the near plane will not change 近平面上的任何点都不会改变
$M_{persp\to ortho}^{(4\times4)}\begin{pmatrix}x\\y\\z\\1\end{pmatrix}=\begin{pmatrix}nx\\ny\\\text{unknown}\\z\end{pmatrix}\overset{\text{replace z with n}}{\operatorname*{\to}}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}\Rightarrow\begin{pmatrix}x\\y\\n\\1\end{pmatrix}==\begin{pmatrix}nx\\ny\\n^2\\n\end{pmatrix}$
So the third row must be of the form $(0\ 0\ A\ B)$ 所以第三行的形式必须是$(0\ 0\ A\ B)$
$\begin{pmatrix}0&0&A&B\end{pmatrix}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}=n^2$
What do we have now?
$\begin{pmatrix}0&0&A&B\end{pmatrix}\begin{pmatrix}x\\y\\n\\1\end{pmatrix}=n^2\to An+B=n^2$
Any point’s z on the far plane will not change 近平面上的任何点都不会改变
$\begin{pmatrix}0\\0\\f\\1\end{pmatrix}\Rightarrow\begin{pmatrix}0\\0\\f\\1\end{pmatrix}==\begin{pmatrix}0\\0\\f^2\\f\end{pmatrix}\quad\to\quad Af+B=f^2$
Solve for $A$ and $B$
$\begin{aligned}An+B&=n^2\\Af+B&=f^2\end{aligned}\quad\to\quad\begin{aligned}A&=n+f\\B&=-nf\end{aligned}$
Finally, every entry in $M_{persp\to ortho}$ is known!
What’s next?
环境配置
WSL2 下:
|
配置环境变量:
|
MobaXterm 下配置 wsl2:
开跑!
安装库:
|
Windows 下的 VSCode,安装 wsl 插件,点击左下角,连接 wsl。
打开作业模板,有如下命令:
mkdir build
: 创建名为 build 的文件夹。cd build
: 移动到 build 文件夹下。cmake ..
: 注意其中 ’..’ 表示上一级目录,若为 ’.’ 则表示当前目录。make
: 编译程序,错误提示会显示在终端中。./Transformation
:若上一步无错误,则可运行程序(这里 Transformation 为可执行文件名,可参照 CMakeLists.txt 中修改)。写一个 compile.sh
便于编译:
|
修改权限:
|
开跑!
|
作业
示例代码
|
题目
给定一个点 $P=(2,1)$, 将该点绕原点先逆时针旋转 $45^\circ$,再平移
$(1,2)$,计算出变换后点的坐标(要求用齐次坐标进行计算)。
$P$ 以齐次坐标的表示形式为 $(2, 1, 1)^T$
旋转矩阵为 $R(\pi/4)=\begin{bmatrix}
\cos \pi/4 & -\sin \pi/4 & 0 \\
\sin \pi/4 & \cos \pi/4 & 0 \\
0 & 0 & 1
\end{bmatrix}$
平移矩阵 $T(1, 2)=\begin{bmatrix}
1 & 0 & 1 \\
0 & 1 & 2 \\
0 & 0 & 1
\end{bmatrix}$
最终坐标为 $TRP$。
|
|