public static bool IsInOrIntersectFrustum(ref BoundingFrustum frustum, ref BoundingBox box, ref BoundingSphere sphere) { for (int i = 0; i < 6; i++) { var plane = frustum.GetPlane(i); var sphereRet = plane.Intersects(ref sphere); if (sphereRet == PlaneIntersectionType.Back) { return(false); } else if (sphereRet == PlaneIntersectionType.Intersecting) { return(true); } GetBoxToPlanePVertexNVertex(ref box, ref plane.Normal, out Vector3 p, out Vector3 n); var boxRet = Collision.PlaneIntersectsPoint(ref plane, ref p); if (boxRet == PlaneIntersectionType.Back) { return(false); } else if (boxRet == PlaneIntersectionType.Intersecting) { return(true); } } return(true); }
/// <summary> /// Containment test between this <see cref="BoundingFrustum"/> and specified <see cref="BoundingFrustum"/>. /// </summary> /// <param name="instance">Instance</param> /// <param name="frustum">A <see cref="BoundingFrustum"/> for testing.</param> /// <returns>Result of testing for containment between this <see cref="BoundingFrustum"/> and specified <see cref="BoundingFrustum"/>.</returns> public static ContainmentType FrustumContainsFrustum(this BoundingFrustum instance, BoundingFrustum frustum) { if (instance == frustum) { return(ContainmentType.Contains); } var intersects = false; for (var i = 0; i < 6; ++i) { var plane = instance.GetPlane(i); frustum.Intersects(ref plane, out PlaneIntersectionType planeIntersectionType); if (planeIntersectionType == PlaneIntersectionType.Back) { return(ContainmentType.Disjoint); } else if (planeIntersectionType == PlaneIntersectionType.Intersecting) { intersects = true; break; } } return(intersects ? ContainmentType.Intersects : ContainmentType.Contains); }
public static bool Intersects(ref BoundingFrustum frustum, ref BoundingBox box) { for (int i = 0; i < 6; i++) { var plane = frustum.GetPlane(i); GetBoxToPlanePVertexNVertex(ref box, ref plane.Normal, out Vector3 p, out Vector3 n); if (Collision.PlaneIntersectsPoint(ref plane, ref p) == PlaneIntersectionType.Back) { return(false); } } return(true); }
public static bool Intersects(ref BoundingFrustum frustum, ref BoundingSphere sphere) { for (int i = 0; i < 6; i++) { var plane = frustum.GetPlane(i); var result = plane.Intersects(ref sphere); if (result == PlaneIntersectionType.Back) { return(false); } else if (result == PlaneIntersectionType.Intersecting) { return(true); } } return(true); }