OctreeNode.GetChild C# (CSharp) Method

GetChild() protected method

protected GetChild ( float x, float y, float z ) : OctreeNode,
x float
y float
z float
return OctreeNode,
    protected internal OctreeNode GetChild(float x, float y, float z)
    {
        return Bounds.PointWithinBounds(x, y, z)
                   ? (Branch != null
                          ? (from t in Branch where t.Bounds.PointWithinBounds(x, y, z) select t.GetChild(x, y, z)).
                                FirstOrDefault()
                          : this)
                   : null;
    }

Usage Example

    // Returns whether the node is changed.
    private bool AddInternal(IntVector3 coords, T obj, OctreeNode <T> node, int level, IntVector3 corner)
    {
        if (node.isFilled)
        {
            return(false);
        }
        else if (level == 0)
        {
            node.obj      = obj;
            node.objCount = 1;
            return(true);
        }

        int        childSize  = 1 << (level - 1);
        IntVector3 childIndex = (coords - corner) / childSize;
        var        childNode  = node.GetChild(childIndex);

        if (childNode == null)
        {
            childNode = node.CreateChild(childIndex);
        }

        long oldChildObjCount = childNode.objCount;
        bool changed          = AddInternal(coords, obj, childNode, level - 1, corner + childIndex * childSize);

        if (changed)
        {
            node.objCount += childNode.objCount - oldChildObjCount;
            if (childNode.isFilled)
            {
                node.MergeIfPossible(obj);
            }
        }
        return(changed);
    }
All Usage Examples Of OctreeNode::GetChild