图形学基础 | 基础视图变换

视图变换 (View transformation)

将虚拟世界中具有三维坐标的物体(x, y, z)变换到以二维的像素位置(x, y)来表示的屏幕坐标系之中:

  1. 模型变换 (modeling tranformation)
    将场景中的物体调整至坐标所在位置

  2. 摄像机变换 (camera tranformation)
    得到物体与摄像机的相对位置

  3. 投影变换 (projection tranformation)
    便是根据平行投影或透视投影将三维空间投影至标准二维平面 [ − 1 , 1 ] 2 [-1,1]^2 [1,1]2之上

  4. 视口变换 (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=gg,u=t×wt×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=lleft planex=rright planey=bbottom planey=ttop planez=nnear planez=ffar plane

空间转换分为三个步骤,

  1. 将原空间范围的左下角移至原点
  2. 缩放给定倍数
  3. 将缩放后的空间范围移至新空间范围

以二维转换为例:
2d
可以得到变换矩阵:

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 −

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值