src/public/octree.h
void Insert(OctObjectType* Object)
    {
        BoxF pBox = Object->GetBox();

        // Have children? Try to put it in one of them
        if (nodes.Num() > 0)
        {
            int index = GetIndex(pBox);

            if (index != -1)
            {
                nodes[index]->Insert(Object);
                return;
            }
        }

        // Put it in me
        objects.Add(Object);

        // Full? split and try to distribute objects into children
        if (objects.Num() > MAX_OBJECTS && level < MAX_LEVELS)
        {
            if (nodes.Num() == 0)
            {
                Split();
            }

            unsigned int i = 0;
            while (i < objects.Num())
            {
                int index = GetIndex(objects[i]->GetBox());

                if (index != -1)
                {
                    nodes[index]->Insert(objects[i]);
                    objects.RemoveAtSwap(i);
                }
                else
                {
                    i++;
                }
            }
        }
    }
// Add an object to the tree
Add an object to the tree
Add an object to the tree
void Insert(OctObjectType* Object)
    {
        BoxF pBox = Object->GetBox();
        if (nodes.Num() > 0)
        {
            int index = GetIndex(pBox);
            if (index != -1)
            {
                nodes[index]->Insert(Object);
                return;
            }
        }
        objects.Add(Object);
        if (objects.Num() > MAX_OBJECTS && level < MAX_LEVELS)
        {
            if (nodes.Num() == 0)
            {
                Split();
            }
            unsigned int i = 0;
            while (i < objects.Num())
            {
                int index = GetIndex(objects[i]->GetBox());
                if (index != -1)
                {
                    nodes[index]->Insert(objects[i]);
                    objects.RemoveAtSwap(i);
                }
                else
                {
                    i++;
                }
            }
        }
    }
void Insert ( OctObjectType * Object ) { BoxF pBox = Object -> GetBox ( ) ; if ( nodes . Num ( ) > 0 ) { int index = GetIndex ( pBox ) ; if ( index != -1 ) { nodes [ index ] -> Insert ( Object ) ; return ; } } objects . Add ( Object ) ; if ( objects . Num ( ) > MAX_OBJECTS && level < MAX_LEVELS ) { if ( nodes . Num ( ) == 0 ) { Split ( ) ; } unsigned int i = 0 ; while ( i < objects . Num ( ) ) { int index = GetIndex ( objects [ i ] -> GetBox ( ) ) ; if ( index != -1 ) { nodes [ index ] -> Insert ( objects [ i ] ) ; objects . RemoveAtSwap ( i ) ; } else { i ++ ; } } } }
Add an object to the tree
Add an object to the tree
// Have children? Try to put it in one of them // Put it in me // Full? split and try to distribute objects into children