AstarQuery を使用してパスを計算したら、AstarQuery::GetPath() オブジェクトを呼び出して、Path オブジェクトとして取得できます。Path オブジェクトは、繰り返し使用することができる、ノードおよびエッジのコレクションです。
たとえば、次のコードは、クエリーによって計算されたパスを取得し、各フレームで異なる位置の矢印をビジュアル デバッグ システムに送信します。[Tutorial_FirstIntegration.cpp からのコード]
class MyGameLevel { public: ... void TestPath(Kaim::World* world); ... }; ... void MyGameLevel::TestPath(Kaim::World* world) { Kaim::ScopedDisplayList displayList(world, Kaim::DisplayList_Enable); displayList.InitSingleFrameLifespan("Test Path", "My Game"); if (m_astarQuery->m_processStatus == Kaim::QueryDone) { Kaim::AStarQueryResult result = m_astarQuery->GetResult(); if( result == Kaim::ASTAR_DONE_PATH_FOUND ) { Kaim::Path* resultPath = m_astarQuery->GetPath(); if( resultPath->GetEdgeCount() == 0 ) return; // Let's fake an object moving on this path // in a very basic way. static KyFloat32 ratio = 0.0f; ratio += 0.00005f; if( ratio > 1.0f ) ratio = 0.0f; KyFloat32 positionRatio = ratio * resultPath->GetEdgeCount(); KyUInt32 currentEdge = (KyUInt32)floorf(positionRatio); Kaim::Vec3f edgeStart = resultPath->GetNodePosition(currentEdge); Kaim::Vec3f edgeEnd = resultPath->GetNodePosition(currentEdge+1); Kaim::Vec3f objectPosition = edgeStart + (positionRatio-currentEdge)*(edgeEnd-edgeStart); Kaim::VisualShapeColor shapeColor; shapeColor.m_triangleColor = Kaim::VisualColor(255, 255, 0); shapeColor.m_lineColor = Kaim::VisualColor(175, 175, 0); displayList.PushArrow( objectPosition + Kaim::Vec3f(0.0f, 0.0f, 2.0f), objectPosition, 0.05f, shapeColor); } } }
Navigation Lab をゲームに接続すると、現在追従しているエッジの長さに比例して変化する速さで、始点からターゲット ポイントまで移動する黄色の矢印が表示されます。
もちろん、上記のコードは、独自の目的でゲーム コード内の AstarQuery によって生成されるパスにアクセスして使用する基本的な方法の 1です。ただし、このチュートリアルの次のフェーズでは、キャラクタがパスの計算と追従を簡単に実行できる、Gameware Navigation に組み込まれた高度なパス フォローイング システムについて説明します。