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 29
| Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar) {
Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();
Eigen::Matrix4f persp2ortho = Eigen::Matrix4f::Identity(); Eigen::Matrix4f ortho = Eigen::Matrix4f::Identity();
float top = abs(zNear) * tan(eye_fov / 2 / 180 * MY_PI); float bottom = -top; float right = top * aspect_ratio; float left = -right;
persp2ortho << zNear, 0, 0, 0, 0, zNear, 0, 0, 0, 0, zNear + zFar, -zNear * zFar, 0, 0, 1, 0;
ortho << 2 / (right - left), 0, 0, -(right + left) / (right - left), 0, 2 / (top - bottom), 0, -(top + bottom) / (top - bottom), 0, 0, 2 / (zNear - zFar), -(zNear + zFar) / (zNear - zFar), 0, 0, 0, 1;
projection = ortho * persp2ortho * projection; return projection; }
|