15 #ifndef INCLUDED_ATOMSMATHFRUSTUMTEST_H
16 #define INCLUDED_ATOMSMATHFRUSTUMTEST_H
18 #include <AtomsMath/ImathBox.h>
19 #include <AtomsMath/ImathFrustum.h>
20 #include <AtomsMath/ImathMatrix.h>
21 #include <AtomsMath/ImathNamespace.h>
22 #include <AtomsMath/ImathSphere.h>
23 #include <AtomsMath/ImathVec.h>
25 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
139 ATOMSMATH_INTERNAL_NAMESPACE::Matrix44<T>
cameraMat() const noexcept {
return cameraMatrix; }
142 ATOMSMATH_INTERNAL_NAMESPACE::Frustum<T>
currentFrustum() const noexcept {
return currFrustum; }
176 frustum.planes (frustumPlanes, cameraMat);
180 for (
int i = 0; i < 2; ++i)
184 planeNormX[i] =
Vec3<T> (frustumPlanes[index + 0].normal.x,
185 frustumPlanes[index + 1].
normal.x,
186 frustumPlanes[index + 2].
normal.x);
187 planeNormY[i] =
Vec3<T> (frustumPlanes[index + 0].normal.y,
188 frustumPlanes[index + 1].
normal.y,
189 frustumPlanes[index + 2].
normal.y);
190 planeNormZ[i] =
Vec3<T> (frustumPlanes[index + 0].normal.z,
191 frustumPlanes[index + 1].
normal.z,
192 frustumPlanes[index + 2].
normal.z);
194 planeNormAbsX[i] =
Vec3<T> (std::abs (planeNormX[i].x),
195 std::abs (planeNormX[i].y),
196 std::abs (planeNormX[i].z));
197 planeNormAbsY[i] =
Vec3<T> (std::abs (planeNormY[i].x),
198 std::abs (planeNormY[i].y),
199 std::abs (planeNormY[i].z));
200 planeNormAbsZ[i] =
Vec3<T> (std::abs (planeNormZ[i].x),
201 std::abs (planeNormZ[i].y),
202 std::abs (planeNormZ[i].z));
204 planeOffsetVec[i] =
Vec3<T> (frustumPlanes[index + 0].distance,
205 frustumPlanes[index + 1].distance,
206 frustumPlanes[index + 2].distance);
208 currFrustum = frustum;
209 cameraMatrix = cameraMat;
212 template <
typename T>
216 Vec3<T> center = sphere.center;
217 Vec3<T> radiusVec =
Vec3<T> (sphere.radius, sphere.radius, sphere.radius);
220 Vec3<T> d0 = planeNormX[0] * center.x + planeNormY[0] * center.y + planeNormZ[0] * center.z -
221 radiusVec - planeOffsetVec[0];
223 if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0)
226 Vec3<T> d1 = planeNormX[1] * center.x + planeNormY[1] * center.y + planeNormZ[1] * center.z -
227 radiusVec - planeOffsetVec[1];
229 if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0)
235 template <
typename T>
239 Vec3<T> center = sphere.center;
240 Vec3<T> radiusVec =
Vec3<T> (sphere.radius, sphere.radius, sphere.radius);
243 Vec3<T> d0 = planeNormX[0] * center.x + planeNormY[0] * center.y + planeNormZ[0] * center.z +
244 radiusVec - planeOffsetVec[0];
246 if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0)
249 Vec3<T> d1 = planeNormX[1] * center.x + planeNormY[1] * center.y + planeNormZ[1] * center.z +
250 radiusVec - planeOffsetVec[1];
252 if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0)
258 template <
typename T>
265 Vec3<T> center = (box.min + box.max) / 2;
266 Vec3<T> extent = (box.max - center);
269 Vec3<T> d0 = planeNormX[0] * center.x + planeNormY[0] * center.y + planeNormZ[0] * center.z -
270 planeNormAbsX[0] * extent.x - planeNormAbsY[0] * extent.y -
271 planeNormAbsZ[0] * extent.z - planeOffsetVec[0];
273 if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0)
276 Vec3<T> d1 = planeNormX[1] * center.x + planeNormY[1] * center.y + planeNormZ[1] * center.z -
277 planeNormAbsX[1] * extent.x - planeNormAbsY[1] * extent.y -
278 planeNormAbsZ[1] * extent.z - planeOffsetVec[1];
280 if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0)
286 template <
typename T>
293 Vec3<T> center = (box.min + box.max) / 2;
294 Vec3<T> extent = (box.max - center);
297 Vec3<T> d0 = planeNormX[0] * center.x + planeNormY[0] * center.y + planeNormZ[0] * center.z +
298 planeNormAbsX[0] * extent.x + planeNormAbsY[0] * extent.y +
299 planeNormAbsZ[0] * extent.z - planeOffsetVec[0];
301 if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0)
304 Vec3<T> d1 = planeNormX[1] * center.x + planeNormY[1] * center.y + planeNormZ[1] * center.z +
305 planeNormAbsX[1] * extent.x + planeNormAbsY[1] * extent.y +
306 planeNormAbsZ[1] * extent.z - planeOffsetVec[1];
308 if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0)
314 template <
typename T>
319 Vec3<T> d0 = (planeNormX[0] * vec.x) + (planeNormY[0] * vec.y) + (planeNormZ[0] * vec.z) -
322 if (d0.x >= 0 || d0.y >= 0 || d0.z >= 0)
325 Vec3<T> d1 = (planeNormX[1] * vec.x) + (planeNormY[1] * vec.y) + (planeNormZ[1] * vec.z) -
328 if (d1.x >= 0 || d1.y >= 0 || d1.z >= 0)
340 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImathBox.h:36
Definition: ImathFrustum.h:38
Definition: ImathFrustumTest.h:84
ATOMSMATH_INTERNAL_NAMESPACE::Frustum< T > currentFrustum() const noexcept
Return the viewing frustum (primarily for debugging)
Definition: ImathFrustumTest.h:142
bool completelyContains(const Sphere3< T > &sphere) const noexcept
Definition: ImathFrustumTest.h:237
void setFrustum(const Frustum< T > &frustum, const Matrix44< T > &cameraMat) noexcept
Definition: ImathFrustumTest.h:173
bool isVisible(const Sphere3< T > &sphere) const noexcept
Definition: ImathFrustumTest.h:214
ATOMSMATH_INTERNAL_NAMESPACE::Matrix44< T > cameraMat() const noexcept
Return the camera matrix (primarily for debugging)
Definition: ImathFrustumTest.h:139
FrustumTest(const Frustum< T > &frustum, const Matrix44< T > &cameraMat) noexcept
Initialize to a given frustum and camera matrix.
Definition: ImathFrustumTest.h:99
FrustumTest() noexcept
Initialize camera matrix to identity.
Definition: ImathFrustumTest.h:90
Definition: ImathMatrix.h:631
Definition: ImathPlane.h:30
Vec3< T > normal
The normal to the plane.
Definition: ImathPlane.h:37
Definition: ImathSphere.h:25
Definition: ImathVec.h:260