MCPcopy Create free account
hub / github.com/defold/defold / CreateFrustumFromMatrix

Function CreateFrustumFromMatrix

engine/dlib/src/dlib/intersection.cpp:40–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38// https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf
39
40void 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
65bool TestFrustumPoint(const Frustum& frustum, const dmVMath::Point3& pos)

Callers 2

TESTFunction · 0.85
DrawRenderListFunction · 0.85

Calls 2

NormalizePlaneFunction · 0.85
getRowMethod · 0.45

Tested by 1

TESTFunction · 0.68