1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar) { Eigen::Matrix4f projection; Eigen::Matrix4f orthotrans1; Eigen::Matrix4f orthotrans2; Eigen::Matrix4f persptrans; float f, n, l, r, b, t, fov; n = -zNear; f = -zFar; t = tan(eye_fov / 2) * abs(n); b = -t; r = t * aspect_ratio; l = -r; persptrans << n, 0, 0, 0, 0, n, 0, 0, 0, 0, n + f, -n * f, 0, 0, 1, 0; orthotrans1 << 2 / (r - l), 0, 0, 0, 0, 2 / (t - b), 0, 0, 0, 0, 2 / (n - f), 0, 0, 0, 0, 1; orthotrans2 << 1, 0, 0, -(r + l) / 2, 0, 1, 0, -(t + b) / 2, 0, 0, 1, -(n + f) / 2, 0, 0, 0, 1; projection = orthotrans1 * orthotrans2 * persptrans; return projection; }
|