gwnavruntime/channel/bubbletocornerfunnel.h Source File

bubbletocornerfunnel.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 #ifndef Navigation_BubbleToCornerFunnel_H
8 #define Navigation_BubbleToCornerFunnel_H
9 
13 
14 
15 namespace Kaim
16 {
17 
18 class BubbleArray;
19 class BubbleToCornerFunnel;
20 class ScopedDisplayList;
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 
72 class BubbleToCornerFunnel
73 {
74 public:
75  BubbleToCornerFunnel(const BubbleArray* bubbleArray)
76  : m_bubbleArray(bubbleArray)
77  , m_previousResult(FunnelUnchanged)
78  , m_leftBorderDisplayList(KY_NULL)
79  , m_rightBorderDisplayList(KY_NULL)
80  {}
81 
82  void Initialize(KyUInt32 apexIdx, const Vec2f& entryDir, KyFloat32 fullTurnToleranceSin);
83  FunnelResult UpdateAccordinglyToCorner(KyUInt32 cornerIdx, KyArrayPOD<KyUInt32>& indicesOfTheCornersIncludedInCurrentPivot);
84 
85  KyUInt32 GetApexIdx() const { return m_apexIdx; }
86  const Bubble& GetApexBubble() const { return m_apexBubble; }
87  const BubbleFunnelBorder& GetLeftBorder() const { return m_leftBorder; }
88  const BubbleFunnelBorder& GetRightBorder() const { return m_rightBorder; }
89  FunnelResult GetPreviousResult() const { return m_previousResult; }
90 
91 private:
92  bool IsStrictlyInTurnRange(const Vec2f& entryDir, const Vec2f& exitDir, RotationDirection rotDir, const Vec2f& dir2d) const;
93  bool IsOutsideOnLeft(const Vec2f& axis2d) const;
94  bool IsOutsideOnRight(const Vec2f& axis2d) const;
95 
96  bool IsOutsideOnLeft_Standard(const Vec2f& axis2d) const;
97  bool IsOutsideOnRight_Standard(const Vec2f& axis2d) const;
98  bool IsStrictlyInHalfPlan(const Vec2f& refDir, KyFloat32 rotSign, const Vec2f& axis2d) const;
99  bool IsInHalfPlan(const Vec2f& refDir, KyFloat32 rotSign, const Vec2f& axis2d) const;
100 
101  enum IsInsideFunnelResult
102  {
103  FunnelNotInitialized,
104  LeftBorderNotInitialized,
105  RightBorderNotInitialized,
106  SmallFunnelRange,
107  NearLeftBorder,
108  NearRightBorder,
109  StrictlyInsideFunnel,
110  OutsideFunnel
111  };
112  IsInsideFunnelResult IsInsideFunnel(const Vec2f& axis2d, KyFloat32 fullTurnToleranceSin) const;
113 
114  bool IsInsideFunnel(const Vec2f& axis2d) const;
115 
116  void TightenLeftBorder(const BubbleFunnelBorder& border);
117  void TightenRightBorder(const BubbleFunnelBorder& border);
118  void PushBorderAsLineInDisplayList(const BubbleFunnelBorder& border, ScopedDisplayList* displayList, VisualColor color);
119 
120 private:
121  // Inputs
122  const BubbleArray* m_bubbleArray;
123 
124  KyUInt32 m_apexIdx;
125  Bubble m_apexBubble;
126  RotationDirection m_apexRotDir;
127  FunnelSide m_apexSide;
128  Vec2f m_entryDir;
129 
130  KyFloat32 m_fullTurnToleranceSin;
131 
132  // Keep radius-related funnel information.
133  BubbleFunnelBorder m_leftBorder;
134  BubbleFunnelBorder m_rightBorder;
135 
136  // Output
137  FunnelResult m_previousResult;
138 
139  // Internals
140  Bubble m_lastAddedCornerBubble; // Just to avoid allocating a Bubble on each iteration.
141  bool m_entryDirPassed;
142  bool m_hasQuitApexBubble;
143 
144 public: // internal - debug
145  ScopedDisplayList* m_leftBorderDisplayList;
146  ScopedDisplayList* m_rightBorderDisplayList;
147 };
148 
149 
150 KY_INLINE void BubbleToCornerFunnel::TightenLeftBorder(const BubbleFunnelBorder& border)
151 {
152  if (m_leftBorderDisplayList)
153  PushBorderAsLineInDisplayList(border, m_leftBorderDisplayList, VisualColor::Green);
154 
155  m_leftBorder = border;
156  m_previousResult = FunnelTightened;
157 }
158 
159 KY_INLINE void BubbleToCornerFunnel::TightenRightBorder(const BubbleFunnelBorder& border)
160 {
161  if (m_rightBorderDisplayList)
162  PushBorderAsLineInDisplayList(border, m_rightBorderDisplayList, VisualColor::DarkRed);
163 
164  m_rightBorder = border;
165  m_previousResult = FunnelTightened;
166 }
167 
168 
169 KY_INLINE bool BubbleToCornerFunnel::IsOutsideOnLeft_Standard(const Vec2f& axis2d) const
170 {
171  return IsStrictlyInHalfPlan(m_leftBorder.GetSegmentDir2d(), 1.0f, axis2d);
172 }
173 
174 KY_INLINE bool BubbleToCornerFunnel::IsOutsideOnRight_Standard(const Vec2f& axis2d) const
175 {
176  return IsStrictlyInHalfPlan(m_rightBorder.GetSegmentDir2d(), -1.0f, axis2d);
177 }
178 
179 } // namespace Kaim
180 
181 #endif // Navigation_BubbleToCornerFunnel_H
Adaptive radius funnel to be used typically to string pull within a Bubble array. ...
Definition: bubbletocornerfunnel.h:74
This class encapsulate an array of Bubbles.
Definition: bubblearray.h:23
#define KY_NULL
Null value.
Definition: types.h:247
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:20
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
Definition: gamekitcrowddispersion.h:20
static const VisualColor Green
Represents the color with RGBA values ( 0, 128, 0, 255).  
Definition: visualcolor.h:147
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
static const VisualColor DarkRed
Represents the color with RGBA values (139, 0, 0, 255).  
Definition: visualcolor.h:127