gwnavruntime/path/positiononpath.h Source File

positiononpath.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 
8 // primary contact: LAPA - secondary contact: JUBA
9 
10 #ifndef Navigation_PositionOnPath_H
11 #define Navigation_PositionOnPath_H
12 
13 #include "gwnavruntime/path/path.h"
15 
16 namespace Kaim
17 {
18 
21 {
25 };
26 
27 
34 {
35  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Path)
36 
37 public:
38  // ---------------------------------- Main API Functions ----------------------------------
39 
41 
42  bool operator==(const PositionOnPath& positionOnPath) const;
43  bool operator!=(const PositionOnPath& positionOnPath) const;
44 
45  void InitOnPathNode (Path* path, KyUInt32 pathNodeIdx);
46  void InitOnPathFirstNode(Path* path);
47  void InitOnPathLastNode (Path* path);
48  void InitOnPathEdge (Path* path, const Vec3f& positionOnEdge, KyUInt32 pathEdgeIdx);
49  void Clear();
50  bool IsValid() const;
51 
52  bool IsAtFirstNodeOfPath() const;
53  bool IsAtLastNodeOfPath() const;
54  bool IsAtFirstEdgeOfPath() const;
55  bool IsAtLastEdgeOfPath() const;
56  bool IsAtLastNodeOfAChannel() const;
57  Path* GetPath() const;
58  const Vec3f& GetPosition() const;
59  PositionOnPathStatus GetPositionOnPathStatus() const;
60  KyFloat32 GetRemainingDistanceToEndOfPath() const;
61 
64 
67 
70 
73  bool DoesPrecede(const PositionOnPath& other) const;
74 
77  bool IsStrictlyBefore(const PositionOnPath& other) const;
78 
79 
80  // ---------------------------------- Path Edge Functions ----------------------------------
81 
87  KyUInt32 GetPathEdgeIndex() const;
88 
94 
100 
101 
102  // ---------------------------------- Move Functions ----------------------------------
103 
107  void MoveForward(KyFloat32 distanceMove);
108 
112  void MoveBackward(KyFloat32 distanceMove);
113 
121 
129 
134 
139 
146 
153 
154 
157  KyFloat32 ComputeDistance(const PositionOnPath& otherPositionOnPath) const;
158 
159 
162  KyFloat32 MoveForwardToClosestPositionOnPath(const Vec3f& originalPosition, const PositionOnPath* upToPosOnPath = KY_NULL);
163 
164  // ---------------------------------- Unsafe Version of Functions ----------------------------------
166 
167  // cf. MoveForward_StopAtPathNode
168  KyFloat32 MoveForward_StopAtPathNode_Unsafe(KyFloat32 distanceMove);
169  // cf. MoveBackward_StopAtPathNode
170  KyFloat32 MoveBackward_StopAtPathNode_Unsafe(KyFloat32 distanceMove);
171  // cf. MoveForwardToNextPathNode
172  void MoveForwardToNextPathNode_Unsafe();
173  // cf. MoveBackwardToPrevPathNode
174  void MoveBackwardToPrevPathNode_Unsafe();
175  // cf. MoveForwardToNextPathEdge
176  void MoveForwardToNextPathEdge_Unsafe();
177  // cf. MoveBackwardToPrevPathEdge
178  void MoveBackwardToPrevPathEdge_Unsafe();
179 
180 private:
181  KyFloat32 ComputeDistanceToEndOfPathFromPathEdge(KyUInt32 pathEdgeIdx, const Vec3f& positionOnEdge) const;
182  KyFloat32 ComputeDistanceToEndOfPathFromPathNode(KyUInt32 pathNodeIdx) const;
183  KyFloat32 ComputeDistance(KyUInt32 fromPathNodeIdx, KyUInt32 toPathNodeIdx) const;
184 
185  void ClampOnCurrentPathEdge(const Kaim::Vec3f& originalPosition);
186 
187 public: // internal
188  void GetRawValues(Path*& path, Vec3f& position, PositionOnPathStatus& onPathStatus, KyUInt32& currentIndexOnPath, KyFloat32& distanceToEndOfPath) const
189  {
190  path = m_path;
191  position = m_position;
192  onPathStatus = m_onPathStatus;
193  currentIndexOnPath = m_currentIndexOnPath;
194  distanceToEndOfPath = m_distanceToEndOfPath;
195  }
196  void SetRawValues(Path* path, const Vec3f& position, PositionOnPathStatus onPathStatus, KyUInt32 currentIndexOnPath, KyFloat32 distanceToEndOfPath)
197  {
198  m_path = path;
199  m_position = position;
200  m_onPathStatus = onPathStatus;
201  m_currentIndexOnPath = currentIndexOnPath;
202  m_distanceToEndOfPath = distanceToEndOfPath;
203  }
204 
205 private:
206  Ptr<Path> m_path;
207  Vec3f m_position;
208 
209  PositionOnPathStatus m_onPathStatus;
210  KyUInt32 m_currentIndexOnPath; // index on the Path edge or index of the Path node. position is on ]EdgeStart, EdgeEnd]
211 
212  KyFloat32 m_distanceToEndOfPath; // Maintained informatively, ie.e it is not used to differentiate two PositionOnPath instances.
213  bool m_mustUpdateDistanceInternalState; // Internal state used to prevent some useless computations of m_distanceToEndOfPath in some functions.
214 };
215 
216 } // namespace Kaim
217 
218 
220 
221 #endif // Navigation_PositionOnPath_H
PathEdgeType GetEdgeTypeToMoveOnForward() const
return the type of the edge given by GetEdgeIdxToMoveOnForward()
Definition: positiononpath.inl:52
KyUInt32 GetPathEdgeIndex() const
This function has to be used carefully:
Definition: positiononpath.inl:23
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:34
This class aggregates all necessary information about a position on a Path, namely: ...
Definition: positiononpath.h:33
void MoveBackwardToPrevPathEdge()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:107
PositionOnPathStatus
< enumerates="" the="" different="" status="" an="" objectpositiononpath="" can="" have="" on="" its="" path.="" />
Definition: positiononpath.h:20
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.inl:42
bool IsStrictlyBefore(const PositionOnPath &other) const
Returns true when this PositionOnPath strictly precede the other one; returns false if it as as the s...
The PositionOnPath is on a Path node.
Definition: positiononpath.h:23
#define KY_NULL
Null value.
Definition: types.h:247
The PositionOnPath is on a Path edge.
Definition: positiononpath.h:24
PathEdgeType GetPathEdgeType() const
This function has to be used carefully, cf. GetPathEdgeIndex()
Definition: positiononpath.inl:50
void MoveForward(KyFloat32 distanceMove)
Main distance-based forward move method: moves the position along distanceMove meters measured on the...
void MoveBackward(KyFloat32 distanceMove)
Main distance-based backward move method: moves the position along distanceMove meters measured on th...
The PositionOnPath is not yet defined.
Definition: positiononpath.h:22
PathEdgeType GetEdgeTypeToMoveOnBackward() const
return the type of the edge given by GetEdgeIdxToMoveOnBackward()
Definition: positiononpath.inl:53
void MoveForwardToNextPathNode()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:89
Definition: gamekitcrowddispersion.h:20
KyFloat32 ComputeDistance(const PositionOnPath &otherPositionOnPath) const
Return the distance along the Path from/to the other position.
KyFloat32 MoveForwardToClosestPositionOnPath(const Vec3f &originalPosition, const PositionOnPath *upToPosOnPath=0)
Move forward to the closest position on path from originalPosition.
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:82
void MoveBackwardToPrevPathNode()
Atomic backward move method: must be used with lot of care.
Definition: positiononpath.inl:95
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
void MoveForwardToNextPathEdge()
Atomic forward move method: must be used with lot of care.
Definition: positiononpath.inl:101
PathEdgeType
Defines the different kind of PathEdge within a Path.
Definition: path.h:26
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
bool DoesPrecede(const PositionOnPath &other) const
Returns true when this PositionOnPath precede or is at same position that the other one...
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:75
The class representing a path.
Definition: path.h:42
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