gwnavruntime/channel/bubble.h Source File

bubble.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 
14 
15 namespace Kaim
16 {
17 
18 class DisplayList;
19 class BubbleBlob;
20 
23 {
24  UndefinedBubbleType,
25  StartBubble,
26  EndBubble,
27  IntermediaryBubble
28 };
29 
31 class Bubble
32 {
33 public:
34  Bubble();
35  Bubble(const Vec3f& center, KyFloat32 radius, RotationDirection rotationDirection, BubbleType type = UndefinedBubbleType);
36 
37  void Reset();
38  void Set(const Vec3f& center, KyFloat32 radius, RotationDirection rotationDirection, BubbleType type = UndefinedBubbleType);
39 
40  void InitFromBlob(const BubbleBlob& blob);
41 
42  void SetCenter(const Vec3f& center);
43  void SetRadius(KyFloat32 radius);
44  void SetRotationDirection(RotationDirection rotationDirection);
45  void SetType(BubbleType type);
46 
47  void SetCenterAltitude(KyFloat32 newCenterAltitude);
48 
49  const Vec3f& GetCenter() const;
50  KyFloat32 GetRadius() const;
51  RotationDirection GetRotationDirection() const;
52  BubbleType GetType() const;
53  FunnelSide GetFunnelSide() const;
54 
55  bool IsInitialized() const;
56 
59  KyResult ComputeBiTangentDirection(const Bubble& arrivalBubble, Vec2f& biTangentDir) const;
60 
63  KyResult ComputeBiTangent(const Bubble& arrivalBubble, Vec2f& biTangentStart, Vec2f& biTangentEnd, Vec2f& biTangentNormalizedDir) const;
64  KyResult ComputeBiTangent(const Bubble& arrivalBubble, Vec2f& biTangentStart, Vec2f& biTangentEnd) const;
65 
69  KyResult ComputeBiTangent(const Bubble& arrivalBubble, Vec3f& biTangentStart, Vec3f& biTangentEnd, Vec2f& biTangentNormalizedDir) const;
70  KyResult ComputeBiTangent(const Bubble& arrivalBubble, Vec3f& biTangentStart, Vec3f& biTangentEnd) const;
71 
73  KyResult ComputeBiTangentBubble(const Vec3f& tangencyPosition, const Bubble& secondBubble, Vec3f& tangencyPositionOnSecondBubble, Bubble& biTangentBubble) const;
74 
76  KyResult ComputeTangentBubble(const Vec3f& tangencyPosition, const Vec3f& position, Bubble& tangentBubble) const;
77 
79  void ComputeMedianTurnAxisAndPoint(const Vec2f& entryDir, const Vec2f& exitDir, Vec2f &medianTurnAxis, Vec3f& midPoint) const;
80 
81  void Display(DisplayList& displayList, KyUInt32 subdivisionCount = 36) const;
82 
83  bool operator==(const Bubble& other) const;
84 
85  void DisplayDirOnBubble(const Vec2f& dir, DisplayList& displayList, Color color, KyFloat32 length) const;
86 
87 private:
88  Vec3f m_center;
89  KyFloat32 m_radius;
90  RotationDirection m_rotationDirection;
91  BubbleType m_type;
92 };
93 
94 KY_INLINE Bubble::Bubble() { Reset(); }
95 KY_INLINE Bubble::Bubble(const Vec3f& center, KyFloat32 radius, RotationDirection rotationDirection, BubbleType type)
96 {
97  Set(center, radius, rotationDirection, type);
98 }
99 KY_INLINE void Bubble::Reset()
100 {
101  Set(Vec3f::Zero(), 0.0f, UninitializedRotationDirection, UndefinedBubbleType);
102 }
103 KY_INLINE void Bubble::Set(const Vec3f& center, KyFloat32 radius, RotationDirection rotationDirection, BubbleType type)
104 {
105  SetCenter(center);
106  SetRadius(radius);
107  SetRotationDirection(rotationDirection);
108  SetType(type);
109 }
110 
111 KY_INLINE void Bubble::SetCenter(const Vec3f& center) { m_center = center; }
112 KY_INLINE void Bubble::SetRadius(KyFloat32 radius) { m_radius = radius; }
113 KY_INLINE void Bubble::SetRotationDirection(RotationDirection rotationDirection) { m_rotationDirection = rotationDirection; }
114 KY_INLINE void Bubble::SetType(BubbleType type) { m_type = type; }
115 KY_INLINE void Bubble::SetCenterAltitude(KyFloat32 newCenterAltitude) { m_center.z = newCenterAltitude; }
116 
117 KY_INLINE const Vec3f& Bubble::GetCenter() const { return m_center; }
118 KY_INLINE KyFloat32 Bubble::GetRadius() const { return m_radius; }
119 KY_INLINE RotationDirection Bubble::GetRotationDirection() const { return m_rotationDirection; }
120 KY_INLINE BubbleType Bubble::GetType() const { return m_type; }
121 
122 KY_INLINE bool Bubble::IsInitialized() const { return m_rotationDirection != UninitializedRotationDirection; }
123 
124 KY_INLINE KyResult Bubble::ComputeBiTangent(const Bubble& arrivalBubble, Vec2f& biTangentStart, Vec2f& biTangentEnd) const
125 {
126  Vec2f unused;
127  return ComputeBiTangent(arrivalBubble, biTangentStart, biTangentEnd, unused);
128 }
129 KY_INLINE FunnelSide Bubble::GetFunnelSide() const
130 {
131  if (m_type != IntermediaryBubble)
132  return FunnelBothSides;
133 
134  return (
135  (m_rotationDirection == Clockwise ) ? FunnelRight :
136  (m_rotationDirection == CounterClockwise) ? FunnelLeft :
137  UndefinedFunnelSide);
138 }
139 KY_INLINE KyResult Bubble::ComputeBiTangent(const Bubble& arrivalBubble, Vec3f& biTangentStart, Vec3f& biTangentEnd) const
140 {
141  Vec2f unused;
142  return ComputeBiTangent(arrivalBubble, biTangentStart, biTangentEnd, unused);
143 }
144 
145 inline bool Bubble::operator==(const Bubble& other) const
146 {
147  return
148  m_center == other.m_center &&
149  m_radius == other.m_radius &&
150  m_rotationDirection == other.m_rotationDirection &&
151  m_type == other.m_type ;
152 }
153 
154 
155 
156 template <class OSTREAM>
157 inline OSTREAM& operator<<(OSTREAM& os, const Bubble& bubble)
158 {
159  os << "center=" << bubble.GetCenter() << " radius=" << bubble.GetRadius() << " direction=" << GetRotationDirectionLabel(bubble.GetRotationDirection());
160  return os;
161 }
162 
163 } // namespace Kaim
164 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
KyResult ComputeBiTangentBubble(const Vec3f &tangencyPosition, const Bubble &secondBubble, Vec3f &tangencyPositionOnSecondBubble, Bubble &biTangentBubble) const
Computes the Bubble tangent to this Bubble at the provided position and tangent to arrivalBubble...
Definition: bubble.cpp:74
KyResult ComputeBiTangent(const Bubble &arrivalBubble, Vec2f &biTangentStart, Vec2f &biTangentEnd, Vec2f &biTangentNormalizedDir) const
Computes the segment starting from this Bubble and arriving on arrivalBubble, tangent to both Bubbles...
Definition: bubble.cpp:46
static Vec3f Zero()
Returns {0.0f, 0.0f, 0.0f}.
Definition: vec3f.h:99
KyResult ComputeTangentBubble(const Vec3f &tangencyPosition, const Vec3f &position, Bubble &tangentBubble) const
Computes the Bubble tangent to this Bubble at the provided tangencyPosition and passing through an ar...
Definition: bubble.cpp:215
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:15
BubbleType
Defines the type of a bubble accordingly to the place it has in a BubbleArray, a BubbleList, etc.
Definition: bubble.h:22
This class represents a circle with potential rotation limitation.
Definition: bubble.h:31
2d vector using KyFloat32.
Definition: vec2f.h:18
DisplayList is used to push text, lines or shapes for rendering in the NavigationLab e...
Definition: displaylist.h:128
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
RGBA color.
Definition: color.h:16
KyResult ComputeBiTangentDirection(const Bubble &arrivalBubble, Vec2f &biTangentDir) const
Computes the normalized direction of the segment starting from this Bubble and arriving on arrivalBub...
Definition: bubble.cpp:21
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
void ComputeMedianTurnAxisAndPoint(const Vec2f &entryDir, const Vec2f &exitDir, Vec2f &medianTurnAxis, Vec3f &midPoint) const
Computes median turn axis and position accordingly to provided entry and exit axis.
Definition: bubble.cpp:267