Esempio n. 1
0
void Octree::UpdateObject(CollisionMesh& object)
{
    Partition* partition = object.GetPartition();
    Partition* newPartition = nullptr;
    assert(partition);

    if(!IsAllInsidePartition(object, *partition))
    {
        // Move upwards until object is fully inside a single partition
        Partition* parent = partition->GetParent();
        while(parent && !IsAllInsidePartition(object, *parent))
        {
            parent = parent->GetParent();
        }

        // Will be in found partition or one of the children
        newPartition = FindPartition(object, parent ? *parent : *m_octree);
    }
    else
    {
        // Can only be in partition and partition's children
        newPartition = FindPartition(object, *partition);
    }

    assert(newPartition);
    if(newPartition != partition)
    {
        // connect object and new partition together
        partition->RemoveNode(object);
        newPartition->AddNode(object);
        object.SetPartition(newPartition);
    }
}
Esempio n. 2
0
void Octree::IterateUpOctree(CollisionMesh& node, Partition& partition)
{
    auto& nodes = partition.GetNodes();
    for(unsigned int i = 0; i < nodes.size(); ++i)
    {
        m_iteratorFn(*nodes[i], node);
    }

    if(partition.GetParent())
    {
        IterateUpOctree(node, *partition.GetParent());
    }
}