gwnavruntime/channel/funnel.h Source File

funnel.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 
11 
12 namespace Kaim
13 {
14 
15 enum FunnelDirection
16 {
17  ForwardFunnel,
18  BackwardFunnel
19 };
20 
21 enum FunnelResult
22 {
23  FunnelError, // The funnel failed to update with the last provided corner.
24  FunnelIgnored, // The last provided corner has been ignored (e.g. it lays inside the apex bubble).
25  FunnelUnchanged, // The last provided corner did not change the funnel (e.g. a right corner on the right of the current left-most right corner).
26  FunnelTightened, // The last provided corner has tighten the funnel (e.g. a right corner that lay on the left of the former left-most right corner and on the right of the current right-most left corner, that is now the new left-most right corner).
27  FunnelClosedOverRight, // The last provided corner has closed the funnel over its left-most right corner.
28  FunnelClosedOverLeft // The last provided corner has closed the funnel over its right-most left corner.
29 };
30 KY_INLINE static bool IsClosureCase(FunnelResult result) { return ((result == FunnelClosedOverRight) || (result == FunnelClosedOverLeft)); }
31 
32 enum FunnelSide
33 {
34  UndefinedFunnelSide,
35  FunnelLeft,
36  FunnelRight,
37  FunnelBothSides // start and end corners are collapsed and impact both sides of the funnel.
38 };
39 
40 
42 class Funnel
43 {
44 public:
45  Funnel()
46  : m_apexIdx(0)
47  , m_leftCornerIdx(0)
48  , m_rightCornerIdx(0)
49  , m_apexSide(UndefinedFunnelSide)
50  , m_funnelDirection(ForwardFunnel)
51  , m_previousResult(FunnelUnchanged)
52  , m_isLeftBorderInitialized(false)
53  , m_isRightBorderInitialized(false)
54  {}
55 
56  void Initialize(KyUInt32 apexIdx, FunnelSide apexSide, FunnelDirection funnelDirection = ForwardFunnel);
57  FunnelResult Update(const Vec2f& vecToCorner, KyUInt32 idx, FunnelSide side);
58 
59  FunnelDirection GetFunnelDirection() const { return m_funnelDirection; }
60  KyUInt32 GetApexIdx() const { return m_apexIdx; }
61  FunnelSide GetApexSide() const { return m_apexSide; }
62  KyUInt32 GetLeftCornerIdx() const { return m_leftCornerIdx; }
63  KyUInt32 GetRightCornerIdx() const { return m_rightCornerIdx; }
64  FunnelResult GetPreviousResult() const { return m_previousResult; }
65 
66 private:
67  void TightenLeftBorder(const Vec2f& vecToCorner, KyUInt32 cornerIdx);
68  void TightenRightBorder(const Vec2f& vecToCorner, KyUInt32 cornerIdx);
69 
70  bool IsOutsideOnLeft(const Vec2f& axis2d) const;
71  bool IsOutsideOnRight(const Vec2f& axis2d) const;
72 
73  void ResolveActualClosureCase(FunnelResult naturalClosure);
74 
75 
76 private:
77  Vec2f m_vec2dToLeft;
78  Vec2f m_vec2dToRight;
79 
80  KyUInt32 m_apexIdx;
81  KyUInt32 m_leftCornerIdx;
82  KyUInt32 m_rightCornerIdx;
83 
84  FunnelSide m_apexSide;
85  FunnelDirection m_funnelDirection;
86 
87  FunnelResult m_previousResult;
88 
89  bool m_isLeftBorderInitialized;
90  bool m_isRightBorderInitialized;
91 };
92 
93 
94 KY_INLINE FunnelSide GetFunnelSideFromRotationDirection(RotationDirection rotDir)
95 {
96  return (
97  (rotDir == Clockwise ) ? FunnelRight :
98  (rotDir == CounterClockwise) ? FunnelLeft :
99  UndefinedFunnelSide);
100 }
101 
102 
103 } // namespace Kaim
104 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:15
2d vector using KyFloat32.
Definition: vec2f.h:18
Basic straight line funnel acting directly on 2D positions.
Definition: funnel.h:42
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17