Beispiel #1
0
 bool OctreeNode::addObject(MapObject& object) {
     if (!m_bounds.contains(object.bounds()))
         return false;
     if (m_bounds.max[0] - m_bounds.min[0] > m_minSize)
         for (unsigned int i = 0; i < 8; i++)
             if (addObject(object, i))
                 return true;
     m_objects.push_back(&object);
     return true;
 }
Beispiel #2
0
        bool OctreeNode::removeObject(MapObject& object) {
            if (!m_bounds.contains(object.bounds()))
                return false;
            for (unsigned int i = 0; i < 8; i++) {
                if (m_children[i] != NULL && m_children[i]->removeObject(object)) {
                    if (m_children[i]->empty()) {
                        delete m_children[i];
                        m_children[i] = NULL;
                    }
                    return true;
                }
            }

            MapObjectList::iterator it = find(m_objects.begin(), m_objects.end(), &object);
            if (it == m_objects.end())
                return false;

            m_objects.erase(it);
            return true;
        }