Exemplo n.º 1
0
    public void Grow(Vector2 direction)
    {
        QuadTreeNode tempRoot = null;
        if (direction == new Vector2(1, 1))
        {
            tempRoot = new QuadTreeNode(this, null, Root.AAR.Position + new Vector2(Root.AAR.Size.x / 2, Root.AAR.Size.y / 2), (Root.AAR.Size.x + Root.AAR.Size.y) / 2, Root.MinSize, 0);
            tempRoot.MeshObject.Children[0] = Root.MeshObject;
        }
        if (direction == new Vector2(-1, -1))
        {
            tempRoot = new QuadTreeNode(this, null, Root.AAR.Position + new Vector2(-Root.AAR.Size.x / 2, -Root.AAR.Size.y / 2), (Root.AAR.Size.x + Root.AAR.Size.y) / 2, Root.MinSize, 0);
            tempRoot.MeshObject.Children[2] = Root.MeshObject;
        }
        if (direction == new Vector2(1, -1))
        {
            tempRoot = new QuadTreeNode(this, null, Root.AAR.Position + new Vector2(Root.AAR.Size.x / 2, -Root.AAR.Size.y / 2), (Root.AAR.Size.x + Root.AAR.Size.y) / 2, Root.MinSize, 0);
            tempRoot.MeshObject.Children[1] = Root.MeshObject;
        }
        if (direction == new Vector2(-1, 1))
        {
            tempRoot = new QuadTreeNode(this, null, Root.AAR.Position + new Vector2(-Root.AAR.Size.x / 2, Root.AAR.Size.y / 2), (Root.AAR.Size.x + Root.AAR.Size.y) / 2, Root.MinSize, 0);
            tempRoot.MeshObject.Children[3] = Root.MeshObject;
        }

        Root.DestroyGameObject();
        Root = tempRoot;
        Root.ApplyValues();
    }