Beispiel #1
0
        /// <summary>
        /// Test if a frustum is fully inside, outside, or just intersecting the sphere.
        /// </summary>
        /// <param name="box">The box for testing.</param>
        /// <param name="result">The containment type as an output parameter.</param>
        public ContainmentType Contains(BoundingFrustum frustum)
        {
            // Check if all corners are in sphere.
            bool inside = true;

            Vector3[] corners = frustum.GetCorners();
            foreach (Vector3 corner in corners)
            {
                if (this.Contains(corner) == ContainmentType.Disjoint)
                {
                    inside = false;
                    break;
                }
            }
            if (inside)
            {
                return(ContainmentType.Contains);
            }

            // Check if the distance from sphere center to frustrum face is less than radius.
            double dmin = 0;

            // TODO : calcul dmin

            if (dmin <= Radius * Radius)
            {
                return(ContainmentType.Intersects);
            }

            // Else disjoint
            return(ContainmentType.Disjoint);
        }
Beispiel #2
0
 /// <summary>
 /// Creates the smallest <see cref="BoundingSphere"/> that can contain a specified <see cref="BoundingFrustum"/>.
 /// </summary>
 /// <param name="frustum">The frustum to create the sphere from.</param>
 /// <returns>The new <see cref="BoundingSphere"/>.</returns>
 public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum)
 {
     return(CreateFromPoints(frustum.GetCorners()));
 }