3D Engine/QuadTree.cpp
//Distribute objects in actual node to new childs
Distribute objects in actual node to new childs
Distribute objects in actual node to new childs
void QuadtreeNode::RedistributeChilds() 
{
	for (std::list<GameObject*>::iterator it = objectsInNode.begin(); it != objectsInNode.end();)
	{
		GameObject* go = *it;
		OBB b = go->GetAABB();
		AABB new_box(b.MinimalEnclosingAABB());
		bool intersects[4];
		for (int i = 0; i < 4; ++i)
			intersects[i] = childs[i]->box.Intersects(new_box);
		if (intersects[0] && intersects[1] && intersects[2] && intersects[3])
			++it; 
		else
		{
			it = objectsInNode.erase(it);
			for (int i = 0; i < 4; ++i)
				if (intersects[i]) childs[i]->Insert(go);
		}
	}
}
void QuadtreeNode :: RedistributeChilds ( ) { for ( std :: list < GameObject * > :: iterator it = objectsInNode . begin ( ) ; it != objectsInNode . end ( ) ; ) { GameObject * go = * it ; OBB b = go -> GetAABB ( ) ; AABB new_box ( b . MinimalEnclosingAABB ( ) ) ; bool intersects [ 4 ] ; for ( int i = 0 ; i < 4 ; ++ i ) intersects [ i ] = childs [ i ] -> box . Intersects ( new_box ) ; if ( intersects [ 0 ] && intersects [ 1 ] && intersects [ 2 ] && intersects [ 3 ] ) ++ it ; else { it = objectsInNode . erase ( it ) ; for ( int i = 0 ; i < 4 ; ++ i ) if ( intersects [ i ] ) childs [ i ] -> Insert ( go ) ; } } }
Distribute objects in actual node to new childs
Distribute objects in actual node to new childs
// Now redistribute ALL objects // Now distribute this new gameobject onto the childs // if it hits all childs, better to just keep it here