各位同学:
针对投影矩阵, 推导的过程如下: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]