二刷GAMES11 Transformation

齐次座标

引入齐次座标是想把包含平移在内的变换写成一个矩阵乘以一个向量的形式。

Homogenous Coordinates
2D point \((x,y,1)^T\) 其实是\((x/w,y/w,w)^T\) w不等于0
2D vector \((x,y,0)^T\)

2D Transformations

  • 缩放,Scale

\[\mathbf{S}(s_x,s_y)=\begin{pmatrix}s_x&0&0\\0&s_y&0\\0&0&1\end{pmatrix} \]

  • 旋转,Rotation

\[\mathbf{R}(\alpha)=\begin{pmatrix}\cos\alpha&-\sin\alpha&0\\\sin\alpha&\cos\alpha&0\\0&0&1\end{pmatrix} \]

  • 平移,Translation

\[\mathbf{T}(t_x,t_y)=\begin{pmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{pmatrix} \]

  • 斜切,Shear

组合变换

变换顺序很重要,矩阵点乘不符合交换律

仿射变换(Affine transformation),又称仿射映射,是指在几何中,对一个向量空间进行一次线性变换并接上一个平移,变换为另一个向量空间。
线性变换不改变原点。
齐次座标通过高纬度的线性变换完成低纬度的仿射变换。
旋转矩阵是正交矩阵,旋转矩阵的逆是旋转矩阵的转置。

3D Transformations

  • 缩放,Scale
  • 旋转,Rotation
  • 平移,Translation

相机成像投影

View/Camera Transformation

定义相机

  • Position
  • Look-at / gaze direction
  • Up direction

一般相机的标准定位

  • The origin, up at Y, look at -Z
  • And transform the objects along with the camera

Projection Transformation

将3D转为2D

  • 正交投影


    规范化的过程,平移到原点,缩放到[1,1,1]标准正方体中

  • 透视投影
    近大远小


    思路是先将f平面挤压成和n平面一样大小的,然后进行正交投影
    挤压的矩阵定义为\(M_{persp->ortho}\),同时n平面上的点座标不变,f平面点z座标不变。
    推导过程见图。
    课上问题:中间的点挤压后z会变大还是变小
    答:z变大了。推导过程如下:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章