本文整理汇总了C++中PathFinding::findShortestPathByAstar方法的典型用法代码示例。如果您正苦于以下问题:C++ PathFinding::findShortestPathByAstar方法的具体用法?C++ PathFinding::findShortestPathByAstar怎么用?C++ PathFinding::findShortestPathByAstar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathFinding
的用法示例。
在下文中一共展示了PathFinding::findShortestPathByAstar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PathFind
void SmartAIController::PathFind(Engine::Actor & actor, D3DXVECTOR3 newGoal)
{
Engine::Vector3 nGoal= Engine::Vector3(newGoal.x, newGoal.y, newGoal.z);
Engine::Vector3 cGoal= Engine::Vector3(currentGoal.x, currentGoal.y, currentGoal.z);
if(positionToFollow.size()<=0 || (DistanceXYZ(nGoal, cGoal)>20.0f))
{
if( (DistanceXYZ(nGoal, cGoal)>20.0f))
currentGoal=newGoal;
//AI
PathFinding playerPath;
playerPath.SetLinks(Engine::WaypointsData::Manager().links);
playerPath.SetPoints(Engine::WaypointsData::Manager().points);
D3DXVECTOR3 currentPos= D3DXVECTOR3( actor.getActorPosition()->getx(), actor.getActorPosition()->gety(), actor.getActorPosition()->getz() );
positionToFollow=playerPath.findShortestPathByAstar(currentGoal,currentPos);
}
Engine::Vector3 closestPositionToFollow= Vector3(positionToFollow[0].x, positionToFollow[0].y, positionToFollow[0].z);
float distance=DistanceXZ(closestPositionToFollow, *actor.getActorPosition());
if(distance<30.0f)
{
positionToFollow.erase(positionToFollow.begin() + 0);
}
else
{
Vector3 follow;
follow.setx(positionToFollow[0].x - actor.getActorPosition()->getx());
follow.sety(positionToFollow[0].y - actor.getActorPosition()->gety());
follow.setz(positionToFollow[0].z - actor.getActorPosition()->getz());
follow=follow.Normalize();
D3DXVECTOR3 newFollow;
newFollow= D3DXVECTOR3(follow.getx()* 20 *speed, 0, follow.getz()* 20 *speed);
actor.TransLatePosition(newFollow);
}
}