Exemplo n.º 1
0
    protected OctreeEntry <T> SetChild(int index, T node)
    {
        if (children[index] != null)
        {
            // The entry already exists
            children[index].entry = node;

            return(children[index]);
        }

        OctreeEntry <T> fish = treeBase.entryPool.Catch();

        // Find the new child min
        int xMinimum, yMinimum, zMinimum;

        MinOfChildIndex(index, out xMinimum, out yMinimum, out zMinimum);

        // change the min from local to world space
        float xWorldMinimum = xMinimum * treeBase.leafDimensions.x;
        float yWorldMinimum = yMinimum * treeBase.leafDimensions.y;
        float zWorldMinimum = zMinimum * treeBase.leafDimensions.z;

        // change the min from local to world space
        float xWorldMaximum = xWorldMinimum + treeBase.leafDimensions.x;
        float yWorldMaximum = yWorldMinimum + treeBase.leafDimensions.y;
        float zWorldMaximum = zWorldMinimum + treeBase.leafDimensions.z;

        // Initialize the new node with world space bounds
        fish.Initialize(node, xMinimum, yMinimum, zMinimum, new Vector3(xWorldMinimum, yWorldMinimum, zWorldMinimum), new Vector3(xWorldMaximum, yWorldMaximum, zWorldMaximum));

        // Set index to the child
        children[(int)index] = fish;
        // Increase the child counter
        ++childCount;
        // Set the OctryEnty's value to what was passed
        children[(int)index].entry = node;

        return(children[(int)index]);
    }
Exemplo n.º 2
0
    private void CreateEntryAtIndex(int index)
    {
        if (children[index] != null)
        {
            return;
        }

        OctreeEntry <T> fish = treeBase.entryPool.Catch();
        // Find the new child min
        int xMinimum, yMinimum, zMinimum;

        MinOfChildIndex(index, out xMinimum, out yMinimum, out zMinimum);
        // change the min from local to world space
        float minX = xMinimum * treeBase.leafDimensions.x;
        float minY = yMinimum * treeBase.leafDimensions.y;
        float minZ = zMinimum * treeBase.leafDimensions.z;

        // Initialize the new node with world space bounds
        fish.Initialize(default(T), xMinimum, yMinimum, zMinimum, new Vector3(minX, minY, minZ), new Vector3(minX + treeBase.leafDimensions.x, minY + treeBase.leafDimensions.y, minZ + treeBase.leafDimensions.z));
        // Set index to the child
        children[(int)index] = fish;
    }