Overview

Cont. 也就是 continue 的意思吧 >..<

local space (.obj)               -- Model -->
→ world space                    -- View -->
→ camera view space              -- Projection -->
→ clip space   (x, y, z, w)      -- perspective divide -->
→ NDC space    (x/w, y/w, z/w)   -- Viewport -->
→ screen space (x,y)

// clip = Projection * View * Model * local_position;
// ndc  = clip / clip.w;
// screen = Viewport * ndc;

Model

  1. 模型本身的本地坐标

模型是一系列的三角形面,通过一系列的三角形顶点坐标表示出来,可以通过加载模型文件直接拿到,例如 .obj 格式,

  1. 模型缩放,模型在场景中怎么摆放 (移动、旋转)

View

image.png

View 就是一个观测,就是我们拿着一个摄像机看场景。摄像机可以在空间中的任意位置,朝向任意角度,比方说相机在空间中的位置是上图 $\overrightarrow{e}$ 。我们对它做这样的处理——把它移动到坐标原点,然后旋转至与坐标轴方向一致。这等价与把场景中所有其他物体做相反变换,那么我们的相机就自然而然再原点。具体做法如下:

  1. Translates $\overrightarrow{e}$ to origin

    image.png

  2. Rotate $\hat{g}$ to -z, $\hat{t}$ to y, $\hat{g} \times \hat{t}$ to x

  3. Consider it’s inverse rotation: x to $\hat{g} \times \hat{t}$, y to $\hat{t}$, z to $\hat{g}$

    Transforme objects together with the camera.

    正交矩阵求逆,直接转置就可以。

    正交矩阵求逆,直接转置就可以。

    <aside>

    步骤2 的 $R_{view}$ 很难写,但是我们可以很容易写出来 $R^{-1}_{view}$,然后再求逆矩阵就好了。

    $R^{-1}_{view}$ 怎么写出来 GAMES 101 并没有细讲,只是说你可以代入验证它是对的,这样的方式我不喜欢,建议看 3Brown1Blue 的视频《线性代数的本质》去理解了线性变换的几何意义,之后再这里就非常简单了。可以理解为 “基变换”——竖着看矩阵的每一列,把它们看做向量。这个矩阵的对应的变换就是把原来的坐标系基底向量对应地变成现在的列表示的向量,这个过程中其他所有的点跟着线性变换 (线性可以简单理解为就是比例不变地移动,原来平行变换后还是平行)

    于是我们看前三列,不用解释,显然就是 : x to $\hat{g} \times \hat{t}$, y to $\hat{t}$, z to $\hat{g}$

    想要了解更多可以看线性代数笔记 Linear Algebra

    </aside>

    <aside>

    这里相机的变换的时候,场景中一切其他物体也要跟着变换(确保相对位置不变)。

    </aside>

Projection

image.png

Orthograpc Projection (正交投影)

A simple way of understanding

  1. Camera located at origin, looking at -Z, up at Y.
  2. Drop Z coordinate
  3. Translate (center to origin) first, then scale (length/width/height to 2) (the canonical cube [-1, 1]$^3$)

In General