本文整理汇总了C++中GraphNode::setDistanceFromStart方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphNode::setDistanceFromStart方法的具体用法?C++ GraphNode::setDistanceFromStart怎么用?C++ GraphNode::setDistanceFromStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphNode
的用法示例。
在下文中一共展示了GraphNode::setDistanceFromStart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeDistanceFromStart
/** Recursively determines the distance the beginning (lower end) of the quads
* have from the start of the track.
* \param node The node index for which to set the distance from start.
* \param new_distance The new distance for the specified graph node.
*/
void QuadGraph::computeDistanceFromStart(unsigned int node, float new_distance)
{
GraphNode *gn = m_all_nodes[node];
float current_distance = gn->getDistanceFromStart();
// If this node already has a distance defined, check if the new distance
// is longer, and if so adjust all following nodes. Without this the
// length of the track (as taken by the distance from start of the last
// node) could be smaller than some of the paths. This can result in
// incorrect results for the arrival time estimation of the AI karts.
// See trac #354 for details.
// Then there is no need to test/adjust any more nodes.
if(current_distance>=0)
{
if(current_distance<new_distance)
{
float delta = new_distance - current_distance;
updateDistancesForAllSuccessors(gn->getQuadIndex(), delta, 0);
}
return;
}
// Otherwise this node has no distance defined yet. Set the new
// distance, and recursively update all following nodes.
gn->setDistanceFromStart(new_distance);
for(unsigned int i=0; i<gn->getNumberOfSuccessors(); i++)
{
GraphNode *gn_next = m_all_nodes[gn->getSuccessor(i)];
// The start node (only node with distance 0) is reached again,
// recursion can stop now
if(gn_next->getDistanceFromStart()==0)
continue;
computeDistanceFromStart(gn_next->getQuadIndex(),
new_distance + gn->getDistanceToSuccessor(i));
} // for i
} // computeDistanceFromStart