gwnavruntime/queries/utils/rayqueryutils.h Source File

rayqueryutils.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: JUBA - secondary contact: NOBODY
9 #ifndef Navigation_RayQueryUtils_H
10 #define Navigation_RayQueryUtils_H
11 
17 
18 namespace Kaim
19 {
20 
21 class Box2f;
22 class NavTrianglePtr;
23 class NavTriangleRawPtr;
24 class NavHalfEdgePtr;
25 class NavHalfEdgeRawPtr;
26 class TriangleFromPosAndTriangleSeedQuery;
27 class WorldIntegerPos;
28 class LocalStoreActiveDataWorkspaceContext;
29 class RawNavTagSubSegment;
30 class WorkingMemory;
31 class Path;
32 template <class T> class WorkingMemArray;
33 
36 {
39 };
40 
41 class CompositeSubSegment
42 {
43 public:
44  CompositeSubSegment() {}
45  CompositeSubSegment(const Vec3f& startPos3f, const NavTriangleRawPtr& startTriangle, KyFloat32 costMultiplier)
46  {
47  m_rawNavTagSubSegment.m_navTriangleRawPtr = startTriangle;
48  m_rawNavTagSubSegment.m_entrancePos3f = startPos3f;
49  m_costMultiplierSubSegment.m_costMultiplier = costMultiplier;
50  m_costMultiplierSubSegment.m_entrancePos3f = startPos3f;
51  }
52 public:
53  RawNavTagSubSegment m_rawNavTagSubSegment;
54  CostMultiplierSubSegment m_costMultiplierSubSegment;
55 };
56 
58 class RayQueryUtils
59 {
61 public:
62  RayQueryUtils(const Vec3f& startPos3f, const Vec3f& destPos3f, void* traverseLogicUserData,
63  ScopedDynamicOutput& scopeAutoSaveDynamicOutput, DynamicOutputMode savingMode = QUERY_SAVE_NOTHING, KyFloat32 firstCostMultiplier = 1.f,
64  ComputeCostMode computeCostMode = QUERY_DO_NOT_COMPUTE_COST);
65 
66  KyResult StorePropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, CompositeSubSegment& subSegment,
67  const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob);
68 
69  template<class TraverseLogic>
70  KyResult StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr,
71  CompositeSubSegment& currentSubSegment, const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob, KyFloat32 nextCostMultiplier, KyFloat32& cost);
72 
73  KyInt32 GetFirstEdgeToCrossInStartTriangle(const NavTriangleRawPtr& startTriangleRawPtr, const CoordPos64& startCoordPos, const CoordPos64& destCoordPos);
74 
75  bool IsEdgeBeyondDestPos(const CoordPos64& cellOrigin, const NavFloorBlob& navFloorBlob, NavHalfEdgeIdx navHalfEdgeIdx,
76  const CoordPos64& segmentStartCoordPos, const CoordPos64& segmentDestCoordPos, const CoordPos64& destinationCoordPos, const KyInt64& startToDestSquareDist);
77 
78  void UpdateCostAlongAxis(const Vec3f& endOfCostMultiplierSegment, KyFloat32& cost);
79 
80  template<class TLogic>
81  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode = QUERY_DO_NOT_COMPUTE_COST)
82  {
83  return NeedToCommputeOrStoreDataFromCost(typename TLogic::CostMultiplierUsage(), dynamicOutputMode, computeCostMode);
84  }
85 
86  KyResult PushTriangleInDynamicOutput(DynamicOutputMode dynamicOutputMode, const NavTriangleRawPtr& startTriangleRawPtr);
87  static KyResult FinalizeLastSubSegment(DynamicOutputMode dynamicOutputMode, ScopedDynamicOutput& scopedDynamicOutput, const Vec3f& lastPos, CompositeSubSegment& subSegment);
88 protected:
89  KyResult StoreTriangle(const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr);
90  KyResult ComputeAndStoreEdgeIntersection(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, const CoordPos64& cellOrigin,
91  const NavFloorBlob* navFloorBlob, Vec3f& intersectionWithEdge);
92 
93  KyResult FinalizeAndStoreNavTagSubSegment(const Vec3f& intersectionWithEdge, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, RawNavTagSubSegment& navTagSubSegment);
94  KyResult FinalizeAndStoreCostMultiplerSubSegment(const Vec3f& intersectionWithEdge, KyFloat32 nextCostMultiplier, CostMultiplierSubSegment& costMultSubSegment);
95 
96  bool EdgeIsANavTagBoundary(const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, RawNavTagSubSegment& navTagSubSegment);
97 
98  void ComputeIntersectionWithEdge(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, const CoordPos64& cellOrigin,
99  const NavFloorBlob* navFloorBlob, Vec3f& intersection);
100 
101  KyResult StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr,
102  CompositeSubSegment& currentSubSegment, const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob, KyFloat32 nextCostMultiplier,
103  bool updateDataFromCostLimit, KyFloat32& cost);
104 
105  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithoutCostMultipler& , DynamicOutputMode, ComputeCostMode) { return false; }
106  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithCostMultiplerPerNavTag&, DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
107  {
108  return NeedToCommputeOrStoreDataFromCost_Impl(dynamicOutputMode, computeCostMode);
109  }
110  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithCostMultiplerPerTriangle&, DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
111  {
112  return NeedToCommputeOrStoreDataFromCost_Impl(dynamicOutputMode, computeCostMode);
113  }
114  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost_Impl(DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
115  {
116  return (dynamicOutputMode & QUERY_SAVE_COSTMULTIPLIERSUBSEGMENTS) != 0 || computeCostMode == QUERY_COMPUTE_COST_ALONG_3DAXIS;;
117  }
118 public:
119  Vec3f m_startPos3f;
120  Vec3f m_destPos3f;
121  void* m_traverseLogicUserData;
122 
123  DynamicOutputMode m_dynamicOutputMode;
124  ComputeCostMode m_computeCostMode;
125  ScopedDynamicOutput* m_scopedDynamicOutput;
126 
127  KyFloat32 m_dist3DOverSquareDist2d;
128  Vec3f m_currentCostMultiplierStartPos;
129  KyFloat32 m_currentCostMultiplier;
130 };
131 
132 template<class TLogic>
133 KY_INLINE KyResult RayQueryUtils::StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr,
134  CompositeSubSegment& currentSubSegment, const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob, KyFloat32 nextCostMultiplier, KyFloat32& cost)
135 {
136  bool updateDataFromCostLimit = NeedToCommputeOrStoreDataFromCost<TLogic>(m_dynamicOutputMode, m_computeCostMode);
137  return StoreOrComputeCostFromPropagationData(integerPrecision, currentPairHalfEdgeRawPtr, currentSubSegment,
138  cellOrigin,navFloorBlob, nextCostMultiplier, updateDataFromCostLimit, cost);
139 }
140 
141 }
142 
143 
144 #endif //Navigation_RayQueryUtils_H
145 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
The NavFloorBlob contains a connected and not overlapping part of triangle mesh static data within a ...
Definition: navfloorblob.h:42
The cost is not computed.
Definition: rayqueryutils.h:37
KyUInt32 NavHalfEdgeIdx
An index that uniquely identifies a single edge of a triangle within the set of edges owned by a NavF...
Definition: navmeshtypes.h:87
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
This class defines a two-dimensional vector whose coordinates are stored using 64-bit integers...
Definition: vec2ll.h:27
DynamicOutputMode
Enumerates possible ways of storing crossed data from a query in a QueryDynamicOutput object...
Definition: querydynamicoutput.h:26
This class is a "volatile" version of the NavTagSubSegment class.
Definition: navtagsubsegment.h:20
ComputeCostMode
Enumerates the possible ways a RayCanGoQuery can compute the cost of following the ray...
Definition: rayqueryutils.h:35
Vec2LL CoordPos64
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:19
Definition: gamekitcrowddispersion.h:20
This class is an helper used internaly to factorize code of Ray queries (RayCanGoQuery, RayCastGoQuery, ...)
Definition: rayqueryutils.h:60
Indicates that QueryDynamicOutput will not be used to store anything.
Definition: querydynamicoutput.h:28
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtrianglerawptr.h:30
This class represents a CostMultiplier sub-segment of a ray (within a RayCastQuery or a RayCanGoQuery...
Definition: costmultipliersubsegment.h:25
The cost is computed according to the CanTraverseAndGetCostMultiplier function of the traverseLogic...
Definition: rayqueryutils.h:38
Indicates that QueryDynamicOutput will be used to store CostMultiplierSubSegment. ...
Definition: querydynamicoutput.h:33
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
Each instance of this class uniquely identifies a singleNavHalfEdge in a NavFloor.
Definition: navhalfedgerawptr.h:34
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