gwnavruntime/channel/stringpuller.h Source File

stringpuller.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_StringPuller_H
8 #define Navigation_StringPuller_H
9 
11 
14 
17 
18 
19 namespace Kaim
20 {
21 
22 class World;
23 class BiTangentSorter_IncreasingAngleFromReferenceDirection;
24 
25 enum StringPullerResult
26 {
27  StringPuller_NotInitialized,
28  StringPuller_NotComputed,
29 
30  StringPuller_Done_Success,
31 
32  StringPuller_Done_InvalidInput,
33  StringPuller_Done_CurrentPivotOppositeBorderNotFound,
34  StringPuller_Done_BubbleToCornerFunnelFailure,
35  StringPuller_Done_NextPivotNotFound,
36  StringPuller_Done_NextPivotOppositeBorderNotFound,
37 };
38 
39 
43 {
44 public:
45  StringPuller();
46 
47  void Initialize(const BubbleArray& bubbleArray);
48  void Clear();
49 
50  // Compute full StringPull, i.e. same as Advance with no slicing
51  KY_INLINE void Compute(StringPulledBubbleList& stringPulledBubbleList);
52 
53  // Advances the pivot at most by maxPivotPerAdvance
54  void Advance(StringPulledBubbleList& stringPulledBubbleList, KyUInt32 maxPivotPerAdvance = 1);
55 
56 
57 public: // Internal. They are public only to be unit tested
58  KyResult RunFromCurrentPivot(StringPulledBubbleList& stringPulledBubbleList);
59 
60  KyResult ComputeClosedCorner();
61  KyResult ComputeNextPivot();
62  KyResult StringPullBetweenPivots(StringPulledBubbleList& stringPulledBubbleList);
63 
64  KyResult ComputeCurrentPivotEnterOrthoOppositeBoderIndex();
65  KyResult ComputeNextPivotEnterOrthoOppositeBoderIndex();
66 
67  KyResult ComputeCornerEnterOrthoOppositeBoderIndex(KyUInt32 cornerIndex, FunnelSide cornerSide, const Vec2f& enterDirection,
68  KyUInt32& oppositeBorderStartIdx, KyUInt32& oppositeBorderEndIdx, const VisualColor& baseColor, const char* displayListName);
69 
70  KyResult ComputeOppositeBorderIndex(KyUInt32 cornerIdx, const Vec2f& direction, KyUInt32& oppositeBorderStartIdx, KyUInt32& oppositeBorderEndIdx);
71  KyResult CollectIntersectingBubblesInPivotTurn();
72  KyResult CollectIntersectingBubblesSameSideThanCurrentPivot();
73  KyResult CollectIntersectingBubblesSameSideThanClosedCorner();
74  KyResult CollectIntersectingBubblesUpToClosedCorner(RotationDirection collectedBubbleRotDir);
75  KyResult CollectIntersectingBubblesOverClosedCorner(RotationDirection collectedBubbleRotDir);
76 
77  KyUInt32 GetNextTangentBubbleIdx(FunnelSide funnelSide, const Vec2f& refDir);
78 
79  void VisualDebugRunFromCurrentPivot() const;
80  void VisualDebugGetNextTangentBubbleIdx(KyUInt32 bubbleCount, const Bubble& curPivotBubble, const Vec2f& refDir, BiTangentSorter_IncreasingAngleFromReferenceDirection& increasingAngleSorter) const;
81  void VisualDebugStringPullBetweenPivots() const;
82  void VisualDebugComputeCornerEnterOrtho_1(const VisualColor& displayColor, const char* displayListName, KyUInt32 cornerIndex) const;
83  void VisualDebugComputeCornerEnterOrtho_2(const VisualColor& displayColor, const char* displayListName, KyUInt32 cornerIndex, const Vec2f& curPivotEnterOrthoDir, const Vec2f& enterDirection) const;
84  void VisualDebugComputeCornerEnterOrtho_3(const char* displayListName, KyUInt32 oppositeBorderStartIdx, KyUInt32 oppositeBorderEndIdx, VisualColor displayColor) const;
85 public: // Internal: public only for unit tests
86  // Inputs
87  const BubbleArray* m_bubbleArray;
88 
89  // Parameters
90  KyFloat32 m_fullTurnToleranceSin; // Very technical: default is 0.01 ( = sin(~s0.57 Degrees )), must be let very small
91 
92  // Internal
93 // StringPulledBubbleList m_localStringPull;
94  KyArrayPOD<KyUInt32> m_indicesOfTheSameSideCornersIncludedInCurrentPivotBubble;
95  BubbleFunnelBorder m_funnelClosedBorder;
96 
97  KyUInt32 m_bubbleCount;
98 
99  KyUInt32 m_currentPivotIndex;
100  FunnelSide m_currentPivotSide;
101  Vec2f m_currentPivotEnterDirection;
102  KyUInt32 m_currentPivotOrthoOppositeBorderStartIdx;
103  KyUInt32 m_currentPivotOrthoOppositeBorderEndIdx;
104 
105  KyUInt32 m_nextPivotIndex;
106  FunnelSide m_nextPivotSide;
107  Vec2f m_nextPivotEnterDirection;
108  KyUInt32 m_nextPivotOrthoOppositeBorderStartIdx;
109  KyUInt32 m_nextPivotOrthoOppositeBorderEndIdx;
110 
111  KyArrayPOD<KyUInt32> m_intersectingBubbles; // aka bubble subset
112  struct BiTangent
113  {
114  KyFloat32 GetSqLength2d() const { return SquareDistance2d(m_startPos, m_endPos); }
115  Vec3f m_startPos;
116  Vec3f m_endPos;
117  Vec2f m_dir;
118  };
119  KyArrayPOD<BiTangent> m_biTanArray;
120  KyArrayPOD<KyUInt32> m_sortedIndices;
121  KyArrayPOD<KyUInt32> m_localStringPullCornerIndices;
122 
123  // Outputs
124  StringPullerResult m_result;
125 
126  // VisualDebug
127  mutable KyUInt32 m_loopIndex;
128  mutable StringStream m_groupName;
129 
130 public:
131  bool m_advancedVisualDebuggingEnabled;
132  World* m_advancedVisualDebuggingWorld;
133 };
134 
135 
136 KY_INLINE void StringPuller::Compute(StringPulledBubbleList& stringPulledBubbleList) { Advance(stringPulledBubbleList, KyUInt32MAXVAL); }
137 
138 } // namespace Kaim
139 
140 #endif // Navigation_StringPuller_H
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class encapsulate an array of Bubbles.
Definition: bubblearray.h:23
Represents a single RGBA color.
Definition: visualcolor.h:19
This class is a runtime container for Gameware Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:54
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:20
KyFloat32 SquareDistance2d(const Vec3f &v1, const Vec3f &v2)
Returns the square of the distance between v1 and v2, ignoring Z coordinates.
Definition: vec3f.h:277
This class represents a circle with potential rotation limitation.
Definition: bubble.h:35
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
Definition: gamekitcrowddispersion.h:20
Computes a StringPulledBubbleList from the provided array of bubbles.
Definition: stringpuller.h:42
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23