@brief Takes in points at the near clipping plane, as well as the near and far clipping planes. Result matrix maps [l, r] and [b, t] to [-1, 1], and [n, f] to [-1, 1] (should be configurable) Resulting matrix operates on Eigen::Vector4d, which are row-matrices - transpose if you want it to work on column matrices. @todo Look into using Eigen::Projective3d?
| 46 | /// |
| 47 | /// @todo Look into using Eigen::Projective3d? |
| 48 | inline Eigen::Matrix4d createProjectionMatrix(Rectd const &bounds, |
| 49 | double near, double far) { |
| 50 | // Convert from "left, right, bottom top, near, far" to the 4x4 |
| 51 | // transform. |
| 52 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml |
| 53 | // BEGIN APPARENTLY OUTDATED NOTE - works more accurately if you ignore |
| 54 | // that. |
| 55 | // NOTE: There is actually a bug in the documentation. If you |
| 56 | // call glFrustum() and print out the results and compare them, |
| 57 | // the value D from that page holds -1 and the value where there |
| 58 | // is a -1 is what holds D. This error is also copied to the |
| 59 | // Microsoft page describing this function. These are elements |
| 60 | // [2][3] and [3][2], which are swapped. |
| 61 | // END APPARENTLY OUTDATED NOTE |
| 62 | auto const right = bounds[Rectd::RIGHT]; |
| 63 | auto const left = bounds[Rectd::LEFT]; |
| 64 | auto const top = bounds[Rectd::TOP]; |
| 65 | auto const bottom = bounds[Rectd::BOTTOM]; |
| 66 | |
| 67 | Eigen::Matrix4d mat; |
| 68 | // clang-format off |
| 69 | mat << (2 * near / (right - left)), 0, ((right + left) / (right - left)), 0, |
| 70 | 0, (2 * near / (top - bottom)), ((top + bottom) / (top - bottom)), 0, |
| 71 | 0, 0, (-(far + near) / (far - near)), (-2 * far * near / (far - near)), |
| 72 | 0, 0, -1, 0; |
| 73 | // clang-format on |
| 74 | return mat; |
| 75 | } |
| 76 | |
| 77 | namespace projection_options { |
| 78 |
no outgoing calls
no test coverage detected