void BinaryTreeVisibleNodeCounter::GetVisibleNodes(Node *tree, Node *parent)
{
	if (tree != nullptr)
	{
		if (IsVisible(tree, parent))
		{
			visibleNodes_.insert(tree);
		}
		GetVisibleNodes(tree->Left, tree);
		GetVisibleNodes(tree->Right, tree);
	}
}
std::unordered_set<Node *> BinaryTreeVisibleNodeCounter::GetVisibleNodes(Node *tree)
{
	maxAncesterValue_.clear();
	visibleNodes_.clear();

	if (tree != nullptr)
	{
		if (IsVisible(tree, nullptr))
		{
			visibleNodes_.insert(tree);
		}
		GetVisibleNodes(tree->Left, tree);
		GetVisibleNodes(tree->Right, tree);
	}

	return visibleNodes_;
}
void QTPFSPathDrawer::GetVisibleNodes(const QTPFS::QTNode* nt, std::list<const QTPFS::QTNode*>& nodes) const {
	if (nt->IsLeaf()) {
		nodes.push_back(nt);
	} else {
		for (unsigned int i = 0; i < nt->children.size(); i++) {
			const QTPFS::QTNode* n = nt->children[i];
			const float3 mins = float3(n->xmin() * SQUARE_SIZE, 0.0f, n->zmin() * SQUARE_SIZE);
			const float3 maxs = float3(n->xmax() * SQUARE_SIZE, 0.0f, n->zmax() * SQUARE_SIZE);

			if (!camera->InView(mins, maxs))
				continue;

			GetVisibleNodes(nt->children[i], nodes);
		}
	}
}
void QTPFSPathDrawer::DrawNodeTree(const MoveDef* md) const {
	QTPFS::QTNode* nt = pm->nodeTrees[md->pathType];
	CVertexArray* va = GetVertexArray();

	std::list<const QTPFS::QTNode*> nodes;
	std::list<const QTPFS::QTNode*>::const_iterator nodesIt;

	GetVisibleNodes(nt, nodes);

	va->Initialize();
	va->EnlargeArrays(nodes.size() * 4, 0, VA_SIZE_C);

	for (nodesIt = nodes.begin(); nodesIt != nodes.end(); ++nodesIt) {
		DrawNode(*nodesIt, md, va, false, true, true);
	}

	glLineWidth(2);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	va->DrawArrayC(GL_QUADS);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glLineWidth(1);
}