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


C++ PathNode::getLinks方法代码示例

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


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

示例1: resetStartNode

void Follower::resetStartNode()
{
	mStartNode->setPosition(mPosition);
	//find closest existing node and use the same links as it has
	PathNode* close;
	gCurrentLevel->getPaths()->getNodeNearPosition(close, mPosition);
	mStartNode->setLinks(close->getLinks());
}
开发者ID:brentspector,项目名称:Dart,代码行数:8,代码来源:Player.cpp

示例2: clock

vector<D3DXVECTOR3> AStar::findPath(PathNode* _start, PathNode* _end)
{
	//time it for debugging
	clock_t clockStart = clock();
	//empty the closed set vector
	vector<PathNode*>().swap(mClosedSet);
	//empty the open set and put in only the start node
	vector<PathNode*>().swap(mOpenSet);
	mOpenSet.push_back(_start);
	//set all node gScores to max
	for (PathNode* PN : mPathNodes)
		PN->setGScore(INT_MAX);
	//set start node properties
	_start->setGScore(0);
	_start->setFScore(findHeuristic(_start, _end));
	//while the open set is not empty
	while (mOpenSet.size() > 0)
	{
		//the node in open set having the lowest f score
		PathNode* current;
		findLowestFScore(current);
		//if we found the goal, return the path
		if (current == _end || ((clock() - clockStart) / (float)CLOCKS_PER_SEC) > MAX_PATH_TIME_LOW)
		{
			vector<D3DXVECTOR3> rePath;
			reconstructPath(rePath, _start, current);
			return rePath;
		}
		//save current to closed set
		mClosedSet.push_back(current);
		//remove current from open set
		for (vector<PathNode*>::iterator iter = mOpenSet.begin(); iter != mOpenSet.end(); ++iter)
		{
			if (*iter == current)
			{
				mOpenSet.erase(iter);
				break;
			}
		}
		//for each linked node in the current node
		for (PathNode* PN : current->getLinks())
		{
			//if it is already in the closed set, continue
			if (inClosedSet(PN))
				continue;
			//find tentative gScore
			int tempGScore = current->getGScore() + findHeuristic(current, _end);
			//if link node is not in open set or tempGScore < present GScore
			if (!inOpenSet(PN) || tempGScore < PN->getGScore())
			{
				//set the came from of the link to the current node
				PN->setCameFrom(current);
				//set g score
				PN->setGScore(tempGScore);
				PN->setFScore(PN->getGScore() + findHeuristic(PN, _end));
				//if link is not in open set, add to it
				if (!inOpenSet(PN))
					mOpenSet.push_back(PN);
			}
		}
	}
	//finished loop without finding goal
	OutputDebugString(L"ERROR: No path found.");
	return vector<D3DXVECTOR3>();

}
开发者ID:brentspector,项目名称:Dart,代码行数:66,代码来源:PathNode.cpp


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