二刷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變大了。推導過程如下:

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