gwnavruntime/path/positiononpath.h Source File

positiononpath.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 
8 #pragma once
9 
10 #include "gwnavruntime/path/path.h"
12 
13 namespace Kaim
14 {
15 
18 {
22 };
23 
24 
30 {
31  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Path)
32 
33 public:
34  // ---------------------------------- Main API Functions ----------------------------------
35 
36  PositionOnPath() : m_onPathStatus(PositionOnPathStatus_Undefined), m_currentIndexOnPath(KyUInt32MAXVAL), m_distanceToEndOfPath(0.0f), m_mustUpdateDistanceInternalState(true) {}
37 
38  bool operator==(const PositionOnPath& positionOnPath) const;
39  bool operator!=(const PositionOnPath& other) const { return !(*this == other); }
40 
41  void InitOnPathNode(Path* path, KyUInt32 pathNodeIdx);
42  void InitOnPathFirstNode(Path* path) { InitOnPathNode(path, 0); }
43  void InitOnPathLastNode(Path* path);
44  void InitOnPathEdge(Path* path, const Vec3f& positionOnEdge, KyUInt32 pathEdgeIdx);
45 
46  void Clear();
47 
48  bool IsValid() const { return m_onPathStatus != PositionOnPathStatus_Undefined && m_path != nullptr && m_currentIndexOnPath < m_path->GetNodeCount(); }
49 
50  bool IsAtFirstNodeOfPath() const { return m_onPathStatus == PositionOnPathStatus_OnPathNode && m_currentIndexOnPath == 0; }
51  bool IsAtLastNodeOfPath() const { return m_onPathStatus == PositionOnPathStatus_OnPathNode && m_currentIndexOnPath + 1 == m_path->GetNodeCount(); }
52  bool IsAtFirstEdgeOfPath() const { return m_onPathStatus != PositionOnPathStatus_Undefined && m_currentIndexOnPath == 0; }
53 
54  bool IsAtLastEdgeOfPath() const { return IsAtLastNodeOfPath() || (m_onPathStatus == PositionOnPathStatus_OnPathEdge && m_currentIndexOnPath + 1 == m_path->GetEdgeCount()); }
55 
56  bool IsAtLastNodeOfAChannel() const;
57 
58  Path* GetPath() const { return m_path; }
59 
60  const Vec3f& GetPosition() const { return m_position; }
61 
62  PositionOnPathStatus GetPositionOnPathStatus() const { return m_onPathStatus; }
63 
64  KyFloat32 GetRemainingDistanceToEndOfPath() const { return m_distanceToEndOfPath; }
65 
67  PathEdgeType GetPathEdgeType() const { return m_path->GetPathEdgeType(GetPathEdgeIndex()); }
68 
70  PathEdgeType GetEdgeTypeToMoveOnForward() const { return m_path->GetPathEdgeType(GetEdgeIdxToMoveOnForward()); }
71 
73  PathEdgeType GetEdgeTypeToMoveOnBackward() const { return m_path->GetPathEdgeType(GetEdgeIdxToMoveOnBackward()); }
74 
77  bool DoesPrecede(const PositionOnPath& other) const;
78 
81  bool IsStrictlyBefore(const PositionOnPath& other) const;
82 
83 
84  // ---------------------------------- Path Edge Functions ----------------------------------
85 
91  KyUInt32 GetPathEdgeIndex() const;
92 
98 
104 
105  // ---------------------------------- Move Functions ----------------------------------
106 
110  void MoveForward(KyFloat32 distanceMove);
111 
115  void MoveBackward(KyFloat32 distanceMove);
116 
124 
132 
137 
142 
149 
156 
157 
160  KyFloat32 ComputeDistance(const PositionOnPath& otherPositionOnPath) const;
161 
162 
165  KyFloat32 MoveForwardToClosestPositionOnPath(const Vec3f& originalPosition, const PositionOnPath* upToPosOnPath = nullptr);
166 
167  // ---------------------------------- Unsafe Version of Functions ----------------------------------
169 
170  // cf. MoveForward_StopAtPathNode
172  // cf. MoveBackward_StopAtPathNode
173  KyFloat32 MoveBackward_StopAtPathNode_Unsafe(KyFloat32 distanceMove);
174  // cf. MoveForwardToNextPathNode
175  void MoveForwardToNextPathNode_Unsafe();
176  // cf. MoveBackwardToPrevPathNode
177  void MoveBackwardToPrevPathNode_Unsafe();
178  // cf. MoveForwardToNextPathEdge
179  void MoveForwardToNextPathEdge_Unsafe();
180  // cf. MoveBackwardToPrevPathEdge
181  void MoveBackwardToPrevPathEdge_Unsafe();
182 
183 private:
184  KyFloat32 ComputeDistanceToEndOfPathFromPathEdge(KyUInt32 pathEdgeIdx, const Vec3f& positionOnEdge) const;
185  KyFloat32 ComputeDistanceToEndOfPathFromPathNode(KyUInt32 pathNodeIdx) const;
186  KyFloat32 ComputeDistance(KyUInt32 fromPathNodeIdx, KyUInt32 toPathNodeIdx) const;
187 
188  void ClampOnCurrentPathEdge(const Kaim::Vec3f& originalPosition);
189 
190 public: // internal
191  void GetRawValues(Path*& path, Vec3f& position, PositionOnPathStatus& onPathStatus, KyUInt32& currentIndexOnPath, KyFloat32& distanceToEndOfPath) const
192  {
193  path = m_path;
194  position = m_position;
195  onPathStatus = m_onPathStatus;
196  currentIndexOnPath = m_currentIndexOnPath;
197  distanceToEndOfPath = m_distanceToEndOfPath;
198  }
199  void SetRawValues(Path* path, const Vec3f& position, PositionOnPathStatus onPathStatus, KyUInt32 currentIndexOnPath, KyFloat32 distanceToEndOfPath)
200  {
201  m_path = path;
202  m_position = position;
203  m_onPathStatus = onPathStatus;
204  m_currentIndexOnPath = currentIndexOnPath;
205  m_distanceToEndOfPath = distanceToEndOfPath;
206  }
207 
208 private:
209  Ptr<Path> m_path;
210  Vec3f m_position;
211 
212  PositionOnPathStatus m_onPathStatus;
213  KyUInt32 m_currentIndexOnPath; // index on the Path edge or index of the Path node. position is on ]EdgeStart, EdgeEnd]
214 
215  KyFloat32 m_distanceToEndOfPath; // Maintained informatively, ie.e it is not used to differentiate two PositionOnPath instances.
216  bool m_mustUpdateDistanceInternalState; // Internal state used to prevent some useless computations of m_distanceToEndOfPath in some functions.
217 };
218 
219 } // namespace Kaim
220 
221 
223 
PathEdgeType GetEdgeTypeToMoveOnForward() const
return the type of the edge given by GetEdgeIdxToMoveOnForward()
Definition: positiononpath.h:70
KyUInt32 GetPathEdgeIndex() const
This function has to be used carefully:
Definition: positiononpath.inl:10
KyUInt32 GetEdgeIdxToMoveOnForward() const
If this in on a Path node, it returns the index of the edge starting at this Path node...
Definition: positiononpath.inl:20
This class aggregates all necessary information about a position on a Path.
Definition: positiononpath.h:29
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
void MoveBackwardToPrevPathEdge()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:74
PositionOnPathStatus
< enumerates="" the="" different="" status="" an="" objectpositiononpath="" can="" have="" on="" its="" path.="" />
Definition: positiononpath.h:17
KyUInt32 GetEdgeIdxToMoveOnBackward() const
If this in on a Path node, it returns the index of the edge ending at this Path node, else it returns the index of the edge current instance lies on.
Definition: positiononpath.h:103
bool IsStrictlyBefore(const PositionOnPath &other) const
Returns true when this PositionOnPath strictly precede the other one; returns false if it as as the s...
Definition: positiononpath.cpp:236
The PositionOnPath is on a Path node.
Definition: positiononpath.h:20
The PositionOnPath is on a Path edge.
Definition: positiononpath.h:21
PathEdgeType GetPathEdgeType() const
This function has to be used carefully, cf. GetPathEdgeIndex()
Definition: positiononpath.h:67
void MoveForward(KyFloat32 distanceMove)
Main distance-based forward move method: moves the position along distanceMove meters measured on the...
Definition: positiononpath.cpp:281
void MoveBackward(KyFloat32 distanceMove)
Main distance-based backward move method: moves the position along distanceMove meters measured on th...
Definition: positiononpath.cpp:304
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The PositionOnPath is not yet defined.
Definition: positiononpath.h:19
PathEdgeType GetEdgeTypeToMoveOnBackward() const
return the type of the edge given by GetEdgeIdxToMoveOnBackward()
Definition: positiononpath.h:73
void MoveForwardToNextPathNode()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:56
KyFloat32 MoveForwardToClosestPositionOnPath(const Vec3f &originalPosition, const PositionOnPath *upToPosOnPath=nullptr)
Move forward to the closest position on path from originalPosition.
Definition: positiononpath.cpp:126
KyFloat32 MoveForward_StopAtPathNode_Unsafe(KyFloat32 distanceMove)
These functions are unsafe in regard to the pre-conditions mentioned in the functions of similar name...
Definition: positiononpath.cpp:422
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyFloat32 ComputeDistance(const PositionOnPath &otherPositionOnPath) const
Return the distance along the Path from/to the other position.
Definition: positiononpath.cpp:99
KyFloat32 MoveBackward_StopAtPathNode(KyFloat32 distanceMove)
Atomic move method: moves backward the position on the current Path edge it lays on, up to distanceMove meters.
Definition: positiononpath.inl:49
void MoveBackwardToPrevPathNode()
Atomic backward move method: must be used with lot of care.
Definition: positiononpath.inl:62
void MoveForwardToNextPathEdge()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:68
bool DoesPrecede(const PositionOnPath &other) const
Returns true when this PositionOnPath precede or is at same position that the other one...
Definition: positiononpath.cpp:192
KyFloat32 MoveForward_StopAtPathNode(KyFloat32 distanceMove)
Atomic move method: moves forward the position on the current Path edge it lays on, up to distanceMove meters.
Definition: positiononpath.inl:42
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
The class representing a path.
Definition: path.h:62
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16