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


C++ PathFinding::SetLinks方法代码示例

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


在下文中一共展示了PathFinding::SetLinks方法的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);
	}
}
开发者ID:aaraddhyanb,项目名称:GreenLagoon,代码行数:42,代码来源:SmartAIController.cpp


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