Beispiel #1
0
        /// <summary>
        ///     Splits a quadtree into quadrants.
        /// </summary>
        public void Split()
        {
            if (CurrentDepth + 1 >= MaxDepth)
            {
                return;
            }

            var min    = NodeBounds.TopLeft;
            var max    = NodeBounds.BottomRight;
            var center = NodeBounds.Center;

            RectangleF[] childAreas =
            {
                RectangleF.CreateFrom(min,                 center),
                RectangleF.CreateFrom(new Point2(center.X, min.Y),   new Point2(max.X,     center.Y)),
                RectangleF.CreateFrom(center,              max),
                RectangleF.CreateFrom(new Point2(min.X,    center.Y),new Point2(center.X,  max.Y))
            };

            for (var i = 0; i < childAreas.Length; ++i)
            {
                var node = new Quadtree(childAreas[i]);
                Children.Add(node);
                Children[i].CurrentDepth = CurrentDepth + 1;
            }

            foreach (QuadtreeData contentQuadtree in Contents)
            {
                foreach (Quadtree childQuadtree in Children)
                {
                    childQuadtree.Insert(contentQuadtree);
                }
            }
            Clear();
        }
        /// <summary>
        ///     Splits a quadtree into quadrants.
        /// </summary>
        public void Split()
        {
            if (CurrentDepth + 1 >= MaxDepth)
            {
                return;
            }

            var min    = NodeBounds.TopLeft;
            var max    = NodeBounds.BottomRight;
            var center = NodeBounds.Center;

            RectangleF[] childAreas =
            {
                RectangleF.CreateFrom(min,                 center),
                RectangleF.CreateFrom(new PointF(center.X, min.Y),   new PointF(max.X,     center.Y)),
                RectangleF.CreateFrom(center,              max),
                RectangleF.CreateFrom(new PointF(min.X,    center.Y),new PointF(center.X,  max.Y))
            };

            for (var i = 0; i < childAreas.Length; ++i)
            {
                var node = new Quadtree(childAreas[i]);
                Children.Add(node);
                Children[i].CurrentDepth = CurrentDepth + 1;
            }

            for (int i = 0, size = Contents.Count; i < size; ++i)
            {
                for (int j = 0; j < Children.Count; j++)
                {
                    Children[j].Insert(Contents[i]);
                }
            }

            Contents.Clear();
        }
 public void AddParent(Quadtree parent)
 {
     Parents.Add(parent);
 }
 public void RemoveParent(Quadtree parent)
 {
     Parents.Remove(parent);
 }
Beispiel #5
0
 /// <summary>
 /// Creates a collision tree covering the specified area.
 /// </summary>
 /// <param name="boundary">Boundary of the collision tree.</param>
 public CollisionComponent(RectangleF boundary)
 {
     _collisionTree = new Quadtree(boundary);
 }