Exemple #1
0
 public QuadtreeNode(float Size, Vector2 Position, QuadtreeNode Parent, int Depth)
 {
     this.Size     = Size;
     this.Position = Position;
     this.Parent   = Parent;
     this.Depth    = Depth;
     Boxes         = new LinkedList <AlignedBoundingBox>();
 }
Exemple #2
0
        public void Subdivide()
        {
            float newSize = this.Size / 2;

            child0 = new QuadtreeNode(newSize, this.Position + newSize / 2 * new Vector2(1, 1), this, Depth + 1);
            child1 = new QuadtreeNode(newSize, this.Position + newSize / 2 * new Vector2(-1, 1), this, Depth + 1);
            child2 = new QuadtreeNode(newSize, this.Position + newSize / 2 * new Vector2(-1, -1), this, Depth + 1);
            child3 = new QuadtreeNode(newSize, this.Position + newSize / 2 * new Vector2(1, -1), this, Depth + 1);
        }
Exemple #3
0
 private void drawAlg(QuadtreeNode current, Color color, SpriteBatch batch, Camera cam)
 {
     if (current[0] != null)
     {
         drawAlg(current[0], color, batch, cam);
         drawAlg(current[1], color, batch, cam);
         drawAlg(current[2], color, batch, cam);
         drawAlg(current[3], color, batch, cam);
     }
     else
     {
         current.Draw(color, batch, cam);
     }
 }
Exemple #4
0
        private void insert(AlignedBoundingBox newBounds, QuadtreeNode current)
        {
            newBounds.ContainerTree = this;
            if (current.isColliding(newBounds) && current.Depth < MaxDepth)
            {
                if (current[0] == null)
                {
                    current.Subdivide();
                }

                insert(newBounds, current[0]);
                insert(newBounds, current[1]);
                insert(newBounds, current[2]);
                insert(newBounds, current[3]);
            }
            else if (current.isColliding(newBounds))
            {
                current.InsertBounds(newBounds);
            }
        }
Exemple #5
0
 private void collisionSearch(AlignedBoundingBox searchBounds, QuadtreeNode current, ref LinkedList <AlignedBoundingBox> list)
 {
     if (current.isColliding(searchBounds) && current[0] != null)
     {
         collisionSearch(searchBounds, current[0], ref list);
         collisionSearch(searchBounds, current[1], ref list);
         collisionSearch(searchBounds, current[2], ref list);
         collisionSearch(searchBounds, current[3], ref list);
     }
     else if (current[0] == null)
     {
         if (current.Boxes.Count != 0)
         {
             foreach (AlignedBoundingBox b in current.Boxes)
             {
                 if (b.isColliding(searchBounds) && !list.Contains(b) && b != searchBounds)
                 {
                     list.AddFirst(b);
                 }
             }
         }
     }
 }
Exemple #6
0
 public Quadtree(Vector2 Position, float Size, int MaxDepth)
 {
     this.MaxDepth = MaxDepth;
     Root          = new QuadtreeNode(Size, Position, null, 1);
 }