Пример #1
0
        public bool Intersects(AxisAlignedBox box)
        {
            foreach (Plane plane in FrustumHelper.GetPlanes(this))
            {
                if ((plane.Normal.X * box.Min.X) + (plane.Normal.Y * box.Min.Y) + (plane.Normal.Z * box.Min.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Max.X) + (plane.Normal.Y * box.Min.Y) + (plane.Normal.Z * box.Min.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Max.X) + (plane.Normal.Y * box.Min.Y) + (plane.Normal.Z * box.Max.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Min.X) + (plane.Normal.Y * box.Min.Y) + (plane.Normal.Z * box.Max.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Min.X) + (plane.Normal.Y * box.Max.Y) + (plane.Normal.Z * box.Min.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Max.X) + (plane.Normal.Y * box.Max.Y) + (plane.Normal.Z * box.Min.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Max.X) + (plane.Normal.Y * box.Max.Y) + (plane.Normal.Z * box.Max.Z) + plane.D > 0)
                {
                    continue;
                }

                if ((plane.Normal.X * box.Min.X) + (plane.Normal.Y * box.Max.Y) + (plane.Normal.Z * box.Max.Z) + plane.D > 0)
                {
                    continue;
                }

                // all points are behind the one plane so they can't be inside any other plane
                return(false);
            }

            return(true);
        }
Пример #2
0
        public bool Intersects(IEnumerable <Vector3F> polygon)
        {
            foreach (Plane plane in FrustumHelper.GetPlanes(this))
            {
                bool gotOne = false;
                foreach (Vector3F vert in polygon)
                {
                    if ((plane.Normal.X * vert.X) + (plane.Normal.Y * vert.Y) + (plane.Normal.Z * vert.Z) + plane.D > 0)
                    {
                        gotOne = true;
                        break;
                    }
                }
                if (gotOne)
                {
                    continue;
                }

                // all points are behind the one plane so they can't be inside any other plane
                return(false);
            }
            return(true);
        }