gwnavruntime/pathfollower/circlearcsplinesection.h Source File

circlearcsplinesection.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 
9 
12 
13 
14 namespace Kaim
15 {
16 
17 class CircleArcSplineSectionBlob;
18 class CircleArcSplineSectionDisplayConfig;
19 
20 
24 {
25  static const KyFloat32 SmallLengthThreshold;
26 
27 public:
30  : m_startSectionIdx(KyUInt32MAXVAL)
31  , m_endSectionIdx(KyUInt32MAXVAL)
32  , m_length2d(0.0f)
33  {}
34 
36  CircleArcSplineSection(const Bubble& bubble, const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx,
37  const Vec2f& startTangent = Vec2f::Zero(), const Vec2f& endTangent = Vec2f::Zero());
38 
40  CircleArcSplineSection(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& dir2d = Vec2f::Zero());
41 
42 
43  void InitFromBlob(const CircleArcSplineSectionBlob* blob);
44 
45  void Reset();
46 
47  const Bubble& GetBubble() const { return m_bubble; }
48  const Vec3f& GetStartPosition() const { return m_startPosition; }
49  const Vec3f& GetEndPosition() const { return m_endPosition; }
50  KyUInt32 GetStartSectionIdx() const { return m_startSectionIdx; }
51  KyUInt32 GetEndSectionIdx() const { return m_endSectionIdx; }
52  KyFloat32 GetLength2d() const { return m_length2d; }
53  const Vec2f& GetStartTangent() const { return m_startTangent; }
54  const Vec2f& GetEndTangent() const { return m_endTangent; }
55 
56  const Vec3f& GetCenter() const { return m_bubble.GetCenter(); }
57  KyFloat32 GetRadius() const { return m_bubble.GetRadius(); }
58  RotationDirection GetRotationDirection() const { return m_bubble.GetRotationDirection(); }
59 
60  bool IsInitialized() const { return (m_length2d > 0.0f); }
61  bool IsASegment() const { return (GetRadius() == KyFloat32MAXVAL); }
62  bool IsCurve() const { return (GetRadius() != KyFloat32MAXVAL); }
63  bool IsSmall() const { return (m_length2d < SmallLengthThreshold); }
64 
67  void SetStartPosition(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec2f& startTangent);
68 
71  void SetEndPosition(const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& endTangent);
72 
75  Vec2f ComputeTangent(const Vec3f& position) const;
76 
80  void MoveTo(Vec3f& position, KyFloat32 distanceFromStart, Vec2f* tangent = nullptr) const;
81 
82 
83 public: // internal
84  // The following functions directly or indirectly call GetAngleRad, that uses
85  // the time-consuming Acosf function. They are intended to be used with care.
86 
87  // Computes the angle between start position and the provided position seen
88  // from the bubble center.
89  // \pre This method asserts the CircleArcSplineSection is not a segment. Take care to check
90  // this before calling this method.
91  KyFloat32 ComputeAngleFromStart(const Vec3f& position) const;
92 
93  // Computes the 2d distance along the arc between start position and the
94  // provided position.
95  // When the arc is a segment, this distance can be negative (the position
96  // lays before the start).
97  // When the arc is curve, this distance is always positive or null.
98  KyFloat32 ComputeDistance2dFromStart(const Vec3f& position) const;
99 
100  // Computes the 2d distance along the arc between the provided position and
101  // end position.
102  // This distance can be negative (when the position lays after the end).
103  KyFloat32 ComputeDistance2dToEnd(const Vec3f& position) const;
104 
105  void Display(const CircleArcSplineSectionDisplayConfig& displayConfig, DisplayList& displayList_arc, DisplayList& displayList_extremities,
106  DisplayList& displayList_sectionIdx, DisplayList& displayList_radius) const;
107 
108 private:
109  void ComputeStartTangent();
110  void ComputeEndTangent();
111  void ComputeProperties();
112 
113 
114 private:
115  // Primary members, actually defining the CircleArcSplineSection.
116  Bubble m_bubble;
117 
118  Vec3f m_startPosition;
119  Vec3f m_endPosition;
120 
121  Vec2f m_startTangent;
122  Vec2f m_endTangent;
123 
124  KyUInt32 m_startSectionIdx;
125  KyUInt32 m_endSectionIdx;
126 
127  // Secondary members: useful values computed from the primary members.
128  KyFloat32 m_length2d;
129 };
130 
131 KY_INLINE CircleArcSplineSection::CircleArcSplineSection(const Bubble& bubble, const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& startTangent, const Vec2f& endTangent)
132 : m_bubble(bubble)
133 , m_startPosition(startPosition)
134 , m_endPosition(endPosition)
135 , m_startTangent(startTangent)
136 , m_endTangent(endTangent)
137 , m_startSectionIdx(startSectionIdx)
138 , m_endSectionIdx(endSectionIdx)
139 {
140  if (m_startTangent == Vec2f::Zero())
141  ComputeStartTangent();
142 
143  if (m_endTangent == Vec2f::Zero())
144  ComputeEndTangent();
145 
146  ComputeProperties();
147 }
148 
149 KY_INLINE CircleArcSplineSection::CircleArcSplineSection(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& dir2d)
150 : m_bubble(startPosition, KyFloat32MAXVAL, UndefinedRotationDirection, UndefinedBubbleType)
151 , m_startPosition(startPosition)
152 , m_endPosition(endPosition)
153 , m_startTangent(dir2d)
154 , m_endTangent(dir2d)
155 , m_startSectionIdx(startSectionIdx)
156 , m_endSectionIdx(endSectionIdx)
157 {
158  if (m_startTangent == Vec2f::Zero())
159  {
160  ComputeStartTangent();
161  m_endTangent = m_startTangent;
162  }
163 
164  ComputeProperties();
165 }
166 
167 } // namespace Kaim
168 
#define KyFloat32MAXVAL
KyFloat32 max value
Definition: types.h:71
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
void SetEndPosition(const Vec3f &endPosition, KyUInt32 endSectionIdx, const Vec2f &endTangent)
Sets end position related information.
Definition: circlearcsplinesection.cpp:121
This class represents a circle with potential rotation limitation.
Definition: bubble.h:31
2d vector using KyFloat32.
Definition: vec2f.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Vec2f ComputeTangent(const Vec3f &position) const
Computes the tangent direction at the given position.
Definition: circlearcsplinesection.cpp:135
void MoveTo(Vec3f &position, KyFloat32 distanceFromStart, Vec2f *tangent=nullptr) const
Moves the provided position to the one on CircleArcSplineSection at the given distance from start pos...
Definition: circlearcsplinesection.cpp:158
static Vec2f Zero()
Returns {0.0f, 0.0f}.
Definition: vec2f.h:93
void SetStartPosition(const Vec3f &startPosition, KyUInt32 startSectionIdx, const Vec2f &startTangent)
Sets start position related information.
Definition: circlearcsplinesection.cpp:107
Class representing either an oriented circle arc or a straight line segment, to be aggregated into a ...
Definition: circlearcsplinesection.h:23
CircleArcSplineSection()
Creates an uninitialized CircleArcSplineSection.
Definition: circlearcsplinesection.h:29
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16