MVP transformation

(本文为三无产品。不含详细推导过程,不含示意图,不知所云。仅供围观)


  1. model transformation

    模型在世界坐标系下的表示

  2. view/camera transformation

    将相机调整到世界坐标系上,使得模型在相机坐标系下表示

  3. projection transformation

设模型位于给定frustum/cube中,将其映射至的标准立方体中

  1. viewport transformation

    将标准立方体映射至显示屏幕上

1. Model Transformation (M)

from model to world transform:

2. View/Camera Transformation (V)

from world coordinate to camera

  • -- camera/eye position
  • -- gaze direction (look at)
  • -- view-up vector

其中和不一定垂直

世界坐标系:

camera的base在世界坐标系的表示为:,最后归一化

表示为:

表示为:
\begin{align} M_{view} &= \begin{pmatrix} R_{world \to cam}^{-1} & -\bf{e} \\ \bf{0} & 1 \\ \end{pmatrix} \\ &= \begin{pmatrix} \bf{u}_x & \bf{u}_y & \bf{u}_z & -\bf{e}_x \\ \bf{v}_x & \bf{v}_y & \bf{v}_z & -\bf{e}_y \\ \bf{w}_x & \bf{w}_y & \bf{w}_z & -\bf{e}_z \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \end{align}

3. Projection Transformation (P)

3.1 Orthographic Projection Transformation (正交投影变换)

from cube to canonical cube

define cube plane:

  • -- left plane
  • -- right plane
  • -- bottom plane
  • -- top plane
  • -- near plane
  • -- far plane

变换步骤:先平移至原点,再缩放
M_{orth} = \begin{pmatrix} \cfrac{2}{r-l} & 0 & 0 & -\cfrac{r+l}{r-l} \\ 0 & \cfrac{2}{t-b} & 0 & -\cfrac{t+b}{t-b} \\ 0 & 0 & \cfrac{2}{n-f} & -\cfrac{n+f}{n-f} \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

3.2 Perspective Projection Transformation (透视投影变换)

from frustum to cube: 保持近平面不变,远平面形状压缩为近平面(z值不变)

define frustum plane distance:

  • -- near plane
  • -- far plane

以下公式基于虎书(此处假设)

而在一些图形API中,假设,此时:

最终透视投影变换可以表示为:

如果给定以下参数,define frustum para:

  • -- field of view (视场角,竖直方向)
  • -- 宽高比

so:

考虑frustum参数,并且认为frustum设置于camera朝向轴线上,可以表示为:
M_{orth} = \begin{pmatrix} \cfrac{-n/|n|}{ratio \cdot \tan{\frac{fov}{2}}} & 0 & 0 & 0 \\ 0 & \cfrac{-n/|n|}{\tan{\frac{fov}{2}}} & 0 & 0 \\ 0 & 0 & \cfrac{2}{n-f} & -\cfrac{n+f}{n-f} \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

so:
M_{persp} = \begin{pmatrix} \cfrac{-n/|n|}{ratio \cdot \tan{\frac{fov}{2}}} & 0 & 0 & 0 \\ 0 & \cfrac{-n/|n|}{\tan{\frac{fov}{2}}} & 0 & 0 \\ 0 & 0 & \cfrac{n+f}{n-f} & -\cfrac{2nf}{n-f} \\ 0 & 0 & n/|n| & 0 \\ \end{pmatrix}

4. Viewport Transformation (视口变换)

from canonical cube to screen

define

scale: ,z方向不变

Ref

  1. games101
  2. Fundamentals of Computer Graphics, Fourth Edition, 4th Edition
  3. 计算机图形学二:视图变换(坐标系转化,正交投影,透视投影,视口变换)

你可能感兴趣的:(MVP transformation)