gwnavruntime/channel/circlearccangoinchannel.h Source File

circlearccangoinchannel.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_CircleArcCanGoInChannel_H
8 #define Navigation_CircleArcCanGoInChannel_H
9 
11 
12 namespace Kaim
13 {
14 
15 class Channel;
16 
17 class CircleArcCanGoInChannel
18 {
19 public:
20  // pre-condition : circle arc start and end positions are in the channel and their sectionIdx are correct
21  static bool Perform(const Channel* channel, const Bubble& bubble,
22  const Vec3f& arcStartPos, const Vec3f& arcEndPos, KyUInt32 startSectionIdx, KyUInt32 endSectionIdx);
23 
24 protected:
25  enum CircleArcCanGoResult
26  {
27  CircleArcCanGoResult_NoIntersection,
28  CircleArcCanGoResult_CollisionWithBorder,
29  CircleArcCanGoResult_CollisionWithSectionStartGate,
30  CircleArcCanGoResult_CollisionWithSectionEndGate,
31  CircleArcCanGoResult_Error
32  };
33  class CWCircleArc
34  {
35  public:
36  CWCircleArc() {}
37 
38  Vec2f m_center;
39  Vec2f m_arcStart;
40  Vec2f m_arcEnd;
41  KyFloat32 m_radius;
42  KyFloat32 m_squareRadius;
43  KyUInt32 m_startSectionIdx;
44  KyUInt32 m_endSectionIdx;
45  bool m_arcStartCloseToSegmentInSection[4];
46  bool m_arcEndCloseToSegmentInSection[4];
47  };
48 
49 
50  class SegmentVsCircleData
51  {
52  KY_CLASS_WITHOUT_COPY(SegmentVsCircleData)
53  public:
54  enum SegmentType { Gate, Border, Undefined };
55  SegmentVsCircleData();
56  void Compute(const Vec3f& segmentStart, const Vec3f& segmentEnd, const CWCircleArc& cWCircleArc, SegmentType segmentType);
57  void BuildReverse(const SegmentVsCircleData& other)
58  {
59  m_segmentStart = other.m_segmentEnd;
60  m_segmentEnd = other.m_segmentStart;
61  m_closestPoint = other.m_closestPoint;
62  m_intersectionCount = other.m_intersectionCount;
63  m_segmentType = other.m_segmentType;
64  m_startPosIsStrictlyInsideCircle = other.m_endPosIsStrictlyInsideCircle;
65  m_endPosIsStrictlyInsideCircle = other.m_startPosIsStrictlyInsideCircle;
66  }
67  void Reverse()
68  {
69  Alg::Swap(m_segmentStart, m_segmentEnd);
70  Alg::Swap(m_startPosIsStrictlyInsideCircle, m_startPosIsStrictlyInsideCircle);
71  }
72  public:
73  Vec2f m_segmentStart;
74  Vec2f m_segmentEnd;
75  Vec2f m_closestPoint;
76  KyUInt8 m_intersectionCount;
77  SegmentType m_segmentType;
78  bool m_startPosIsStrictlyInsideCircle;
79  bool m_endPosIsStrictlyInsideCircle;
80  };
81 
82  class SectionData
83  {
84  public:
85  enum SectionType { Quad, TurnLeft, TurnRight, PreSection, PostSection };
86 
87  const SegmentVsCircleData& GetEndGateSegmentData() const
88  {
89  KY_ASSERT(m_type != PostSection);
90  switch (m_type)
91  {
92  case Quad :
93  case TurnRight : return m_segmentVsCircleData[2];
94  case TurnLeft : return m_segmentVsCircleData[1];
95  case PreSection :
96  default : return m_segmentVsCircleData[0];
97  }
98  }
99  const SegmentVsCircleData& GetStartGateSegmentData() const { KY_ASSERT(m_type != PreSection); return m_segmentVsCircleData[0]; }
100 
101  SectionType m_type;
102  KyUInt32 m_sectionIdx;
103  SegmentVsCircleData m_segmentVsCircleData[4];
104  };
105 
106  static CircleArcCanGoResult InitCircleArcCanGo(const Channel* channel, CWCircleArc& cwCircleArc, SectionData& currentSectionData);
107 
108 
109  static void BuildCWCircleArc(const Channel* channel, const Bubble& bubble, const Vec3f& arcStartPos, const Vec3f& arcEndPos,
110  KyUInt32 startSectionIdx, KyUInt32 endSectionIdx, CWCircleArc &cwCircleArc);
111  static void ComputeArcExtremityLocationInSection(const Channel* channel, const Vec2f& pos, KyUInt32 sectionIdx, bool* posCloseToSegmentInSection);
112 
113  static CircleArcCanGoResult InitCircleArcCanGo_InSection(const Channel* channel, const CWCircleArc& cwCircleArc, SectionData& currentSectionData);
114  static CircleArcCanGoResult InitCircleArcCanGo_GenericForPolylineSection(const CircleArcCanGoInChannel::CWCircleArc& cwCircleArc,
115  const SectionData& currentSectionData, const KyArray<Vec2f>& polyline);
116 
117  static CircleArcCanGoResult ProcessNextSectionAlongArc(const Channel* channel, const CWCircleArc& cwCircleArc, SectionData& currentSectionData,
118  KyUInt32 nextSectionIdx, CircleArcCanGoResult previousResult);
119  static CircleArcCanGoResult ProcessNextSectionAlongArc_InSection(const Channel* channel, const CWCircleArc& cwCircleArc, SectionData& currentSectionData, KyUInt32 currentSectionIdx, CircleArcCanGoResult previousResult);
120  static CircleArcCanGoResult ProcessNextSectionAlongArc_GenericForPolylineSection(const CWCircleArc& cwCircleArc, const SectionData& currentSectionData,
121  const KyArray<Vec2f>& polyline);
122 
123  static bool IsArcTangenteAlmostColinearWithSegment(const Vec2f& segmentStart, const Vec2f& segmentEnd, const Vec2f& center, const Vec2f& arcStart);
124  static bool DoesCircleArcIntersectPolyline(const KyArray<Vec2f>& polyline, const Vec2f& circleCenter, KyFloat32 radius,
125  const Vec2f& circleArcStart, const Vec2f& circleArcEnd);
126  static bool DoesArcGoAwayFromSegment(const SegmentVsCircleData& segmentData, const CWCircleArc& cwCircleArc);
127  static bool IsArcEndBetweenArcStartAndExitPos(const CWCircleArc& cwCircleArc, const SegmentVsCircleData& segmentData, KyUInt32 segmentIdx);
128  static void InitSectionData(const Channel* channel, const CWCircleArc& cwCircleArc, KyUInt32 currentSectionIdx,
129  SectionData& currentSectionData, KyUInt32& segmentCount);
130  static void UpdateSectionData(const Channel* channel, const CWCircleArc& cwCircleArc, KyUInt32 newSectionIdx,
131  SectionData& currentSectionData, KyUInt32& segmentCount);
132 };
133 
134 
135 } // namespace Kaim
136 
137 #endif
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
unsigned char KyUInt8
Type used internally to represent an unsigned 8-bit integer.
Definition: types.h:41
Definition: gamekitcrowddispersion.h:20
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