gwnavruntime/channel/bubblestringpullerbetweenpivots.h Source File

bubblestringpullerbetweenpivots.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_BubbleStringPullerBetweenPivots_H
8 #define Navigation_BubbleStringPullerBetweenPivots_H
9 
11 
12 
13 namespace Kaim
14 {
15 
16 class StringPulledBubbleList;
17 
18 // Internal.
19 // This class computes a string pull on Bubbles that are so that the line
20 class BubbleStringPullerBetweenPivots
21 {
22 private:
23  // A chained-list node identifying a pivot Bubble in both a BubbleArray (globalArrayIdx)
24  // and a local corner index array (localArrayIdx).
25  class Pivot : public ListNode<Pivot>
26  {
27  public:
28  Pivot(KyUInt32 globalArrayIdx, KyUInt32 localArrayIdx)
29  : m_globalArrayIdx(globalArrayIdx)
30  , m_localArrayIdx(localArrayIdx)
31  {}
32 
33  void Set(KyUInt32 globalArrayIdx, KyUInt32 localArrayIdx)
34  {
35  m_globalArrayIdx = globalArrayIdx;
36  m_localArrayIdx = localArrayIdx;
37  }
38 
39  KyUInt32 m_globalArrayIdx;
40  KyUInt32 m_localArrayIdx;
41  };
42 
43 
44  // Defines a sub set for iterative corner index array sort and local
45  // string pull resolution.
46  class BubbleArraySubSet
47  {
48  public:
49  enum SubSetSide
50  {
51  BeforePivot = 0,
52  AfterPivot
53  };
54 
55  BubbleArraySubSet()
56  : m_pivot(KY_NULL)
57  , m_startGlobalIndex(KyUInt32MAXVAL)
58  , m_endGlobalIndex(KyUInt32MAXVAL)
59  , m_refBubbleGlobalIndex(KyUInt32MAXVAL)
60  , m_startLocalIndex(KyUInt32MAXVAL)
61  , m_endLocalIndex(KyUInt32MAXVAL)
62  , m_subSetSide(BeforePivot)
63  {}
64 
65  BubbleArraySubSet(const KyUInt32 startGlobalIndex, const KyUInt32 endGlobalIndex, KyUInt32 startLocalIndex, KyUInt32 endLocalIndex)
66  : m_pivot(KY_NULL)
67  , m_startGlobalIndex(startGlobalIndex)
68  , m_endGlobalIndex(endGlobalIndex)
69  , m_refBubbleGlobalIndex(endGlobalIndex)
70  , m_startLocalIndex(startLocalIndex)
71  , m_endLocalIndex(endLocalIndex)
72  , m_subSetSide(BeforePivot)
73  {}
74 
75  BubbleArraySubSet(Pivot* pivot, SubSetSide subSetSide, const KyUInt32 startGlobalIndex, const KyUInt32 endGlobalIndex, KyUInt32 startLocalIndex, KyUInt32 endLocalIndex)
76  : m_pivot(pivot)
77  , m_startGlobalIndex(startGlobalIndex)
78  , m_endGlobalIndex(endGlobalIndex)
79  , m_refBubbleGlobalIndex(endGlobalIndex)
80  , m_startLocalIndex(startLocalIndex)
81  , m_endLocalIndex(endLocalIndex)
82  , m_subSetSide(subSetSide)
83  {}
84 
85  Pivot* m_pivot;
86  KyUInt32 m_startGlobalIndex;
87  KyUInt32 m_endGlobalIndex;
88  KyUInt32 m_refBubbleGlobalIndex;
89  KyUInt32 m_startLocalIndex;
90  KyUInt32 m_endLocalIndex;
91  SubSetSide m_subSetSide;
92  };
93 
94  class IncreasingProjectionDistance2dLessSorter
95  {
96  public:
97  IncreasingProjectionDistance2dLessSorter(
98  const BubbleArray* bubbleArray, const Vec2f& referencePosition,
99  const Vec2f& referenceVector, KyUInt32 referenceEndBubbleIdx)
100  : m_bubbleArray(bubbleArray)
101  , m_referencePosition(referencePosition)
102  , m_referenceVector(referenceVector)
103  , m_referenceEndBubbleIdx(referenceEndBubbleIdx)
104  {}
105 
106  KY_INLINE bool operator() (KyUInt32 firstIdx, KyUInt32 secondIdx) const
107  {
108  // Let m_referenceEndBubbleIdx be sorted in last position
109  if (firstIdx == m_referenceEndBubbleIdx)
110  return false;
111  if (secondIdx == m_referenceEndBubbleIdx)
112  return true;
113 
114  const Bubble& firstBubble = m_bubbleArray->At(firstIdx);
115  const Bubble& secondBubble = m_bubbleArray->At(secondIdx);
116 
117  const Vec2f vecToFirst = firstBubble.GetCenter().Get2d() - m_referencePosition;
118  const Vec2f vecToSecond = secondBubble.GetCenter().Get2d() - m_referencePosition;
119 
120  return (DotProduct(vecToFirst, m_referenceVector) < DotProduct(vecToSecond, m_referenceVector));
121  }
122 
123  private:
124  const BubbleArray* m_bubbleArray;
125  Vec2f m_referencePosition;
126  Vec2f m_referenceVector;
127  KyUInt32 m_referenceEndBubbleIdx;
128  };
129 
130 
131 public:
132  KyResult SolveLocalStringPulledBubbleList(const BubbleArray& bubbleArray, KyArrayPOD<KyUInt32>& cornerIndexArray,
133  KyUInt32 startGlobalIndex, KyUInt32 endGlobalIndex, StringPulledBubbleList& stringPulledBubbleList);
134 
135 private:
136  // This function analyzes a subset of corner index array to detect a intermediary
137  // pivot. It then split the current subset in two subsets around the identified pivot.
138  // Note that in fact the second part of the initial subset is not created, so that the
139  // first identified pivot is used as start bubble for the next main loop.
140  KyResult TreatNextSubStrip(const BubbleArray& bubbleArray, KyArrayPOD<KyUInt32>& funnelCornerIndices,
141  KyArray<BubbleArraySubSet>& subSets, KyArray<Pivot>& pivotArray, List<Pivot>& pivotList);
142 };
143 
144 } // namespace Kaim
145 
146 #endif // Navigation_BubbleStringPullerBetweenPivots_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
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
KyFloat32 DotProduct(const Vec2f &v1, const Vec2f &v2)
Returns the dot product of v1 and v2.
Definition: vec2f.h:187
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