Navigation Lab からの接続を許可するようにゲームを設定すると、独自のデータ、シェイプ、およびボリュームを Navigation Lab に送信できるようになります。Navigation Lab では、データは Gameware Navigation のネイティブなクラスによって送信されたデバッグ データと同じように表示されます。データは他のデータと同じように、記録、クリップへの保存、および再生ができます。
以下のコード サンプルは、単一フレームのライフスパンで表示リストを作成して送信し、各フレームで処理を繰り返します。ただし、表示リストにあまり変化しないデータが含まれている場合は、代わりにユーザ定義ライフスパンで表示リストを作成し、それを 1 回送信することもできます。そのデータは、変更または削除されるまで、各フレームで表示されます。この代替の詳細については、「ビジュアル デバッグ」を参照してください。
次のコード サンプルでは 3 つすべての方法が示されています。
これらの推奨事項を省略してもエラーは発生しませんが、実際には Navigation Lab に送信されない、内部オブジェクトの作成に関わる不要な計算が行われます。
[Tutorial_FirstIntegration.cpp からのコード]
#include "gwnavruntime/visualsystem/displaylist.h" ... void MyGameWorld::TestVisualDebugger() { // Visual debugging is disabled in Shipping builds. Even though the symbols and functions are available, they do nothing. // Guarding this code is not necessary, but is recommended in order to prevent useless computations. #ifndef KY_BUILD_SHIPPING Kaim::VisualDebugServer* visualDebugServer = m_world->GetVisualDebugServer(); // always check the state of the VisualDebugServer // to avoid costly construction of messages for nothing if (visualDebugServer->IsConnected() == false) return; const char* myCategoryName = "MyGame"; // Sends a message to the Log window of the Navigation Lab static KyUInt32 framecount = 0; KY_LOG_MESSAGE(("FrameCount: %d", framecount)); framecount++; // Sends a single data value KyUInt32 someKindOfInformation = 1256; visualDebugServer->SendUInt32("SomeKindOfInformation", someKindOfInformation, myCategoryName); // Sends current, average, max, and min stats computed by the game const char* someKindOfStat = "SomeKindOfStat"; KyFloat32 currentValue = 2.56f; KyFloat32 averageValue = 2.56f; KyFloat32 maxValue = 3.026f; KyFloat32 minValue = 0.21f; visualDebugServer->SendStats(someKindOfStat, currentValue, averageValue, maxValue, minValue, myCategoryName); // Visual information is sent using a display list Kaim::Vec3f boxLowerCornerPosition = Kaim::Vec3f(-5.0f, -5.0f, 0.0f); Kaim::Vec3f boxExtents = Kaim::Vec3f(3.0f, 2.0f, 1.0f); Kaim::Vec3f positionA = Kaim::Vec3f(0.0f, 2.0f, 0.0f); Kaim::Vec3f positionB = Kaim::Vec3f(10.0f, 10.0f, 0.0f); KyFloat32 radius = 0.4f; KyFloat32 height = 2.0f; // The Gameware Navigation coordinate system is Z-up, right-handed, // in meters. Always convert positions, vectors and sizes from the coordinate // system you use in your game. You can set up a Kaim::CoordSystem object, and use // its methods to do the conversions for you, as shown below. boxLowerCornerPosition = m_coordSystem.ClientToNavigation_Pos( boxLowerCornerPosition ); boxExtents = m_coordSystem.ClientToNavigation_Pos( boxExtents ); positionA = m_coordSystem.ClientToNavigation_Pos( positionA ); positionB = m_coordSystem.ClientToNavigation_Pos( positionB ); radius = m_coordSystem.ClientToNavigation_Dist( radius ); height = m_coordSystem.ClientToNavigation_Dist( height ); { // Create a display list and send a line Kaim::ScopedDisplayList displayList(m_world, Kaim::DisplayList_Enable); displayList.InitSingleFrameLifespan("Simple Display List", myCategoryName); displayList.PushLine(positionB, positionB + Kaim::Vec3f::UnitZ(), Kaim::VisualColor::White); // The ScopedDisplayList is automatically sent to the Navigation Lab // when it goes out of scope. } { // Create a second display list and send more shapes Kaim::ScopedDisplayList displayList(m_world, Kaim::DisplayList_Enable); displayList.InitSingleFrameLifespan("Complex Display List", myCategoryName); Kaim::VisualShapeColor shapeColor; shapeColor.m_triangleColor = Kaim::VisualColor(255, 255, 0); shapeColor.m_lineColor = Kaim::VisualColor(175, 175, 0); displayList.PushVerticalCylinder( positionA, radius, height, 10, shapeColor); displayList.PushLine( positionA, positionB, Kaim::VisualColor::Red); shapeColor.m_triangleColor = Kaim::VisualColor(0, 255, 0, 128); shapeColor.m_lineColor = Kaim::VisualColor(0, 128, 0, 255); Kaim::Box3f someBox(boxLowerCornerPosition, boxLowerCornerPosition + boxExtents); displayList.PushBox(someBox, shapeColor); displayList.PushText( positionB + Kaim::Vec3f::UnitZ(), Kaim::VisualColor(0, 255, 255), "Some text"); // Again, the ScopedDisplayList is automatically sent to the Navigation Lab // when it goes out of scope. } #endif }
Navigation Lab をゲームに接続すると、次のものが表示されるようになります。
また、表示リストで送信されるデータを、Visual debug パネルで表示および非表示にすることができます。表示リストに対して指定したカテゴリ名が、パネル下部の Display lists 見出しの下に表示されます。このカテゴリを展開すると、個々の表示リストを表示または非表示にすることができます。