gwnavruntime/pathfollower/circlearcsplinesection.h Source File

circlearcsplinesection.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 // primary contact: LAPA - secondary contact: NOBODY
8 #ifndef Navigation_CircleArcSplineSection_H
9 #define Navigation_CircleArcSplineSection_H
10 
11 
14 
15 
16 namespace Kaim
17 {
18 
19 class CircleArcSplineSectionBlob;
20 class CircleArcSplineSectionDisplayConfig;
21 
22 
26 {
27  static const KyFloat32 SmallLengthThreshold;
28 
29 public:
32  : m_startSectionIdx(KyUInt32MAXVAL)
33  , m_endSectionIdx(KyUInt32MAXVAL)
34  , m_length2d(0.0f)
35  {}
36 
38  CircleArcSplineSection(const Bubble& bubble, const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx,
39  const Vec2f& startTangent = Vec2f::Zero(), const Vec2f& endTangent = Vec2f::Zero());
40 
42  CircleArcSplineSection(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& dir2d = Vec2f::Zero());
43 
44 
45  void InitFromBlob(const CircleArcSplineSectionBlob* blob);
46 
47  void Reset();
48 
49  const Bubble& GetBubble() const { return m_bubble; }
50  const Vec3f& GetStartPosition() const { return m_startPosition; }
51  const Vec3f& GetEndPosition() const { return m_endPosition; }
52  KyUInt32 GetStartSectionIdx() const { return m_startSectionIdx; }
53  KyUInt32 GetEndSectionIdx() const { return m_endSectionIdx; }
54  KyFloat32 GetLength2d() const { return m_length2d; }
55  const Vec2f& GetStartTangent() const { return m_startTangent; }
56  const Vec2f& GetEndTangent() const { return m_endTangent; }
57 
58  const Vec3f& GetCenter() const { return m_bubble.GetCenter(); }
59  KyFloat32 GetRadius() const { return m_bubble.GetRadius(); }
60  RotationDirection GetRotationDirection() const { return m_bubble.GetRotationDirection(); }
61 
62  bool IsInitialized() const { return (m_length2d > 0.0f); }
63  bool IsASegment() const { return (GetRadius() == KyFloat32MAXVAL); }
64  bool IsCurve() const { return (GetRadius() != KyFloat32MAXVAL); }
65  bool IsSmall() const { return (m_length2d < SmallLengthThreshold); }
66 
69  void SetStartPosition(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec2f& startTangent);
70 
73  void SetEndPosition(const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& endTangent);
74 
77  Vec2f ComputeTangent(const Vec3f& position) const;
78 
82  void MoveTo(Vec3f& position, KyFloat32 distanceFromStart, Vec2f* tangent = KY_NULL) const;
83 
84 
85 public: // Internal
86  // The following functions directly or indirectly call GetAngleRad, that uses
87  // the time-consuming Acosf function. They are intended to be used with care.
88 
89  // Computes the angle between start position and the provided position seen
90  // from the bubble center.
91  // \pre This method asserts the CircleArcSplineSection is not a segment. Take care to check
92  // this before calling this method.
93  KyFloat32 ComputeAngleFromStart(const Vec3f& position) const;
94 
95  // Computes the 2d distance along the arc between start position and the
96  // provided position.
97  // When the arc is a segment, this distance can be negative (the position
98  // lays before the start).
99  // When the arc is curve, this distance is always positive or null.
100  KyFloat32 ComputeDistance2dFromStart(const Vec3f& position) const;
101 
102  // Computes the 2d distance along the arc between the provided position and
103  // end position.
104  // This distance can be negative (when the position lays after the end).
105  KyFloat32 ComputeDistance2dToEnd(const Vec3f& position) const;
106 
107  void Display(const CircleArcSplineSectionDisplayConfig& displayConfig, ScopedDisplayList& displayList_arc, ScopedDisplayList& displayList_extremities,
108  ScopedDisplayList& displayList_sectionIdx, ScopedDisplayList& displayList_radius) const;
109 
110 private:
111  void ComputeStartTangent();
112  void ComputeEndTangent();
113  void ComputeProperties();
114 
115 
116 private:
117  // Primary members, actually defining the CircleArcSplineSection.
118  Bubble m_bubble;
119 
120  Vec3f m_startPosition;
121  Vec3f m_endPosition;
122 
123  Vec2f m_startTangent;
124  Vec2f m_endTangent;
125 
126  KyUInt32 m_startSectionIdx;
127  KyUInt32 m_endSectionIdx;
128 
129  // Secondary members: useful values computed from the primary members.
130  KyFloat32 m_length2d;
131 };
132 
133 KY_INLINE CircleArcSplineSection::CircleArcSplineSection(const Bubble& bubble, const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& startTangent, const Vec2f& endTangent)
134 : m_bubble(bubble)
135 , m_startPosition(startPosition)
136 , m_endPosition(endPosition)
137 , m_startTangent(startTangent)
138 , m_endTangent(endTangent)
139 , m_startSectionIdx(startSectionIdx)
140 , m_endSectionIdx(endSectionIdx)
141 {
142  if (m_startTangent == Vec2f::Zero())
143  ComputeStartTangent();
144 
145  if (m_endTangent == Vec2f::Zero())
146  ComputeEndTangent();
147 
148  ComputeProperties();
149 }
150 
151 KY_INLINE CircleArcSplineSection::CircleArcSplineSection(const Vec3f& startPosition, KyUInt32 startSectionIdx, const Vec3f& endPosition, KyUInt32 endSectionIdx, const Vec2f& dir2d)
152 : m_bubble(startPosition, KyFloat32MAXVAL, UndefinedRotationDirection, UndefinedBubbleType)
153 , m_startPosition(startPosition)
154 , m_endPosition(endPosition)
155 , m_startTangent(dir2d)
156 , m_endTangent(dir2d)
157 , m_startSectionIdx(startSectionIdx)
158 , m_endSectionIdx(endSectionIdx)
159 {
160  if (m_startTangent == Vec2f::Zero())
161  {
162  ComputeStartTangent();
163  m_endTangent = m_startTangent;
164  }
165 
166  ComputeProperties();
167 }
168 
169 } // namespace Kaim
170 
171 #endif // Navigation_CircleArcSplineSection_H
void MoveTo(Vec3f &position, KyFloat32 distanceFromStart, Vec2f *tangent=0) const
Moves the provided position to the one on CircleArcSplineSection at the given distance from start pos...
#define KyFloat32MAXVAL
The maximum value that can be stored in the KyFloat32 variable type.
Definition: types.h:227
#define KY_NULL
Null value.
Definition: types.h:247
RotationDirection
Defines the 4 possible cases of possibly constrained rotation in the horizontal plane for a given ele...
Definition: rotation.h:20
void SetEndPosition(const Vec3f &endPosition, KyUInt32 endSectionIdx, const Vec2f &endTangent)
Sets end position related information.
This class represents a circle with potential rotation limitation.
Definition: bubble.h:35
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
Definition: gamekitcrowddispersion.h:20
Vec2f ComputeTangent(const Vec3f &position) const
Computes the tangent direction at the given position.
static Vec2f Zero()
Returns a vector of zero size: (0,0).
Definition: vec2f.h:154
void SetStartPosition(const Vec3f &startPosition, KyUInt32 startSectionIdx, const Vec2f &startTangent)
Sets start position related information.
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Class representing either an oriented circle arc or a straight line segment, to be aggregated into a ...
Definition: circlearcsplinesection.h:25
CircleArcSplineSection()
Creates an uninitialized CircleArcSplineSection.
Definition: circlearcsplinesection.h:32
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23