gwnavruntime/channel/channelsectionptr.h Source File

channelsectionptr.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 
8 // primary contact: LAPA - secondary contact: NOBODY
9 
10 #ifndef Navigation_ChannelSectionPtr_H
11 #define Navigation_ChannelSectionPtr_H
12 
15 
16 
17 namespace Kaim
18 {
19 
20 class PositionOnPath;
21 
22 class ChannelSectionPtr
23 {
24 public:
25 
26  ChannelSectionPtr();
27  ChannelSectionPtr(Ptr<ChannelArray> channelArray, KyUInt32 channelIdx, KyUInt32 sectionIdx);
28  ~ChannelSectionPtr();
29 
30  void Invalidate();
31 
32  KyResult Set(Ptr<ChannelArray> channelArray, KyUInt32 channelIdx, KyUInt32 sectionIdx);
33 
34  KyResult SetFromPositionOnPath(const PositionOnPath& positionOnPath);
35 
40  KyResult Update(const Vec3f& prevPos, const Vec3f& newPos);
41 
46  KyResult Update(const PositionOnPath& positionOnPath, const Vec3f& newPos);
47 
48  bool IsValid() const;
49 
50  bool operator==(const ChannelSectionPtr& other) const;
51  bool operator!=(const ChannelSectionPtr& other) const;
52 
54 
57  bool IsFirstSection() const;
58 
61  bool IsLastSection() const;
62 
65  bool IsTriangularLeftTurn() const;
66 
69  bool IsTriangularRightTurn() const;
70 
73  bool IsPositionInSection(const Vec2f& position, KyUInt32& positionFlags) const;
74 
75  ChannelArray* GetChannelArray() const;
76  KyUInt32 GetChannelIdx() const;
77  KyUInt32 GetSectionIdx() const;
78 
79  const Channel* GetChannel() const; // WARNING : This object must be valid !
80 
81  KyUInt32 GetPathNodeIdxOfSectionStartGate() const;
82  KyUInt32 GetPathNodeIdxOfSectionEndGate() const;
83  KyUInt32 GetPathNodeIdxOfChannelLastGate() const;
84 
85  KyUInt32 GetSectionStartGateIdx() const;
86  KyUInt32 GetSectionEndGateIdx() const;
87  const Gate& GetSectionStartGate() const;
88  const Gate& GetSectionEndGate() const;
89 
90 public: // internal
91  // Beware this set the channel section based on node index and doesn't take care of node position
92  // i.e. Node position could be in the adjacent section
93  KyResult SetFromPathNodeIdx(const Ptr<ChannelArray>& channelArray, KyUInt32 pathNodeIdx);
94 
95 public: // internal
96  Ptr<ChannelArray> m_channelArray;
97  KyUInt32 m_channelIdx; // The index of the Channel in the ChannelArray.
98  KyUInt32 m_sectionIdx; // The index of the section, i.e. the Gate starting the quad or triangle this position stays on.
99 };
100 
101 
102 KY_INLINE bool ChannelSectionPtr::IsValid() const
103 {
104  if (m_channelArray != KY_NULL && m_channelIdx < m_channelArray->GetChannelCount())
105  {
106  const Channel* channel = m_channelArray->GetChannel(m_channelIdx);
107  return channel != KY_NULL && m_sectionIdx < channel->GetGateCount() + 1;
108  }
109 
110  return false;
111 }
112 
113 KY_INLINE bool ChannelSectionPtr::IsFirstSection() const { return m_sectionIdx == 0; }
114 KY_INLINE bool ChannelSectionPtr::IsLastSection() const { return m_sectionIdx == GetChannel()->GetGateCount(); }
115 
116 KY_INLINE bool ChannelSectionPtr::IsTriangularRightTurn() const
117 {
118  GateType type = GetSectionStartGate().m_type;
119  return (type == RightTurnStart) || (type == RightTurnIntermediary);
120 }
121 
122 KY_INLINE bool ChannelSectionPtr::IsTriangularLeftTurn() const
123 {
124  GateType type = GetSectionStartGate().m_type;
125  return (type == LeftTurnStart) || (type == LeftTurnIntermediary);
126 }
127 
128 KY_INLINE bool ChannelSectionPtr::IsPositionInSection(const Vec2f& position, KyUInt32& positionFlags) const
129 {
130  return GetChannel()->IsPositionInSection(position, m_sectionIdx, positionFlags);
131 }
132 
133 KY_INLINE ChannelArray* ChannelSectionPtr::GetChannelArray() const { return m_channelArray; }
134 KY_INLINE KyUInt32 ChannelSectionPtr::GetChannelIdx() const { return m_channelIdx; }
135 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionIdx() const { return m_sectionIdx; }
136 KY_INLINE const Channel* ChannelSectionPtr::GetChannel() const { return m_channelArray->GetChannel(m_channelIdx); }
137 
138 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfSectionStartGate() const { return GetChannel()->GetGatePathNodeIdx(GetSectionStartGateIdx()); }
139 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfSectionEndGate() const { return GetChannel()->GetGatePathNodeIdx(GetSectionEndGateIdx()); }
140 KY_INLINE KyUInt32 ChannelSectionPtr::GetPathNodeIdxOfChannelLastGate() const { return GetChannel()->GetGatePathNodeIdx(GetChannel()->GetGateCount() -1); }
141 
142 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionStartGateIdx() const { return GetChannel()->GetSectionStartGateIdx(m_sectionIdx); }
143 KY_INLINE KyUInt32 ChannelSectionPtr::GetSectionEndGateIdx() const { return GetChannel()->GetSectionEndGateIdx(m_sectionIdx); }
144 KY_INLINE const Gate& ChannelSectionPtr::GetSectionStartGate() const { return GetChannel()->GetSectionStartGate(m_sectionIdx); }
145 KY_INLINE const Gate& ChannelSectionPtr::GetSectionEndGate() const { return GetChannel()->GetSectionEndGate(m_sectionIdx); }
146 
147 KY_INLINE bool ChannelSectionPtr::operator!=(const ChannelSectionPtr& other) const { return !(*this==other); }
148 KY_INLINE bool ChannelSectionPtr::operator==(const ChannelSectionPtr& other) const
149 {
150  return m_channelArray == other.m_channelArray && m_channelIdx == other.m_channelIdx && m_sectionIdx == other.m_sectionIdx;
151 }
152 
153 template <class OSTREAM>
154 inline OSTREAM& operator<<(OSTREAM& os, const ChannelSectionPtr& channelSectionPtr)
155 {
156  os << "{" << channelSectionPtr.m_channelIdx << ", " << channelSectionPtr.m_sectionIdx << "}";
157  return os;
158 }
159 
160 } // namespace Kaim
161 
162 #endif // Navigation_ChannelSectionPtr_H
Indicates the Gate is the start of a sampled turn to the left (CCW). The next Gate must have either L...
Definition: channel.h:31
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
GateType
Enumerates the different kind of Gates.
Definition: channel.h:23
Indicates the Gate is a sampled left turn intermediary Gate.
Definition: channel.h:32
Indicates the Gate is the start of a sampled turn to the right (CW). The next Gate must have either R...
Definition: channel.h:36
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Indicates the Gate is a sampled right turn intermediary Gate.
Definition: channel.h:37