/// <summary>
        /// Generates 8 sub bounding octrees inside the boudning node.
        /// </summary>
        public void CreateOctree()
        {
            Vector3 size   = this.Box.GetSize();
            Vector3 half   = size / 2.0f;
            Vector3 center = this.Box.Min + half;

            //Divide boundings into 8 child regions
            BoundingNode[] octrees = new BoundingNode[8];
            octrees[0]    = new BoundingNode(Box.Min, center);
            octrees[1]    = new BoundingNode(new Vector3(center.X, Box.Min.Y, Box.Min.Z), new Vector3(Box.Max.X, center.Y, center.Z));
            octrees[2]    = new BoundingNode(new Vector3(center.X, Box.Min.Y, center.Z), new Vector3(Box.Max.X, center.Y, Box.Max.Z));
            octrees[3]    = new BoundingNode(new Vector3(Box.Min.X, Box.Min.Y, center.Z), new Vector3(center.X, center.Y, Box.Max.Z));
            octrees[4]    = new BoundingNode(new Vector3(Box.Min.X, center.Y, Box.Min.Z), new Vector3(center.X, Box.Max.Y, center.Z));
            octrees[5]    = new BoundingNode(new Vector3(center.X, center.Y, Box.Min.Z), new Vector3(Box.Max.X, Box.Max.Y, center.Z));
            octrees[6]    = new BoundingNode(center, Box.Max);
            octrees[7]    = new BoundingNode(new Vector3(Box.Min.X, center.Y, center.Z), new Vector3(center.X, Box.Max.Y, Box.Max.Z));
            this.Children = octrees.ToList();
        }
        /// <summary>
        /// Determines if the given bounding node is within the current camera Frustum.
        /// </summary>
        public static bool CheckIntersection(Camera camera, BoundingNode bounding)
        {
            if (Planes == null)
            {
                UpdateCamera(camera);
            }

            //Check sphere detection
            var sphereFrustum = ContainsSphere(Planes,
                                               bounding.GetCenter(),
                                               bounding.GetRadius());

            switch (sphereFrustum)
            {
            case Frustum.FULL:
                return(true);

            case Frustum.NONE:     //Check the box anyways atm to be sure
            case Frustum.PARTIAL:  //Do bounding box detection
                var boxFrustum = ContainsBox(Planes, bounding.Box);
                if (boxFrustum != Frustum.NONE)
                {
                    return(true);
                }
                else
                {
                    break;
                }
            }

            foreach (var child in bounding.Children)
            {
                bool hasIntersection = CheckIntersection(camera, child);
                if (hasIntersection)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
 /// <summary>
 /// Checks if a bounding node is within the camera fustrum.
 /// </summary>
 public bool InFustrum(BoundingNode boundingNode)
 {
     return(CameraFrustum.CheckIntersection(this, boundingNode));
 }