CG02:View/Camera, Projection And Viewport Transformation In Computer Graphics

This is a summary blog around "GAMES101: Introduction to Modern Computer Graphics", taught by Lingqi Yan. The knowledge and images involved are quoted from the instructor Lingqi Yan's lecture notes and book "Fundamentals of Computer Graphics 4th".


Catalog

How the transformation process works?

1. Model Transformation

2. View/Camera Transformation

2.1 Camera coordinate system

2.2 Transform the camera

 3. Projection Transformation

3.1. Orthographic projection

3.2. Perspective projection

4. Viewport Transformation

Reference


How the transformation process works?

Think about how to take a photo

在侧边栏查询中搜索

StepsWhat to do?Modeling
Steps1Find a good place and arrange peopleModel transformationTo adjust objects in the virtual world where they should be
Steps2Find a good “angle” to put the cameraView/Camera transformationTo get the relative position of objects and camera 
Steps3Cheese!Projection transformationProject 3D space onto standard 2D plane ([-1,1]^2)(by orthographic or perspective projection)
Viewport transformationMapping the standard plane to the screen resolution range, i.e., [-1,1]^2→[0,width]*[0,height]

1. Model Transformation

CG01:Model Transformation In Computer Graphicshttps://blog.youkuaiyun.com/weixin_45336082/article/details/126248635?spm=1001.2014.3001.5501


2. View/Camera Transformation

2.1 Camera coordinate system

  • Position \large \bg_white \large \vec{e}
  • Look-at / gaze direction \large \hat{g}
  • Up direction(assuming perp. to loo-at) \large \hat{t}

2.2 Transform the camera

The purpose of the camera transformation is to get the relative position of all objects to the camera. It is known that simultaneous movement of the object and the camera does not affect the final image result. 

We move the object and the camera simultaneously to make camera locate at the origin, up at Y, look at -Z. Then the coordinates of the object is the relative coordinates of object and camera.

The transformation matrix of the rotation is an orthogonal matrix, so the inverse matrix can be obtained by transposing. In other words, we can transpose a rotation transformation matrix to get its inverse transformation matrix.


 3. Projection Transformation

After the camera transformation, the result is still three-dimensional space coordinates, how to map it to two-dimensional space coordinates is left to the projection transformation to complete. As we know, projections are mainly divided into orthogonal and perspective projections.

Perspective projection vs. orthographic projection

3.1. Orthographic projection

In orthogonal projection, all rays are propagated in parallel and the relative positions of the coordinates do not change.

In general, We want to map a cuboid [l, r] \times [b, t] \times [f, n] to the “canonical (正则、规范、标准)” cube [ - 1 , 1 ]^3 (for calculation convenience).

Consider only the x, y coordinates, it translate (center to origin) first, then scale (length/width/height to 2). Then we can get the transformation matrix.

3.2. Perspective projection

Perspective projection is the way most similar to how the human eye sees things, following the principle that near objects are relatively larger and distant objects are relatively smaller.

We find the relationship between transformed points (x’, y’, z’) and the original points (x, y, z) as follows,

 Then, in homogenous coordinates, we wish to find a matrix that completes the following transformation.

i.e., 

First, the first two rows and the last row of this matrix can be determined very quickly,

So how to determine the third row? Then here it is necessary to apply the properties of perspective projection. 

1) Any point’s z on the near plane will not change

First we perform a rewrite on transformation result, i.e. ,replace z with n,

So the third row must be of the form \bg_white \large (0,0,A,B), i.e.,

Now we have,

2) Any point’s z on the far plane will not change

Similarly, we can obtain,

Solve for A and B,

 Finally, every entry in M_{persp->ortho} is known!

 \LARGE M_{\text {persp } \rightarrow \text { ortho }}=\left(\begin{array}{cccc} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ 0 & 0 & n+f & -fn \\ 0 & 0 & 1 & 0 \end{array}\right)

At last, do orthographic projection (M_{ortho}) to finish

\LARGE M_{persp} = M_{ortho}M_{persp\rightarrow ortho}

\LARGE \mathbf{M}_{\mathrm{persp}}=\left[\begin{array}{cccc} \frac{2 n}{r-l} & 0 & \frac{l+r}{l-r} & 0 \\ 0 & \frac{2 n}{t-b} & \frac{b+t}{b-t} & 0 \\ 0 & 0 & \frac{f+n}{n-f} & \frac{2 f n}{f-n} \\ 0 & 0 & 1 & 0 \end{array}\right]


4. Viewport Transformation

This step is very simple, as introduced in the orthogonal transformation is the conversion of two range spaces. Mapping the standard plane to the screen resolution range, i.e., [-1,1]^2\rightarrow [0,width]*[0,height].

\LARGE M_{\text {viewport }}=\left(\begin{array}{cccc} \frac{\text { width }}{2} & 0 & 0 & \frac{\text { width }}{2} \\ 0 & \frac{\text { height }}{2} & 0 & \frac{\text { height }}{2} \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right)


Reference

[1] Marschner S , Shirley P. Fundamentals of Computer Graphics 4th

[2] Lingqi Yan,  GAMES101: 现代计算机图形学入门

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值