当前位置: 代码迷 >> 综合 >> GAMES101-04空间变换 Cont.
  详细解决方案

GAMES101-04空间变换 Cont.

热度:48   发布时间:2024-01-05 10:33:46.0

04空间变换 Cont.

  • 一、3D transformations
  • 二、Viewing (观测) transformation
    • 1.View(视图)/ Camera transformation
    • 2.Projection (投影) transformation


一、3D transformations

//在数学上,如果一个矩阵的逆等于它的转置,则叫做正交矩阵


万向锁

Rodrigues’ Rotation Formula
罗德里格斯旋转公式

定义了一个旋转轴和一个旋转角度(默认原点起点)

找到四元数并做矩阵变换

二、Viewing (观测) transformation

1.View(视图)/ Camera transformation

. Think about how to take a photo

  • Find a good place and arrange people ( m odel transformation)
    • Find a good “angle” to put the camera ( v iew transformation)
    • Cheese! ( p rojection transformation)
      模型-识别-投影变换(MVP变换)

首先定义相机的放置位置,朝向,角度(顶朝向)

原本相机可以在任意位置,但为了简化,可以将相机放在标准位置(0,0)。

先平移,再旋转
Translate e to origin
在这里插入图片描述
Rotate g to -Z, t to Y,(g x t) To x
反过来写,再求逆
Consider its inverse rotation: × to (g x t),Y to t,Z to -g

Summary

  • Transform objects together with the camera
  • Until camera’s at the origin, up at Y, look at -Z
    ModelView Transformation模型+视图变换

2.Projection (投影) transformation

eg

  • Orthographic (正交) projection
    不会带来近大远小的视觉误差
    (道理我都懂,但是鸽子为什么这莫大?)
    we want to map a cuboid [1,r]x [b, t]x [f,n] to the "canonical (正则、规范、标准)"cube [-1,1]3
    正则立方体

    先将x,y,z方向移动到以原点中心
    再将立方体正则化
    Translate (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)

  • FYl: that’s why OpenGL (a Graphics APl) 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

透视投影到别的平面上后,平行线会不平行。

Recall:
property of homogeneous coordinates

  • (x,y,z,1),(kx, ky,kz,k != O), (xz, yz,z2,z !=0)all represent the same point (x, y, z) in 3D
  • e.g.(1,0,0,1) and (2,0,0,2) both represent (1,0, 0)
    透视投影的平面大小会改变,而正交投影是一样的。

规定:
近平面永远不变。
在平面内向里收缩,远平面不变位置。
Frustum to Cuboid
相似三角形

ln order to find a transformation

  • Find the relationship between transformed points (x’,y’,z’)and the original points (x, y,z)
    In homogeneous coordinates

    继续推导得:

    Observation: the third row is responsible for z’
  • Any point on the near plane will not change
  • Any point’s z on the far plane will not change

Solve for A and B
An+B = 2→4A =n+ f
Af + B = f2
B=—n f
Finally, every entry in Mpersp->ortho is known!What’s next?

  • Do orthographic projection(Mortho) to finish-Mpersp = Mortho Mpersp→ortho