gwnavruntime/channel/circlearccangoinchannel.h Source File

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