GAMES101_1
Carpe Tu Black Whistle

Linear Algebra

和所有课一样,lecture2 做了线性代数的复习课
这里只摘录了一些补充

Cross product

叉乘具有向量表示

左边 3x3 的矩阵叫做 dual matrix of vector

Homogenous Coordinates and Transformation

Homogenous Coordinates: 齐次坐标

Affine map = linear map + translation

通过增加一个维度的方法,可以统一仿射变换为矩阵乘法形式。

  • Translation cannot be represented in matrix form

  • But we don’t want translation to be a special case
  • Is there a unified way to represent all transformations?(and what’s the cost?)

用齐次坐标,能够统一所有的图形变换

More Definition

Add a third coordinate(w-coordinate)

  • 2D point
  • 2D vector

dim-3 补0的向量就不会被受平移影响

Matrix representation of translations

增加第三维度,1为点,0为向量.
做以上矩阵乘法运算,向量vector不会受影响,但是 Point 会出现平移

Valid operation if w-coordinate of result is 1 or 0
坐标系是纵坐标系(没有

  • vec + vec = vec
  • point - point = vec
  • point + vec = point
  • point + point = ??

扩充定义

不为1时,默认可以对向量所有元素除去

引入齐次坐标,可以直接将平移变换融入矩阵乘法。

inverse transform

is the inverse of transformin both a matrix and geometric sense

composing transforms

Sequence of affine transforms

  • Compose by matrix multiplication
    • Very important for performance!

compose transform

多个n维矩阵乘积得到的单个矩阵,反映复合变换

rotate around any point

无特别指明,永远围绕原点旋转
Transform Ordering Matters!

  1. Translate center to origin.
  2. Rotate.
  3. Translate back.

image

Matrix representation?

3D transformations

Use 4 by 4 matrices for affine transformations

先应用了线性变换再加上了平移量。

  • 旋转的变换就是前3维度,基变换
    • Rotation around x-, y-, or z-axis

Compose any 3D rotation from

  • So-called Euler angles
  • Often used in flight simulators: roll, pitch, yaw

image

Rodrigues’s Rotation Formula

Rotation by anglearound axis

参考资料:
https://blog.csdn.net/weixin_40215443/article/details/123950141
https://sites.cs.ucsb.edu/~lingqi/teaching/resources/GAMES101_Lecture_04_supp.pdf
闫老师这个真的看不懂。。。

  • 缩放scale是单位矩阵的对应维度的数乘

    • Scale
  • 位移是最后一列的加减

    • Translation

Viewing transformation

aka Camera Transformation

  • Viewing transformation
    • View/Camera transformation
    • Projection transformation
      • Orthographic projection
      • Perspective projection

  1. model transformation
  2. view tranformation
  3. projection transformation

Define the camera

  • Position
  • Look-at /gaze direction
  • Up direction

Key observation
If the camera and all objects move together, the “photo” will be the same

image

SO we always transform the camera to

  • The origin, up at Y, look at -Z
  • transform the objects along with the camera

image

对于任意位置的相机和物体,变换到原点处基本思路:

  1. 平移到原点
  2. 旋转g->-Z
  3. 旋转t->Y
  4. (g x t)自然与X轴对齐

image

这里旋转矩阵求逆,利用了正交矩阵的性质旋转等于取逆

Also known as ModelView Transformation

for projection transformation

Projection

  • Projection in Computer Graphics
    • 3D to 2D
    • Orthographic projection
    • Perspective projection

image

image

Orthographic Projection

  • A simple way of undersatanding
    • Cam located at origin, looking at -Z, up at Y
    • Drop Z coordinate
    • Translate and scale the resulting rectangle to

image

相机固定于原点,看向-Z方向,可以忽略-Z维度

在空间里定义一个立方体
然后将立方体 [l, r] x [b, t] x [f, n] to the “canonical” cube

  • Transformation matrix
    • transalte(center to origin) first, then scale(length/width/height to 2)

  • Caveat
    • Looking at/along -Z is making near and far not intuitive(n>f)
    • FYI:that’s why OpenGL(a Graphics API) uses left hand coords

Perspective Projection

  • Most common in Computer Graphics, art, visual system.
  • Further objects are smaller.
  • Parallel lines not parallel; converge to single point.

image

image

  • How to do perspective projection
    • First “squish” the frustum into a cuboid(n->n, f->f)()
    • Do orthographic projection(, already known!)

image

先做挤压操作,把frustum挤压成长方体
远平面挤压,近平面不变

被认为是,将远平面挤压变形同近平面再做正交投影

  • In order to find a transformation
    • Find the relationship between transformed points(x’, y’, z’) and the original points(x, y, z)

根据远近平面的设定 In homogeneous coordinates
image

  • Any point on the near plane will not change
  • Any point’s z on the far plane will not change
    根据近平面和远平面的两个设定(利用了近平面不变,远平面中心不变)作为边值条件,求得变换矩阵

对于任意距离的平面,经过以上的形变,距离会被压缩的更远
可以参考 知乎文章
注意:n和f的设定一定是等符号的,这由透视投影的物理场景决定。

  • Finally, every entry in