完成作业2时我的结果是下图(和原作业要求不符合)
查看了一下投影矩阵,发现传入的znear和zfar是正数,我感觉自己是不是在这里错了,下面是我的投影矩阵代码
//cout << eye_fov << ” ” << zNear << ” ” << zFar << endl;
// // // Students will implement this function
zNear = -zNear;
zFar = -zFar;
Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();
Eigen::Matrix4f M_persp2ortho;
M_persp2ortho << zNear, 0, 0, 0,
0, zNear, 0, 0,
0, 0, zNear+zFar, -zNear*zFar,
0, 0, 1, 0;
eye_fov = eye_fov * M_PI / 180;
float t = tan(eye_fov/2.0) * abs(zNear), b = -t;
float r = aspect_ratio * t, l = -r;
Eigen::Matrix4f M_ortho1;
M_ortho1 << 2.0/(r-l), 0, 0, 0,
0, 2.0/(t-b), 0, 0,
0, 0, 2.0/(zNear-zFar), 0,
0, 0, 0, 1.0;
Eigen::Matrix4f M_ortho2;
M_ortho2 << 1.0, 0, 0, -(r+l)/2,
0, 1, 0, -(t+b)/2,
0, 0, 1, -(zNear+zFar)/2,
0, 0, 0, 1.0;
Eigen::Matrix4f M_ortho = M_ortho1 * M_ortho2;
projection = M_ortho * M_persp2ortho;
// TODO: Implement this function
// Create the projection matrix for the given parameters.
// Then return it.
return projection;
Attachments:
You must be
logged in to view attached files.