1#include "frustumclass.h"
4FrustumClass::FrustumClass()
14FrustumClass::~FrustumClass()
18void FrustumClass::ConstructFrustum(XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
float screenDepth)
21 XMFLOAT4X4 projMatrix, matrix;
25 XMStoreFloat4x4(&projMatrix, projectionMatrix);
28 zMinimum = -projMatrix._43 / projMatrix._33;
29 r = screenDepth / (screenDepth - zMinimum);
31 projMatrix._43 = -r * zMinimum;
34 projectionMatrix = XMLoadFloat4x4(&projMatrix);
37 finalMatrix = XMMatrixMultiply(viewMatrix, projectionMatrix);
40 XMStoreFloat4x4(&matrix, finalMatrix);
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;
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));
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;
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));
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;
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));
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;
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));
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;
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));
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;
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));
123bool FrustumClass::CheckPoint(
float x,
float y,
float z)
129 for (i = 0; i < 6; i++)
131 if (((m_planes[i].x * x) + (m_planes[i].y * y) + (m_planes[i].z * z) + m_planes[i].w) < 0.0f)
140bool FrustumClass::CheckCube(
float xCenter,
float yCenter,
float zCenter,
float radius)
146 for (i = 0; i < 6; i++)
148 if (m_planes[i].x * (xCenter - radius) +
149 m_planes[i].y * (yCenter - radius) +
150 m_planes[i].z * (zCenter - radius) + m_planes[i].w >= 0.0f)
155 if (m_planes[i].x * (xCenter + radius) +
156 m_planes[i].y * (yCenter - radius) +
157 m_planes[i].z * (zCenter - radius) + m_planes[i].w >= 0.0f)
162 if (m_planes[i].x * (xCenter - radius) +
163 m_planes[i].y * (yCenter + radius) +
164 m_planes[i].z * (zCenter - radius) + m_planes[i].w >= 0.0f)
169 if (m_planes[i].x * (xCenter + radius) +
170 m_planes[i].y * (yCenter + radius) +
171 m_planes[i].z * (zCenter - radius) + m_planes[i].w >= 0.0f)
176 if (m_planes[i].x * (xCenter - radius) +
177 m_planes[i].y * (yCenter - radius) +
178 m_planes[i].z * (zCenter + radius) + m_planes[i].w >= 0.0f)
183 if (m_planes[i].x * (xCenter + radius) +
184 m_planes[i].y * (yCenter - radius) +
185 m_planes[i].z * (zCenter + radius) + m_planes[i].w >= 0.0f)
190 if (m_planes[i].x * (xCenter - radius) +
191 m_planes[i].y * (yCenter + radius) +
192 m_planes[i].z * (zCenter + radius) + m_planes[i].w >= 0.0f)
197 if (m_planes[i].x * (xCenter + radius) +
198 m_planes[i].y * (yCenter + radius) +
199 m_planes[i].z * (zCenter + radius) + m_planes[i].w >= 0.0f)
210bool FrustumClass::CheckSphere(
float xCenter,
float yCenter,
float zCenter,
float radius)
216 for (i = 0; i < 6; i++)
218 if (((m_planes[i].x * xCenter) + (m_planes[i].y * yCenter) + (m_planes[i].z * zCenter) + m_planes[i].w) < -radius)
227bool FrustumClass::CheckRectangle(
float xCenter,
float yCenter,
float zCenter,
float xSize,
float ySize,
float zSize)
233 for (i = 0; i < 6; i++)
235 if (m_planes[i].x * (xCenter - xSize) +
236 m_planes[i].y * (yCenter - ySize) +
237 m_planes[i].z * (zCenter - zSize) + m_planes[i].w >= 0.0f)
242 if (m_planes[i].x * (xCenter + xSize) +
243 m_planes[i].y * (yCenter - ySize) +
244 m_planes[i].z * (zCenter - zSize) + m_planes[i].w >= 0.0f)
249 if (m_planes[i].x * (xCenter - xSize) +
250 m_planes[i].y * (yCenter + ySize) +
251 m_planes[i].z * (zCenter - zSize) + m_planes[i].w >= 0.0f)
256 if (m_planes[i].x * (xCenter - xSize) +
257 m_planes[i].y * (yCenter - ySize) +
258 m_planes[i].z * (zCenter + zSize) + m_planes[i].w >= 0.0f)
263 if (m_planes[i].x * (xCenter + xSize) +
264 m_planes[i].y * (yCenter + ySize) +
265 m_planes[i].z * (zCenter - zSize) + m_planes[i].w >= 0.0f)
270 if (m_planes[i].x * (xCenter + xSize) +
271 m_planes[i].y * (yCenter - ySize) +
272 m_planes[i].z * (zCenter + zSize) + m_planes[i].w >= 0.0f)
277 if (m_planes[i].x * (xCenter - xSize) +
278 m_planes[i].y * (yCenter + ySize) +
279 m_planes[i].z * (zCenter + zSize) + m_planes[i].w >= 0.0f)
284 if (m_planes[i].x * (xCenter + xSize) +
285 m_planes[i].y * (yCenter + ySize) +
286 m_planes[i].z * (zCenter + zSize) + m_planes[i].w >= 0.0f)