Ejemplo n.º 1
0
    public HxOctreeNode <T> .NodeObject Add(T value, Vector3 boundsMin, Vector3 boundsMax)
    {
        int counter = 0;

        while (!HxOctreeNode <T> .BoundsContains(Root.BoundsMin, Root.BoundsMax, boundsMin, boundsMax))
        {
            ExpandRoot((boundsMin + boundsMax) / 2f);
            if (++counter > 16)
            {
                Debug.LogError("The octree could not contain the bounds.");
                return(null);
            }
        }

        var node = new HxOctreeNode <T> .NodeObject(value, boundsMin, boundsMax);

        NodeMap[value] = node;
        Root.Add(node);
        Count++;
        return(node);
    }
Ejemplo n.º 2
0
    public void Move(HxOctreeNode <T> .NodeObject value, Vector3 boundsMin, Vector3 boundsMax)
    {
        if (value == null)
        {
            Debug.Log("null");
        }
        value.BoundsMin = boundsMin;
        value.BoundsMax = boundsMax;
        var currentNode = value.Node;

        if (!HxOctreeNode <T> .BoundsContains(currentNode.BoundsMin, currentNode.BoundsMax, boundsMin, boundsMax))
        {
            currentNode.Remove(value.Value);
            int counter = 0;
            while (!HxOctreeNode <T> .BoundsContains(currentNode.BoundsMin, currentNode.BoundsMax, boundsMin, boundsMax))
            {
                if (currentNode.Parent != null)
                {
                    currentNode = currentNode.Parent;
                }
                else // current node is the root, expand it
                {
                    counter++;
                    ExpandRoot((boundsMin + boundsMax) / 2f);
                    currentNode = Root;
                    if (counter > 16)
                    {
                        Debug.LogError("The octree could not contain the bounds.");
                        return;
                    }
                }
            }
            currentNode.Add(value);
        }
        //   Root = Root.TryShrink(InitialSize);
    }