正交投影矩阵

正交投影

正交投影是将世界空间的物体,映射到一个单位立方体上,然后缩放为单位立方体

// 平移
(left + right)/2 得到平移后的中心点位置,其他面类似
A = 
  1 0 0 -(left + right)/2
  0 1 0 -(top + bottom)/2
  0 0 1 -(far + near)/2
  0 0 0 1

// 缩放
将平移后的立方体缩放为单位立方体(-1,1),2/r-l,使用右手坐标系,z方向为负,-2(f-n)

B = 
  2/(right - left) 0 0 0
  0 2/(top - bottom) 0 0
  0 0 -2(far - near) 0 0
  0 0 0 1

// 相乘
C = B * A

// 最后结果
C = 
 2/(right - left) 0 0 0
 0 2/(top - bottom) 0  0 
 0 0 2/(near-far)   0
 (left+right)/(left-right)  (bottom+top)/(bottom-top)   (near+far)/(near-far)    1   

var m4 = {
  orthographic: function(left, right, bottom, top, near, far) {
    return [
      2 / (right - left), 0, 0, 0,
      0, 2 / (top - bottom), 0, 0,
      0, 0, 2 / (near - far), 0,
 
      (left + right) / (left - right),
      (bottom + top) / (bottom - top),
      (near + far) / (near - far),
      1,
    ];
  }
posted @ 2020-11-09 19:20  pluscat  阅读(1290)  评论(0编辑  收藏  举报