当前位置: 首页>>代码示例>>C++>>正文


C++ GraphNode::GetParentNode方法代码示例

本文整理汇总了C++中GraphNode::GetParentNode方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphNode::GetParentNode方法的具体用法?C++ GraphNode::GetParentNode怎么用?C++ GraphNode::GetParentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphNode的用法示例。


在下文中一共展示了GraphNode::GetParentNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GraphNode

std::list<Vect3f> CWayPointManager::GetPath(CWayPoint* startPos, CWayPoint* destPos)
{
	std::list<Vect3f> vecPath;

	GraphNodeList openList;
	GraphNodeList closeList;

	GraphNode* gn = new GraphNode();
	gn->SetWP(startPos);
	openList.PushBack(gn);

	GraphNode* endNode = new GraphNode();
	endNode->SetWP(destPos);
	
	while (!openList.IsEmpty())
	{
		GraphNode* current = openList.PopFront();
		
		if(endNode->CompareNode(current))
		{
			endNode->SetParentNode(current->GetParentNode());
			CHECKED_DELETE(current);
			break;
		}

		//Add To close List
		closeList.PushBack(current);

		//Iterate around brothers
		WayPointList& brothers = current->GetWP()->GetBrothers();
		WayPointListIt it = brothers.begin();
		WayPointListIt itEnd = brothers.end();

		for (; it != itEnd; ++it)
		{
			CWayPoint* wp = *it;

			//Set the cost of node_successor to be the cost of node_current plus
			//the cost to get to node_successor from node_current
			//Set h to be the estimated distance to node_goal (Using heuristic function)
			GraphNode* successor = new GraphNode();
			successor->SetWP(wp);
			successor->SetG(current->GetG() + (current->GetWP()->GetPosition().Distance(wp->GetPosition())));
			successor->SetH(wp->GetPosition().Distance(destPos->GetPosition()));

			//find node_successor on the OPEN list
			int32 ofound = openList.IndexOf(successor);

			//if node_successor is on the OPEN list but the existing one is as good
			//or better then discard this successor and continue
			if (ofound>=0)
			{
				GraphNode* temp = openList.At(ofound);
				
				if(temp->GetF() < current->GetF())
				{
					CHECKED_DELETE(successor);
					continue;
				}
			}

			//find node_successor on the CLOSED list
			int32 cFound = closeList.IndexOf(successor);

			//if node_successor is on the CLOSED list but the existing one is as good
			//or better then discard this successor and continue;
			if (cFound>=0)
			{
				GraphNode* temp = closeList.At(cFound);
				
				if(temp->GetF() < current->GetF())
				{
					CHECKED_DELETE(successor);
					continue;
				}
			}

			//Remove occurences of node_successor from OPEN and CLOSED
			if (ofound != -1)
			{
				openList.RemoveAt(ofound);
			}

			if (cFound!=-1)			
			{
				closeList.RemoveAt(cFound);
			}

			//Set the parent of node_successor to node_current;
			successor->SetParentNode(current);

			//Add node_successor to the OPEN list
			openList.PushBack(successor);
		}

		openList.Sort();
	}
	
	if(endNode->GetParentNode() == NULL)
	{
//.........这里部分代码省略.........
开发者ID:kusku,项目名称:red-forest,代码行数:101,代码来源:WayPointManager.cpp


注:本文中的GraphNode::GetParentNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。