19{
20 XMMATRIX finalMatrix;
21 XMFLOAT4X4 projMatrix, matrix;
22 float zMinimum, r, t;
23
24
25 XMStoreFloat4x4(&projMatrix, projectionMatrix);
26
27
28 zMinimum = -projMatrix._43 / projMatrix._33;
29 r = screenDepth / (screenDepth - zMinimum);
30 projMatrix._33 = r;
31 projMatrix._43 = -r * zMinimum;
32
33
34 projectionMatrix = XMLoadFloat4x4(&projMatrix);
35
36
37 finalMatrix = XMMatrixMultiply(viewMatrix, projectionMatrix);
38
39
40 XMStoreFloat4x4(&matrix, finalMatrix);
41
42
43 m_planes[0].x = matrix._13;
44 m_planes[0].y = matrix._23;
45 m_planes[0].z = matrix._33;
46 m_planes[0].w = matrix._43;
47
48
49 t = (float)sqrt((m_planes[0].x * m_planes[0].x) + (m_planes[0].y * m_planes[0].y) + (m_planes[0].z * m_planes[0].z));
50 m_planes[0].x /= t;
51 m_planes[0].y /= t;
52 m_planes[0].z /= t;
53 m_planes[0].w /= t;
54
55
56 m_planes[1].x = matrix._14 - matrix._13;
57 m_planes[1].y = matrix._24 - matrix._23;
58 m_planes[1].z = matrix._34 - matrix._33;
59 m_planes[1].w = matrix._44 - matrix._43;
60
61
62 t = (float)sqrt((m_planes[1].x * m_planes[1].x) + (m_planes[1].y * m_planes[1].y) + (m_planes[1].z * m_planes[1].z));
63 m_planes[1].x /= t;
64 m_planes[1].y /= t;
65 m_planes[1].z /= t;
66 m_planes[1].w /= t;
67
68
69 m_planes[2].x = matrix._14 + matrix._11;
70 m_planes[2].y = matrix._24 + matrix._21;
71 m_planes[2].z = matrix._34 + matrix._31;
72 m_planes[2].w = matrix._44 + matrix._41;
73
74
75 t = (float)sqrt((m_planes[2].x * m_planes[2].x) + (m_planes[2].y * m_planes[2].y) + (m_planes[2].z * m_planes[2].z));
76 m_planes[2].x /= t;
77 m_planes[2].y /= t;
78 m_planes[2].z /= t;
79 m_planes[2].w /= t;
80
81
82 m_planes[3].x = matrix._14 - matrix._11;
83 m_planes[3].y = matrix._24 - matrix._21;
84 m_planes[3].z = matrix._34 - matrix._31;
85 m_planes[3].w = matrix._44 - matrix._41;
86
87
88 t = (float)sqrt((m_planes[3].x * m_planes[3].x) + (m_planes[3].y * m_planes[3].y) + (m_planes[3].z * m_planes[3].z));
89 m_planes[3].x /= t;
90 m_planes[3].y /= t;
91 m_planes[3].z /= t;
92 m_planes[3].w /= t;
93
94
95 m_planes[4].x = matrix._14 - matrix._12;
96 m_planes[4].y = matrix._24 - matrix._22;
97 m_planes[4].z = matrix._34 - matrix._32;
98 m_planes[4].w = matrix._44 - matrix._42;
99
100
101 t = (float)sqrt((m_planes[4].x * m_planes[4].x) + (m_planes[4].y * m_planes[4].y) + (m_planes[4].z * m_planes[4].z));
102 m_planes[4].x /= t;
103 m_planes[4].y /= t;
104 m_planes[4].z /= t;
105 m_planes[4].w /= t;
106
107
108 m_planes[5].x = matrix._14 + matrix._12;
109 m_planes[5].y = matrix._24 + matrix._22;
110 m_planes[5].z = matrix._34 + matrix._32;
111 m_planes[5].w = matrix._44 + matrix._42;
112
113
114 t = (float)sqrt((m_planes[5].x * m_planes[5].x) + (m_planes[5].y * m_planes[5].y) + (m_planes[5].z * m_planes[5].z));
115 m_planes[5].x /= t;
116 m_planes[5].y /= t;
117 m_planes[5].z /= t;
118 m_planes[5].w /= t;
119
120 return;
121}