gwnavruntime/queries/utils/rayqueryutils.h Source File

rayqueryutils.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 
14 
15 namespace Kaim
16 {
17 
18 class Box2f;
19 class NavTrianglePtr;
20 class NavTriangleRawPtr;
21 class NavHalfEdgePtr;
22 class NavHalfEdgeRawPtr;
23 class TriangleFromPosAndTriangleSeedQuery;
24 class WorldIntegerPos;
25 class LocalStoreActiveDataWorkspaceContext;
26 class RawNavTagSubSegment;
27 class WorkingMemory;
28 class Path;
29 template <class T>
30 class WorkingMemArray;
31 
34 {
37 };
39 
40 class CompositeSubSegment
41 {
42 public:
43  CompositeSubSegment() {}
44  CompositeSubSegment(const Vec3f& startPos3f, const NavTriangleRawPtr& startTriangle, KyFloat32 costMultiplier)
45  {
46  m_rawNavTagSubSegment.m_navTriangleRawPtr = startTriangle;
47  m_rawNavTagSubSegment.m_entrancePos3f = startPos3f;
48  m_costMultiplierSubSegment.m_costMultiplier = costMultiplier;
49  m_costMultiplierSubSegment.m_entrancePos3f = startPos3f;
50  }
51 
52 public:
53  RawNavTagSubSegment m_rawNavTagSubSegment;
54  CostMultiplierSubSegment m_costMultiplierSubSegment;
55 };
56 
59 {
60  RayQueryUtils();
61 
62 public:
63  RayQueryUtils(const Vec3f& startPos3f, const Vec3f& destPos3f, void* traverseLogicUserData, ScopedDynamicOutput& scopeAutoSaveDynamicOutput,
64  DynamicOutputMode savingMode = QUERY_SAVE_NOTHING, KyFloat32 firstCostMultiplier = 1.f, ComputeCostMode computeCostMode = QUERY_DO_NOT_COMPUTE_COST);
65 
66  KyResult StorePropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, CompositeSubSegment& subSegment, const CoordPos64& cellOrigin,
67  const NavFloorBlob* navFloorBlob);
68 
69  template <class TraverseLogic>
70  KyResult StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, CompositeSubSegment& currentSubSegment,
71  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, const CoordPos64& segmentStartCoordPos,
76  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 
89 protected:
90  KyResult StoreTriangle(const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr);
91  KyResult ComputeAndStoreEdgeIntersection(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, const CoordPos64& cellOrigin,
92  const NavFloorBlob* navFloorBlob, Vec3f& intersectionWithEdge);
93 
94  KyResult FinalizeAndStoreNavTagSubSegment(const Vec3f& intersectionWithEdge, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, RawNavTagSubSegment& navTagSubSegment);
95  KyResult FinalizeAndStoreCostMultiplierSubSegment(const Vec3f& intersectionWithEdge, KyFloat32 nextCostMultiplier, CostMultiplierSubSegment& costMultSubSegment);
96 
97  bool EdgeIsANavTagBoundary(const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, RawNavTagSubSegment& navTagSubSegment);
98 
99  void ComputeIntersectionWithEdge(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob,
100  Vec3f& intersection);
101 
102  KyResult StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr, CompositeSubSegment& currentSubSegment,
103  const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob, KyFloat32 nextCostMultiplier, bool updateDataFromCostLimit,
104  KyFloat32& cost);
105 
106  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithNoCustomCost&, DynamicOutputMode, ComputeCostMode) { return false; }
107  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithCostPerNavTag&, DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
108  {
109  return NeedToCommputeOrStoreDataFromCost_Impl(dynamicOutputMode, computeCostMode);
110  }
111  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost(const LogicWithCostPerTriangle&, DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
112  {
113  return NeedToCommputeOrStoreDataFromCost_Impl(dynamicOutputMode, computeCostMode);
114  }
115  static KY_INLINE bool NeedToCommputeOrStoreDataFromCost_Impl(DynamicOutputMode dynamicOutputMode, ComputeCostMode computeCostMode)
116  {
117  return (dynamicOutputMode & QUERY_SAVE_COSTMULTIPLIERSUBSEGMENTS) != 0 || computeCostMode == QUERY_COMPUTE_COST_ALONG_3DAXIS;
118  ;
119  }
120 
121 public:
122  Vec3f m_startPos3f;
123  Vec3f m_destPos3f;
124  void* m_traverseLogicUserData;
125 
126  DynamicOutputMode m_dynamicOutputMode;
127  ComputeCostMode m_computeCostMode;
128  ScopedDynamicOutput* m_scopedDynamicOutput;
129 
130  KyFloat32 m_dist3DOverSquareDist2d;
131  Vec3f m_currentCostMultiplierStartPos;
132  KyFloat32 m_currentCostMultiplier;
133 };
134 
135 template <class TLogic>
136 KY_INLINE KyResult RayQueryUtils::StoreOrComputeCostFromPropagationData(KyFloat32 integerPrecision, const NavHalfEdgeRawPtr& currentPairHalfEdgeRawPtr,
137  CompositeSubSegment& currentSubSegment, const CoordPos64& cellOrigin, const NavFloorBlob* navFloorBlob,
138  KyFloat32 nextCostMultiplier, KyFloat32& cost)
139 {
140  bool updateDataFromCostLimit = NeedToCommputeOrStoreDataFromCost<TLogic>(m_dynamicOutputMode, m_computeCostMode);
141  return StoreOrComputeCostFromPropagationData(integerPrecision, currentPairHalfEdgeRawPtr, currentSubSegment, cellOrigin, navFloorBlob, nextCostMultiplier,
142  updateDataFromCostLimit, cost);
143 }
144 }
The NavFloorBlob contains a connected and not overlapping part of triangle mesh static data within a ...
Definition: navfloorblob.h:38
The cost is not computed.
Definition: rayqueryutils.h:35
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:84
2d vector using KyInt64
Definition: vec2ll.h:18
DynamicOutputMode
Enumerates possible ways of storing collected data by a query in a QueryDynamicOutput object...
Definition: querydynamicoutput.h:21
Tag type used for function overloading in templates.
Definition: traverselogic.h:69
This class is a "volatile" version of the NavTagSubSegment class.
Definition: navtagsubsegment.h:16
ComputeCostMode
Enumerates the possible ways a RayCanGoQuery can compute the cost of following the ray...
Definition: rayqueryutils.h:33
std::int64_t KyInt64
int64_t
Definition: types.h:25
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Tag type used for function overloading in templates.
Definition: traverselogic.h:59
This class is an helper used internaly to factorize code of Ray queries (RayCanGoQuery, RayCastGoQuery, ...)
Definition: rayqueryutils.h:58
do not store anything
Definition: querydynamicoutput.h:23
Identifies a single NavTriangle in a NavFloor.
Definition: navtrianglerawptr.h:21
This class represents a CostMultiplier sub-segment of a ray (within a RayCastQuery or a RayCanGoQuery...
Definition: costmultipliersubsegment.h:21
std::int32_t KyInt32
int32_t
Definition: types.h:24
Tag type used for function overloading in templates.
Definition: traverselogic.h:64
The cost is computed according to the CanTraverseAndGetCostMultiplier function of the traverseLogic...
Definition: rayqueryutils.h:36
store CostMultiplierSubSegment array
Definition: querydynamicoutput.h:28
Each instance of this class uniquely identifies a single NavHalfEdge in a NavFloor.
Definition: navhalfedgerawptr.h:23
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16