Ejemplo n.º 1
0
 public Quadtree(Rect rect, int maxElementsPerNode, int maxTotalElements)
 {
     this.root        = this;
     this.Rect        = rect;
     this.elements    = new T[maxElementsPerNode];
     this.numElements = 0;
     this.freeSpace   = maxTotalElements;
 }
Ejemplo n.º 2
0
        virtual protected void SpawnChildNodes()
        {
            float halfWidth  = rect.width * 0.5f;
            float halfHeight = rect.height * 0.5f;

            a = new Quadtree <T>(root, new Rect(rect.xMin, center.y, halfWidth, halfHeight), elements.Length);
            b = new Quadtree <T>(root, new Rect(center.x, center.y, halfWidth, halfHeight), elements.Length);
            c = new Quadtree <T>(root, new Rect(rect.xMin, rect.yMin, halfWidth, halfHeight), elements.Length);
            d = new Quadtree <T>(root, new Rect(center.x, rect.yMin, halfWidth, halfHeight), elements.Length);
        }
Ejemplo n.º 3
0
        virtual public void Destroy()
        {
            elements = null;

            if (a != null)
            {
                a.Destroy();
                b.Destroy();
                c.Destroy();
                d.Destroy();
                a = b = c = d = null;
            }
        }
Ejemplo n.º 4
0
        public void UpdateElements(Quadtree <T> root)
        {
            if (a != null)
            {
                a.UpdateElements(root);
                b.UpdateElements(root);
                c.UpdateElements(root);
                d.UpdateElements(root);
            }

            if (elements != null)
            {
                for (int i = 0; i < elements.Length; ++i)
                {
                    var element = elements[i];

                    if (element != null && !marginRect.Contains(element.Position))
                    {
                        RemoveElementAt(i);
                        root.AddElement(element);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private Quadtree(Quadtree <T> root, Rect rect, int maxElementsPerNode) : this(rect, maxElementsPerNode, 0)
 {
     this.root = root;
 }