gwnavruntime/queries/blobs/astarquerydisplaylistbuilder.h Source File

astarquerydisplaylistbuilder.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 // Primary contact: MAMU - secondary contact: NOBODY
8 #ifndef Navigation_AStarQuery_DisplayListBuilder_H
9 #define Navigation_AStarQuery_DisplayListBuilder_H
10 
17 
18 namespace Kaim
19 {
20 
21 class AStarQueryDisplayListBuilder : public IDisplayListBuilder
22 {
23 public:
24  static void BuildVerticalForbiddenWallLogo(ScopedDisplayList* displayList,
25  const Vec3f& A, const Vec3f& B, const Vec3f& C, const Vec3f& /*D*/, const Vec2f& AtoBDir2d)
26  {
27  const KyFloat32 segmentRadius = 0.1f;
28  const Vec3f center = (A+C) * 0.5;
29  KyFloat32 altDiff = (C.z-A.z);
30  const KyFloat32 length = DotProduct(B.Get2d() - A.Get2d(), AtoBDir2d);
31 
32  KyFloat32 radius = 0.6f * Min(altDiff, length) * 0.5f ;
33  const Vec3f frontPlane(AtoBDir2d.PerpCCW());
34 
35  {
36  VisualShapeColor whiteshapeColor;
37  whiteshapeColor.m_triangleColor = VisualColor::White;
38  const Vec3f frontOffset = frontPlane *segmentRadius;
39  Vec3f corner1 = center - radius*0.75f * AtoBDir2d - radius*0.25f * Vec3f::UnitZ() + frontOffset;
40  Vec3f corner2 = center + radius*0.75f * AtoBDir2d - radius*0.25f * Vec3f::UnitZ() + frontOffset;
41  Vec3f corner3 = center + radius*0.75f * AtoBDir2d + radius*0.25f * Vec3f::UnitZ() + frontOffset;
42  Vec3f corner4 = center - radius*0.75f * AtoBDir2d + radius*0.25f * Vec3f::UnitZ() + frontOffset;
43  displayList->PushQuad(corner1, corner2, corner3, corner4, whiteshapeColor);
44  }
45  {
46  VisualShapeColor redshapeColor;
47  redshapeColor.m_triangleColor = VisualColor::Red;
48  const Vec3f frontOffset = frontPlane *segmentRadius * 0.5f;
49  const KyFloat32 sqrt2Over2 = 0.7071067f * radius;
50  Vec3f v0 = frontOffset + center + radius * AtoBDir2d + 0.f * Vec3f::UnitZ();
51  Vec3f v1 = frontOffset + center + sqrt2Over2 * AtoBDir2d + sqrt2Over2 * Vec3f::UnitZ();
52  Vec3f v2 = frontOffset + center + 0.f * AtoBDir2d + radius * Vec3f::UnitZ();
53  Vec3f v3 = frontOffset + center - sqrt2Over2 * AtoBDir2d + sqrt2Over2 * Vec3f::UnitZ();
54  Vec3f v4 = frontOffset + center - radius * AtoBDir2d - 0.f * Vec3f::UnitZ();
55  Vec3f v5 = frontOffset + center - sqrt2Over2 * AtoBDir2d - sqrt2Over2 * Vec3f::UnitZ();
56  Vec3f v6 = frontOffset + center - 0.f * AtoBDir2d - radius * Vec3f::UnitZ();
57  Vec3f v7 = frontOffset + center + sqrt2Over2 * AtoBDir2d - sqrt2Over2 * Vec3f::UnitZ();
58  displayList->PushTriangle(center + frontOffset, v0, v1, redshapeColor);
59  displayList->PushTriangle(center + frontOffset, v1, v2, redshapeColor);
60  displayList->PushTriangle(center + frontOffset, v2, v3, redshapeColor);
61  displayList->PushTriangle(center + frontOffset, v3, v4, redshapeColor);
62  displayList->PushTriangle(center + frontOffset, v4, v5, redshapeColor);
63  displayList->PushTriangle(center + frontOffset, v5, v6, redshapeColor);
64  displayList->PushTriangle(center + frontOffset, v6, v7, redshapeColor);
65  displayList->PushTriangle(center + frontOffset, v7, v0, redshapeColor);
66  }
67 
68  }
69 
70  static void BuildPropagationBox(ScopedDisplayList* displayList, const Vec3f& start, const Vec3f& dest, KyFloat32 propagationRadius)
71  {
72  OrientedBox2d box2d;
73  box2d.InitAs2dInflatedSegment(start, dest, propagationRadius);
74  Vec3f A = box2d.m_a;
75  Vec3f B = box2d.m_a + box2d.m_normalizedOrientation*box2d.m_length;
76  Vec3f C = box2d.m_a + box2d.m_normalizedOrientation.PerpCCW()*box2d.m_width;
77  Vec3f D = B + (C - A);
78  KyFloat32 minAlt = Min(start.z, dest.z) - 100.f;
79  KyFloat32 maxAlt = Max(start.z, dest.z) + 100.f;
80 
81  BuildOpenBox(displayList, start, dest, A, B, C, D, box2d.m_normalizedOrientation, minAlt, maxAlt, true);
82  }
83 
84 private:
85  static void BuildOpenBox(ScopedDisplayList* displayList, const Vec3f& start, const Vec3f& dest,
86  Vec3f& A, Vec3f& B, Vec3f& C, Vec3f& D, const Vec2f& AtoBDir2d, KyFloat32 minAlt, KyFloat32 maxAlt, bool doLinkToStartAndDest)
87  {
88  Vec3f A2 = A;
89  Vec3f B2 = B;
90  Vec3f C2 = C;
91  Vec3f D2 = D;
92  A.z = minAlt;
93  C.z = minAlt;
94  B.z = minAlt;
95  D.z = minAlt;
96  A2.z = maxAlt;
97  C2.z = maxAlt;
98  B2.z = maxAlt;
99  D2.z = maxAlt;
100 
101  VisualShapeColor shapeColor;
102  shapeColor.m_triangleColor = VisualColor::Black;
103 
104  if (doLinkToStartAndDest)
105  {
106  displayList->PushLine(A, start, shapeColor.m_triangleColor);
107  displayList->PushLine(C, start, shapeColor.m_triangleColor);
108  displayList->PushLine(A2, start, shapeColor.m_triangleColor);
109  displayList->PushLine(C2, start, shapeColor.m_triangleColor);
110  displayList->PushLine(B, dest, shapeColor.m_triangleColor);
111  displayList->PushLine(D, dest, shapeColor.m_triangleColor);
112  displayList->PushLine(B2, dest, shapeColor.m_triangleColor);
113  displayList->PushLine(D2, dest, shapeColor.m_triangleColor);
114  }
115  shapeColor.m_lineColor = VisualColor::Black;
116  shapeColor.m_triangleColor = VisualColor::DimGray;
117 
118  BuildVerticalForbiddenWallLogo(displayList, A, B, B2, A2, AtoBDir2d);
119  displayList->PushQuad( A, B, B2, A2, shapeColor);
120 
121  BuildVerticalForbiddenWallLogo(displayList, C, A, A2, C2, AtoBDir2d.PerpCW());
122  displayList->PushQuad(C, A, A2, C2, shapeColor);
123 
124  BuildVerticalForbiddenWallLogo(displayList, D, C, C2, D2, -AtoBDir2d);
125  displayList->PushQuad(D, C, C2, D2, shapeColor);
126 
127  BuildVerticalForbiddenWallLogo(displayList, B, D, D2, B2, AtoBDir2d.PerpCCW());
128  displayList->PushQuad(B, D, D2, B2, shapeColor);
129 
130  }
131 
132  virtual void DoBuild(ScopedDisplayList* displayList, char* blob, KyUInt32 /*deepBlobSize*/ = 0)
133  {
134  const AStarQueryBlob* aStarQueryBlob = (AStarQueryBlob*) blob;
135 
136  AStarQueryOutputBlob* aStarQueryOutputBlob = aStarQueryBlob->m_queryOutput.Ptr();
137  if (aStarQueryOutputBlob != NULL)
138  {
139  Vec3f offsetVector = Vec3f::UnitZ();
140  VisualShapeColor shapeColor;
141  shapeColor.m_triangleColor = VisualColor::Red;
142 
143 KY_PUSH_ERROR_ON_MISSING_EXPLICIT_CASE_LABEL
144  switch((AStarQueryResult)aStarQueryOutputBlob->m_result)
145  {
146  case ASTAR_NOT_INITIALIZED :
147  break;
148  case ASTAR_NOT_PROCESSED :
160  {
161  shapeColor.m_triangleColor = VisualColor::Orange;
162  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
163  }
164  break;
166  {
167  displayList->PushText(aStarQueryBlob->m_startPos3f + offsetVector, shapeColor.m_triangleColor, "Start outside!");
168  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
169  }
170  break;
172  {
173  displayList->PushText(aStarQueryBlob->m_startPos3f + offsetVector, shapeColor.m_triangleColor, "Start NavTag forbidden!");
174  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
175  }
176  break;
178  {
179  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Destination outside!");
180  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
181  }
182  break;
184  {
185  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Destination NavTag forbidden!");
186  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
187  }
188  break;
190  {
191  BuildPropagationBox(displayList, aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, aStarQueryBlob->m_propagationBoxExtent);
192  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Path not found !");
193  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
194  }
195  break;
197  {
198  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "NavData changed!");
199  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
200  }
201  break;
203  {
204  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Lack of working memory!");
205  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
206  }
207  break;
209  {
210  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Computation Error");
211  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
212  }
213  break;
215  {
216  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Channel Config Error");
217  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
218  }
219  break;
221  {
222  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Channel Computation Error");
223  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
224  }
225  break;
227  {
228  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "startPos=destPos, no Path computed");
229  }
230  break;
232  {
233  shapeColor.m_triangleColor = VisualColor::Lime;
234  PathDisplayListBuilder pathDisplay;
235  pathDisplay.DisplayPath(displayList, &aStarQueryOutputBlob->m_pathBlob);
236  if (aStarQueryOutputBlob->m_abstractPathBlob.m_nodePositions.GetCount() != 0)
237  {
238  pathDisplay.m_edgesColor = Kaim::VisualColor::Lime;
239  pathDisplay.DisplayPath(displayList, &aStarQueryOutputBlob->m_abstractPathBlob);
240  }
241  }
242  break;
244  {
245  displayList->PushText(aStarQueryBlob->m_destPos3f + offsetVector, shapeColor.m_triangleColor, "Query Canceled");
246  displayList->PushLine(aStarQueryBlob->m_startPos3f, aStarQueryBlob->m_destPos3f, shapeColor.m_triangleColor);
247  }
248  break;
249  }
250 KY_POP_ERROR_ON_MISSING_EXPLICIT_CASE_LABEL
251  }
252  }
253 };
254 
255 }
256 
257 #endif
Indicates that a path could not be found between the start and destination points.
Definition: baseastarquery.h:50
Unused. Kept here for backward compatibility.
Definition: baseastarquery.h:43
static const VisualColor Lime
Represents the color with RGBA values ( 0, 255, 0, 255).  
Definition: visualcolor.h:172
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:55
Indicates that insufficient working memory caused the query to stop.
Definition: baseastarquery.h:52
static const VisualColor Black
Represents the color with RGBA values ( 0, 0, 0, 255).  
Definition: visualcolor.h:103
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:53
Indicates that the refined path is being clamped to navMesh according to the altitude tolerance...
Definition: baseastarquery.h:41
static const VisualColor Orange
Represents the color with RGBA values (255, 165, 0, 255).  
Definition: visualcolor.h:195
Indicates that the NavTag at the starting point is forbidden.
Definition: baseastarquery.h:47
Indicates the query has not yet been launched.
Definition: baseastarquery.h:32
Indicates that the channel is initialized, the channel is being computed.
Definition: baseastarquery.h:44
T Min(const T &a, const T &b)
Returns the lesser of the two specified values.
Definition: fastmath.h:113
static const VisualColor Red
Represents the color with RGBA values (255, 0, 0, 255).  
Definition: visualcolor.h:209
Indicates that the NavTag at the destination point is forbidden.
Definition: baseastarquery.h:49
Indicates that the input channelComputerConfig is invalid.
Definition: baseastarquery.h:54
Indicates that the refining process is being initialized.
Definition: baseastarquery.h:37
Indicates that a NavMesh triangle could not be found for the starting point.
Definition: baseastarquery.h:46
static Vec3f UnitZ()
Returns the normalized orientation of the Z axis.
Definition: vec3f.h:218
Indicates that the Astar traversal algorithm has been launched, but has not yet completed.
Definition: baseastarquery.h:34
static const VisualColor DimGray
Represents the color with RGBA values (105, 105, 105, 255).  
Definition: visualcolor.h:136
Indicates the query has not yet been initialized.
Definition: baseastarquery.h:31
Indicates that the refiner is done, but the path has not yet been clamped to the navMesh.
Definition: baseastarquery.h:40
Indicates that the computation has been canceled.
Definition: baseastarquery.h:56
T Max(const T &a, const T &b)
Returns the greater of the two specified values.
Definition: fastmath.h:121
Definition: gamekitcrowddispersion.h:20
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
static const VisualColor White
Represents the color with RGBA values (255, 255, 255, 255).  
Definition: visualcolor.h:234
Indicates that the cost from nodes that are on navMesh are beeing recomputed since they may have been...
Definition: baseastarquery.h:38
Indicates that query starting location and ending location are equals. computing a Path would have le...
Definition: baseastarquery.h:58
Indicates that the query has stopped and must be relaunched because of a change in the NavData...
Definition: baseastarquery.h:51
Indicates that the clamping algorithm has completed, but the path has not yet been built...
Definition: baseastarquery.h:42
Indicates that the Astar traversal algorithm traversed AbstractGraph, and the Abstract path is being ...
Definition: baseastarquery.h:36
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Indicates that the Astar traversal algorithm is finished, and that a path is found and is prepared to...
Definition: baseastarquery.h:35
Indicates that the destination point of the query is outside the NavMesh.
Definition: baseastarquery.h:48
Indicates that a path has been found between the start and destination.
Definition: baseastarquery.h:59
Indicates that the path found is being refined.
Definition: baseastarquery.h:39
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
AStarQueryResult
Enumerates the possible results of an AStarQuery.
Definition: baseastarquery.h:29