Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业一、二中投影矩阵问题

Viewing 3 reply threads
  • Author
    Posts
    • #4653 Score: 0
      Spencor
      Participant

      各位同学:
      针对投影矩阵, 推导的过程如下:n:near, f :far
      根据以下三个矩阵按顺序相乘,得到最终结果的投影矩阵为:
      { n/r, 0,0, 0

      0, n/t,0,0,

      0,0,(n+f)/(f-n), 2*n*f/(n-f),

      0,0,0,1}

      但以上推导的投影矩阵和以下所写的代码,结果好像存在点问题。弧度转换问题已考虑,请哪位同学帮忙解答一下?

      Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar)
      {
      // TODO: Use the same projection matrix from the previous assignments

      float n = zNear > 0 ? zNear : – ZNear;
      float t = tan(eye_fov / (2 * n));
      float r = aspect_ratio * n;

      Eigen::Matrix4f pers;
      pers << n/r, 0, 0, 0,
      0, n/t , 0, 0,
      0, 0, (zNear + zFar)/(zFar – zNear),2* zNear * zFar/(zNear – zFar),
      0, 0, 0, 1;

      return pers;

      }

      一、 透视矩阵
      [n , 0, 0, 0

      0 ,n, 0, 0

      0 ,0 ,-(n+f), n*f
      0, 0, 0, 1 ]

      二、 平移矩阵

      因为l= -r;b=-t;化简为:

      [1,0,0,0

      0,1,0,0,

      0,0,1,-(n+f)/2

      0,0,0,1]

      三、正交矩阵
      [1/r ,0 , 0,0

      0, 1/t, 0, 0

      0, 0, 2/(n-f), 0,

      0,0,0,1]

    • #4660 Score: 0
      Shi YuChen(助教)
      Keymaster
      4 pts

      float t=tan(eye_fov(弧度)/2)*n;
      float r=aspect_ratio*t;

    • #8187 Score: 0
      半片橘子
      Participant

      透视矩阵写错了!应该是:
      [n , 0, 0, 0
      0 ,n, 0, 0
      0 ,0 ,-(n+f), n*f
      0, 0, 0, 1 ]

      所以最终矩阵应该是:
      n/r, 0, 0, 0,
      0, n/t , 0, 0,
      0, 0, 1,-2* zNear * zFar/(zNear – zFar),
      0, 0, 1, 0;

      以上是我自己算的,其实到底是不是对的我也没有准确把握,如果有错,希望能够指出

    • #8188 Score: 0
      半片橘子
      Participant

      n/r, 0, 0, 0,
      0, n/t , 0, 0,
      0, 0, (zNear + zFar)/(zNear – zFar),-2* zNear * zFar/(zNear – zFar),
      0, 0, 1, 0;

Viewing 3 reply threads
  • You must be logged in to reply to this topic.