| 38 | // https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf |
| 39 | |
| 40 | void CreateFrustumFromMatrix(const dmVMath::Matrix4& m, bool normalize, int num_planes, Frustum& frustum) |
| 41 | { |
| 42 | dmVMath::Vector4 x = m.getRow(0); |
| 43 | dmVMath::Vector4 y = m.getRow(1); |
| 44 | dmVMath::Vector4 z = m.getRow(2); |
| 45 | dmVMath::Vector4 w = m.getRow(3); |
| 46 | |
| 47 | frustum.m_NumPlanes = num_planes; |
| 48 | frustum.m_Planes[0] = w + x; // left |
| 49 | frustum.m_Planes[1] = w - x; // right |
| 50 | frustum.m_Planes[2] = w + y; // bottom |
| 51 | frustum.m_Planes[3] = w - y; // top |
| 52 | frustum.m_Planes[4] = w + z; // near |
| 53 | frustum.m_Planes[5] = w - z; // far |
| 54 | |
| 55 | if (normalize) |
| 56 | { |
| 57 | for (int i = 0; i < frustum.m_NumPlanes; ++i) |
| 58 | { |
| 59 | frustum.m_Planes[i] = NormalizePlane(frustum.m_Planes[i]); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | bool TestFrustumPoint(const Frustum& frustum, const dmVMath::Point3& pos) |