9 float zMinimum = -projectionMatrix.r[3].m128_f32[2] / projectionMatrix.r[2].m128_f32[2];
10 float r = screenDepth / (screenDepth - zMinimum);
11 projectionMatrix.r[2].m128_f32[2] = r;
12 projectionMatrix.r[3].m128_f32[2] = -r * zMinimum;
15 matrix = XMMatrixMultiply(viewMatrix, projectionMatrix);
18 planes[0] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] + matrix.r[0].m128_f32[2],
19 matrix.r[1].m128_f32[3] + matrix.r[1].m128_f32[2],
20 matrix.r[2].m128_f32[3] + matrix.r[2].m128_f32[2],
21 matrix.r[3].m128_f32[3] + matrix.r[3].m128_f32[2]));
24 planes[1] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] - matrix.r[0].m128_f32[2],
25 matrix.r[1].m128_f32[3] - matrix.r[1].m128_f32[2],
26 matrix.r[2].m128_f32[3] - matrix.r[2].m128_f32[2],
27 matrix.r[3].m128_f32[3] - matrix.r[3].m128_f32[2]));
30 planes[2] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] + matrix.r[0].m128_f32[0],
31 matrix.r[1].m128_f32[3] + matrix.r[1].m128_f32[0],
32 matrix.r[2].m128_f32[3] + matrix.r[2].m128_f32[0],
33 matrix.r[3].m128_f32[3] + matrix.r[3].m128_f32[0]));
36 planes[3] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] - matrix.r[0].m128_f32[0],
37 matrix.r[1].m128_f32[3] - matrix.r[1].m128_f32[0],
38 matrix.r[2].m128_f32[3] - matrix.r[2].m128_f32[0],
39 matrix.r[3].m128_f32[3] - matrix.r[3].m128_f32[0]));
42 planes[4] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] - matrix.r[0].m128_f32[1],
43 matrix.r[1].m128_f32[3] - matrix.r[1].m128_f32[1],
44 matrix.r[2].m128_f32[3] - matrix.r[2].m128_f32[1],
45 matrix.r[3].m128_f32[3] - matrix.r[3].m128_f32[1]));
48 planes[5] = XMPlaneNormalize(XMVectorSet(matrix.r[0].m128_f32[3] + matrix.r[0].m128_f32[1],
49 matrix.r[1].m128_f32[3] + matrix.r[1].m128_f32[1],
50 matrix.r[2].m128_f32[3] + matrix.r[2].m128_f32[1],
51 matrix.r[3].m128_f32[3] + matrix.r[3].m128_f32[1]));
53 for (
int i = 0; i < 6; i++)
55 m_planes[i] = planes[i];
59bool frustum::CheckCube(
float xCenter,
float yCenter,
float zCenter,
float radius,
float tolerance)
62 for (
int i = 0; i < 6; i++)
64 XMVECTOR plane = m_planes[i];
65 if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
67 if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
69 if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
71 if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
73 if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
75 if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
77 if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
79 if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)