示例#1
0
        public ContainmentType Contains(Frustum frustum)
        {
            //TODO: bad done here need a fix.
            //Because question is not frustum contain box but reverse and this is not the same
            int             i;
            ContainmentType contained;

            Vector3F[] 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);
        }
示例#2
0
        public ContainmentType Contains(Frustum frustum)
        {
            //check if all corner is in sphere
            bool inside = true;


            Vector3F[] corners = frustum.GetCorners();
            foreach (Vector3F 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);
        }
示例#3
0
 public static Sphere CreateFromFrustum(Frustum frustum)
 {
     return(Sphere.CreateFromPoints(frustum.GetCorners()));
 }