gwnavruntime/channel/bubbletocornerfunnel.h Source File

bubbletocornerfunnel.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
12 
13 
14 namespace Kaim
15 {
16 
17 class DisplayListManager;
18 class BubbleArray;
19 class BubbleToCornerFunnel;
20 class DisplayList;
21 
22 // Internal: represents a BubbleFunnel border with all necessary internal references.
23 class BubbleFunnelBorder
24 {
25 public:
26  BubbleFunnelBorder()
27  : m_isInitialized(false)
28  {}
29 
30  BubbleFunnelBorder(KyUInt32 bubbleIdx, const Vec3f& segmentStart, const Vec3f& segmentEnd)
31  {
32  Set(bubbleIdx, segmentStart, segmentEnd);
33  }
34 
35  void Clear()
36  {
37  m_isInitialized = false;
38  }
39 
40  void Set(KyUInt32 bubbleIdx, const Vec3f& segmentStart, const Vec3f& segmentEnd)
41  {
42  m_segmentStart = segmentStart;
43  m_segmentEnd = segmentEnd;
44 
45  const Vec2f segmentVec2d = segmentEnd.Get2d() - segmentStart.Get2d();
46  m_segmentLength2d = segmentVec2d.GetNormalized(m_segmentDir2d);
47 
48  m_bubbleIdx = bubbleIdx;
49  m_isInitialized = true;
50  }
51 
52  const Vec3f& GetSegmentStart() const { return m_segmentStart; }
53  const Vec3f& GetSegmentEnd() const { return m_segmentEnd; }
54  const Vec2f& GetSegmentDir2d() const { return m_segmentDir2d; }
55  KyFloat32 GetSegmentLength2d() const { return m_segmentLength2d; }
56  KyUInt32 GetBubbleIdx() const { return m_bubbleIdx; }
57  bool IsInitialized() const { return m_isInitialized; }
58 
59 private:
60  friend class BubbleToCornerFunnel;
61 
62  Vec3f m_segmentStart;
63  Vec3f m_segmentEnd;
64  Vec2f m_segmentDir2d;
65  KyFloat32 m_segmentLength2d;
66  KyUInt32 m_bubbleIdx;
67  bool m_isInitialized;
68 };
69 
70 
73 {
74 public:
75  BubbleToCornerFunnel(const BubbleArray* bubbleArray, DisplayListManager* displayListManager, bool advancedVisualDebuggingEnabled, const char* loopGroupName)
76  : m_bubbleArray(bubbleArray)
77  , m_previousResult(FunnelUnchanged)
78  , m_funnelBordersDisplayList(nullptr)
79  , m_displayListManager(displayListManager)
80  , m_advancedVisualDebuggingEnabled(advancedVisualDebuggingEnabled)
81  , m_loopGroupName(loopGroupName)
82  {
83  }
84 
85  void Initialize(KyUInt32 apexIdx, const Vec2f& entryDir, KyFloat32 fullTurnToleranceSin);
86 
87  FunnelResult UpdateAccordinglyToCorner(KyUInt32 cornerIdx, KyArrayPOD<KyUInt32>& indicesOfTheCornersIncludedInCurrentPivot);
88 
89  KyUInt32 GetApexIdx() const { return m_apexIdx; }
90  const Bubble& GetApexBubble() const { return m_apexBubble; }
91  const BubbleFunnelBorder& GetLeftBorder() const { return m_leftBorder; }
92  const BubbleFunnelBorder& GetRightBorder() const { return m_rightBorder; }
93  FunnelResult GetPreviousResult() const { return m_previousResult; }
94 
95 private:
96  bool IsStrictlyInTurnRange(const Vec2f& entryDir, const Vec2f& exitDir, RotationDirection rotDir, const Vec2f& dir2d) const;
97  bool IsOutsideOnLeft(const Vec2f& axis2d) const;
98  bool IsOutsideOnRight(const Vec2f& axis2d) const;
99 
100  bool IsOutsideOnLeft_Standard(const Vec2f& axis2d) const;
101  bool IsOutsideOnRight_Standard(const Vec2f& axis2d) const;
102  bool IsStrictlyInHalfPlan(const Vec2f& refDir, KyFloat32 rotSign, const Vec2f& axis2d) const;
103  //bool IsInHalfPlan(const Vec2f& refDir, KyFloat32 rotSign, const Vec2f& axis2d) const;
104 
105  void PushApexInDisplayList(DisplayList& displayList) const;
106 
107  // commented because not used
108  //enum IsInsideFunnelResult
109  //{
110  // FunnelNotInitialized,
111  // LeftBorderNotInitialized,
112  // RightBorderNotInitialized,
113  // SmallFunnelRange,
114  // NearLeftBorder,
115  // NearRightBorder,
116  // StrictlyInsideFunnel,
117  // OutsideFunnel
118  //};
119  //IsInsideFunnelResult IsInsideFunnel(const Vec2f& axis2d, KyFloat32 fullTurnToleranceSin) const;
120 
121  bool IsInsideFunnel(const Vec2f& axis2d) const;
122 
123  void TightenLeftBorder(const BubbleFunnelBorder& border);
124  void TightenRightBorder(const BubbleFunnelBorder& border);
125  void PushBorderAsLineInDisplayList(const BubbleFunnelBorder& border, DisplayList* displayList, Color color);
126 
127 private:
128  // Inputs
129  const BubbleArray* m_bubbleArray;
130 
131  KyUInt32 m_apexIdx;
132  Bubble m_apexBubble;
133  RotationDirection m_apexRotDir;
134  FunnelSide m_apexSide;
135  Vec2f m_entryDir;
136  Vec2f m_entryDirMinusFullTurnTolerance;
137 
138  KyFloat32 m_fullTurnToleranceSin;
139 
140  // Keep radius-related funnel information.
141  BubbleFunnelBorder m_leftBorder;
142  BubbleFunnelBorder m_rightBorder;
143 
144  // Output
145  FunnelResult m_previousResult;
146 
147  // Internals
148  Bubble m_lastAddedCornerBubble; // Just to avoid allocating a Bubble on each iteration.
149  bool m_entryDirPassed;
150  bool m_hasQuitApexBubble;
151 
152 public: // internal - debug
153  DisplayList* m_funnelBordersDisplayList;
154  DisplayListManager* m_displayListManager;
155  bool m_advancedVisualDebuggingEnabled;
156  const char* m_loopGroupName;
157 };
158 
159 
160 KY_INLINE void BubbleToCornerFunnel::TightenLeftBorder(const BubbleFunnelBorder& border)
161 {
162  if (m_funnelBordersDisplayList)
163  PushBorderAsLineInDisplayList(border, m_funnelBordersDisplayList, Color::Green);
164 
165  m_leftBorder = border;
166  m_previousResult = FunnelTightened;
167 }
168 
169 KY_INLINE void BubbleToCornerFunnel::TightenRightBorder(const BubbleFunnelBorder& border)
170 {
171  if (m_funnelBordersDisplayList)
172  PushBorderAsLineInDisplayList(border, m_funnelBordersDisplayList, Color::Red);
173 
174  m_rightBorder = border;
175  m_previousResult = FunnelTightened;
176 }
177 
178 
179 KY_INLINE bool BubbleToCornerFunnel::IsOutsideOnLeft_Standard(const Vec2f& axis2d) const
180 {
181  return IsStrictlyInHalfPlan(m_leftBorder.GetSegmentDir2d(), 1.0f, axis2d);
182 }
183 
184 KY_INLINE bool BubbleToCornerFunnel::IsOutsideOnRight_Standard(const Vec2f& axis2d) const
185 {
186  return IsStrictlyInHalfPlan(m_rightBorder.GetSegmentDir2d(), -1.0f, axis2d);
187 }
188 
189 } // namespace Kaim
190 
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:375
Adaptive radius funnel to be used typically to string pull within a Bubble array. ...
Definition: bubbletocornerfunnel.h:72
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
This class encapsulate an array of Bubbles.
Definition: bubblearray.h:22
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:15
This class represents a circle with potential rotation limitation.
Definition: bubble.h:31
2d vector using KyFloat32.
Definition: vec2f.h:18
DisplayList is used to push text, lines or shapes for rendering in the NavigationLab e...
Definition: displaylist.h:128
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
RGBA color.
Definition: color.h:16
float KyFloat32
float
Definition: types.h:32