Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar) { // TODO: Copy-paste your implementation from the previous assignment.// 那我就复制了捏Q Eigen::Matrix4f projection = Eigen::Matrix4f::Identity(); Eigen::Matrix4f ortho;// 正交投影矩阵 Eigen::Matrix4f persp_to_ortho;// 透视投影转正交投影的矩阵 double fov = eye_fov / 180 * MY_PI;// 转化为弧度制 double n = -zNear, f = -zFar; double top = abs(n) * tan(fov / 2.0f); double bottom = -top; double right = aspect_ratio * top; double left = -right; Eigen::Matrix4f ortho_1;// 用于得到正交投影矩阵的被乘矩阵 Eigen::Matrix4f ortho_2;// 用于得到正交投影矩阵的乘矩阵 ortho_1 << 2 / (right - left), 0, 0, 0, 0, 2 / (top - bottom), 0, 0, 0, 0, 2 / (n - f), 0, 0, 0, 0, 1; ortho_2 << 1, 0, 0, -(right + left) / 2, 0, 1, 0, -(top + bottom) / 2, 0, 0, 1, -(n + f) / 2, 0, 0, 0, 1; ortho = ortho_1 * ortho_2; persp_to_ortho << n, 0, 0, 0, 0, n, 0, 0, 0, 0, n + f, -n * f, 0, 0, 1, 0; projection = ortho * persp_to_ortho; return projection; }
闫老师上课过程中所讲到的 zNear 和 zFar 是负数,而代码中的处理是正数。此时在写透视投影的过程中取 n = -zNear 和 f = -zFar,再把代码框架中定义的近平面和远平面(原始代码中仍为正数)改为负数,这样就可以得到正确的图像和覆盖关系。(三角形分开了是我 z-Buffer 写的有问题)
float f1 = -(50 - 0.1) / 2.0;// 近平面(这里我做下修改 改正负) float f2 = -(50 + 0.1) / 2.0;// 远平面(同上)
This post has received 1 vote up.Attachments:
You must be logged in to view attached files. -
AuthorPosts
Viewing 1 post (of 1 total)