Beispiel #1
0
        public ContainmentType Contains(BoundingFrustum frustum)
        {
            //check if all corner is 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 < radius
            double dmin = 0;

            //TODO : calcul dmin

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

            //else disjoint
            return(ContainmentType.Disjoint);
        }
Beispiel #2
0
        public ContainmentType Contains(BoundingFrustum frustum)
        {
            //TODO: bad done here need a fix.
            //Because question is not frustum contain box but reverse and this is not the same
            Int32           i;
            ContainmentType contained;

            Vector3[] corners = frustum.GetCorners();

            // First we check if frustum is in box
            for (i = 0; i < corners.Length; i++)
            {
                this.Contains(ref corners[i], out contained);
                if (contained == ContainmentType.Disjoint)
                {
                    break;
                }
            }

            if (i == corners.Length) // This means we checked all the corners and they were all contain or instersect
            {
                return(ContainmentType.Contains);
            }

            if (i != 0)             // if i is not equal to zero, we can fastpath and say that this box intersects
            {
                return(ContainmentType.Intersects);
            }


            // If we get here, it means the first (and only) point we checked was actually contained in the frustum.
            // So we assume that all other points will also be contained. If one of the points is disjoint, we can
            // exit immediately saying that the result is Intersects
            i++;
            for (; i < corners.Length; i++)
            {
                this.Contains(ref corners[i], out contained);
                if (contained != ContainmentType.Contains)
                {
                    return(ContainmentType.Intersects);
                }
            }

            // If we get here, then we know all the points were actually contained, therefore result is Contains
            return(ContainmentType.Contains);
        }
Beispiel #3
0
 public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum)
 {
     return(BoundingSphere.CreateFromPoints(frustum.GetCorners()));
 }