目录
视图变换 (View transformation)
将虚拟世界中具有三维坐标的物体(x, y, z)变换到以二维的像素位置(x, y)来表示的屏幕坐标系之中:
-
模型变换 (modeling tranformation)
将场景中的物体调整至坐标所在位置 -
摄像机变换 (camera tranformation)
得到物体与摄像机的相对位置 -
投影变换 (projection tranformation)
便是根据平行投影或透视投影将三维空间投影至标准二维平面 [ − 1 , 1 ] 2 [-1,1]^2 [−1,1]2之上 -
视口变换 (viewport transformation)
将标准平面 [ − 1 , 1 ] 2 [-1,1]^2 [−1,1]2映射到屏幕分辨率范围 [ 0 , w i d t h ] ∗ [ 0 , h e i g h t ] [0,width]*[0,height] [0,width]∗[0,height]之内
1. 模型变换 (Modeling tranformation)
利用基础的变换矩阵将世界当中的物体调整至我们想要的地方
-
基础变换/仿射变换 = 线性变换 + 平移
-
线性变换 = 旋转 + 缩放 + 切变
2. 摄像机变换 (Camera tranformation)
把摄像机的坐标轴(假设为u,v,w分别对应原世界空间中的x,y,z)移动到标准的x,y,z轴
定义以下几个变量:
相机或眼睛位置 (eye postion): e \boldsymbol{e} e
观察方向 (gaze postion): g \boldsymbol{g} g
视点正上方向 (view-up vector): t \boldsymbol{t} t
摄像机坐标系定义如下:
w = − g ∥ g ∥ , u = t × w ∥ t × w ∥ , v = w × u \boldsymbol{w}=-\frac{\boldsymbol{g}}{\|\boldsymbol{g}\|} , \boldsymbol{u}=\frac{\boldsymbol{t} \times \boldsymbol{w}}{\| \boldsymbol{t} \times \boldsymbol{w}\|} , \boldsymbol{v}= \boldsymbol{w} \times \boldsymbol{u} w=−∥g∥g,u=∥t×w∥t×w,v=w×u
将摄像机坐标移动到原坐标系:
M c a m = [ u v w e 0 0 0 1 ] − 1 M_{cam} = \begin{bmatrix} \boldsymbol{u} & \boldsymbol{v} & \boldsymbol{w} & \boldsymbol{e} \\ 0 & 0 & 0 & 1 \end{bmatrix} ^ {-1} Mcam=[u0v0w0e1]−1
3. 投影变换 (Projection tranformation)
正交投影 (Orthographic projection)
正交投影将将物体转换到一个 [ − 1 , 1 ] 2 [-1,1]^2 [−1,1]2的正方体中。
首先定义:
x = l ≡ l e f t p l a n e x = r ≡ r i g h t p l a n e y = b ≡ b o t t o m p l a n e y = t ≡ t o p p l a n e z = n ≡ n e a r p l a n e z = f ≡ f a r p l a n e \begin{aligned} &x=l\equiv left \ plane \\ &x=r\equiv right \ plane \\ &y=b\equiv bottom \ plane \\ &y=t\equiv top \ plane \\ &z=n\equiv near \ plane \\ &z=f\equiv far \ plane \end{aligned} x=l≡left planex=r≡right planey=b≡bottom planey=t≡top planez=n≡near planez=f≡far plane
空间转换分为三个步骤,
- 将原空间范围的左下角移至原点
- 缩放给定倍数
- 将缩放后的空间范围移至新空间范围
以二维转换为例:
可以得到变换矩阵:
w i n d o w = t r a n s l a t e ( x l ′ , y l ′ ) s c a l e ( x h ′ − x l ′ x h − x l , y h ′ − y l ′ y h − y l ) t r a n s l a t e ( − x l , − y l ) = [ 1 0 x l ′ 0 1 y l ′ 0 0 1 ] [ x h ′ − x l ′ x h − x l 0 0 0 y h ′ − y l ′ y h − y l 0 0 0 0 ] [ 1 0 − x l 0 1 − y l 0 0 1 ] = [ x h ′ − x l ′ x h − x l 0 x l ′ x h −