Example #1
0
    public QuadTree3d Balance(QuadTree3d quad)
    {
        while (leaves.Count > 0)
        {
            QuadTree3d toBalance = leaves [0];

            QuadTree3d n1 = GetNodeContaining((toBalance.nodeCenter.x - toBalance.nodeSize), toBalance.nodeCenter.z);
            Debug.Log("BALANCING");
            //Debug.Log ("nodecenter" + nodeCenter);
            //Debug.Log ("nodeSize" + nodeSize);
            int neighbour1Depth = n1.currentDepth;
            Debug.Log("neighbor1 depth " + neighbour1Depth);
            while (toBalance.currentDepth > (neighbour1Depth + 1))
            {
                BalanceSplit(n1);
                neighbour1Depth++;
                Debug.Log("neighbor1 successful");
            }

            QuadTree3d n2 = GetNodeContaining((toBalance.nodeCenter.x + toBalance.nodeSize), toBalance.nodeCenter.z);
            Debug.Log("BALANCING");
            //Debug.Log ("nodecenter" + nodeCenter);
            //Debug.Log ("nodeSize" + nodeSize);
            int neighbour2Depth = n2.currentDepth;
            Debug.Log("neighbor2 depth " + neighbour2Depth);
            while (toBalance.currentDepth > (neighbour2Depth + 1))
            {
                BalanceSplit(n2);
                neighbour2Depth++;
                Debug.Log("neighbor2 successful");
            }

            QuadTree3d n3 = GetNodeContaining(toBalance.nodeCenter.x, (toBalance.nodeCenter.z - toBalance.nodeSize));
            Debug.Log("BALANCING");
            //Debug.Log ("nodecenter" + nodeCenter);
            //Debug.Log ("nodeSize" + nodeSize);
            int neighbour3Depth = n3.currentDepth;
            Debug.Log("neighbor3 depth " + neighbour3Depth);
            while (toBalance.currentDepth > (neighbour3Depth + 1))
            {
                BalanceSplit(n3);
                neighbour3Depth++;
                Debug.Log("neighbor3 successful");
            }

            QuadTree3d n4 = GetNodeContaining(toBalance.nodeCenter.x, (toBalance.nodeCenter.z + toBalance.nodeSize));
            Debug.Log("BALANCING");
            //Debug.Log ("nodecenter" + nodeCenter);
            //Debug.Log ("nodeSize" + nodeSize);
            int neighbour4Depth = n4.currentDepth;
            Debug.Log("neighbor4 depth " + neighbour4Depth);
            while (toBalance.currentDepth > (neighbour4Depth + 1))
            {
                BalanceSplit(n4);
                neighbour4Depth++;
                Debug.Log("neighbor4 successful");
            }


            quad.RemoveLeaf(leaves[0]);
            Debug.Log("LEAVES " + leaves.Count);
            //Debug.Log ("LEAF0 " + leaves[0].nodeCost);
            //Debug.Log ("LEAF1 " + leaves[1].nodeCenter);
        }
        return(quad);
    }