gwnavruntime/queries/utils/queryutils.h Source File

queryutils.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 
16 
17 namespace Kaim
18 {
19 class Box2f;
20 class NavTrianglePtr;
21 class NavTriangleRawPtr;
22 class NavHalfEdgePtr;
23 class NavHalfEdgeRawPtr;
24 class TriangleFromPosAndTriangleSeedQuery;
25 class ThinCapsuleWithExtentOffset;
26 
29 {
30  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
31 
32 public:
33  QueryUtils() : m_database(nullptr), m_workingMemory(nullptr), m_traverseLogicUserData(nullptr), m_performQueryStat(PerformQueryStat_Unspecified) {}
34  QueryUtils(Database* database, WorkingMemory* workingMemory, void* traverseLogicUserData);
35  void Init(Database* database, WorkingMemory* workingMemory, void* traverseLogicUserData);
36  void SetPerformQueryStat(PerformQueryStat performQueryStat);
37 
38  // ------------------------------ Accessors -----------------------------------
39 
40  Database* GetDatabase() { return m_database; }
41  WorkingMemory* GetWorkingMemory() { return m_workingMemory; }
42  void* GetTraverseLogicUserData() { return m_traverseLogicUserData; }
43 
44  // ------------------------------ Update Spatialization -----------------------------
45 
48  bool FindTriangleFromPositionIfNotValid(NavTrianglePtr& navTrianglePtr, const Vec3f& pos, const PositionSpatializationRange& range);
49 
52  bool FindTriangleFromPositionIfNotValid(NavTrianglePtr& navTrianglePtr, const Vec3f& pos, const PositionSpatializationRange& range, WorldIntegerPos& outputIntegerPos);
53 
56  bool FindTriangleFromPositionIfNotValid(NavTrianglePtr& navTrianglePtr, const Vec3f& pos, const WorldIntegerPos& integerPos, const PositionSpatializationRange& range);
57 
59  template <class TLogic>
61 
62 public: // internal
63  // Provides the next HalEdge (CW) starting from the provided HalEdge start vertex.
64  void GetNextHalfEdgeAroundStartVertex(const NavHalfEdgeRawPtr& currentHalfEdge, NavHalfEdgeRawPtr& nextHalfEdge);
65 
66  // Provides the previous HalEdge (CCW) ending at the provided HalEdge end vertex.
67  void GetPrevHalfEdgeAroundDestVertex(const NavHalfEdgeRawPtr& currentHalfEdge, NavHalfEdgeRawPtr& prevHalfEdge);
68 
69  template <class TLogic>
70  KyResult FindValidPositionFromIntegerIntersection(const Vec3f& collisionPos3f, const NavHalfEdgePtr& halfEdgePtrHit, WorldIntegerPos& arrivalIntegerPos,
71  NavTrianglePtr& arrivalTrianglePtr);
72 
73  template <class TLogic, class BorderHalfEdgeProcessor>
74  KyResult BrowseAndProcessAllBorderNavHalfEdgeInBox(BorderHalfEdgeProcessor& borderHalfEdgeProcessor);
75 
76 private:
77  class CheckIfCurrentIntegerPositionIsValidParam
78  {
79  public:
80  CoordPos64 m_start;
81  CoordPos64 m_end;
82  CoordPos64 m_third;
83  CoordPos64 m_startToEnd;
84  CoordPos64 m_endToThird;
85  CoordPos64 m_thirdTostart;
86  WorldIntegerPos m_currentArrivalIntegerPos;
87  };
88 
89  template <class TraverseLogic>
90  KyResult CheckIfCurrentIntegerPositionIsValid(const CheckIfCurrentIntegerPositionIsValidParam& params, TriangleFromPosAndTriangleSeedQuery& triangleFromPosAndTriangleSeedQuery,
91  WorldIntegerPos& arrivalIntegerPos, NavTrianglePtr& arrivalTrianglePtr);
92 
93 public:
95  WorkingMemory* m_workingMemory;
96  void* m_traverseLogicUserData;
97  PerformQueryStat m_performQueryStat;
98 };
99 
103 {
104 public:
105  ThinCapsuleWithExtentOffset(const CoordPos64& capsuleStartCoordPos, const CoordPos64& capsuleEndCoordPos, KyUInt64 capsuleSquareRadius, KyUInt32 recoveryDistance)
106  {
107  m_capsuleStartCoordPos = capsuleStartCoordPos;
108  m_capsuleEndCoordPos = capsuleEndCoordPos;
109  m_capsuleSquareRadius = capsuleSquareRadius;
110  m_recoveryDistance = recoveryDistance;
111 
112  CoordPos64 capsule = m_capsuleEndCoordPos - m_capsuleStartCoordPos;
113  m_capsuleSquareLength = capsule.GetSquareLength();
114  // m_offset will be computed lazily (only if needed)
115  m_offset.x = KyInt64MAXVAL;
116  }
117 
118  CoordPos64 GetOffset();
119 
120 public:
122  CoordPos64 m_capsuleEndCoordPos;
123  KyUInt64 m_capsuleSquareRadius;
124  KyUInt32 m_recoveryDistance;
125 
126  KyUInt64 m_capsuleSquareLength;
127 
128 private:
129  CoordPos64 m_offset;
130 };
131 }
132 
CoordPos64 m_capsuleStartCoordPos
lazily compute the offset and returns it
Definition: queryutils.h:121
std::uint64_t KyUInt64
uint64_t
Definition: types.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Vertical range (above, below) that represents the altitude tolerance for a position to be inside the ...
Definition: positionspatializationrange.h:17
2d vector using KyInt64
Definition: vec2ll.h:18
bool IsHalfEdgeCompatibleWithThinCapsule(const NavHalfEdgeRawPtr &halfEdge, ThinCapsuleWithExtentOffset &capsuleParams)
Check if the specified half edge intersects the specified thin capsule.
Definition: queryutils.inl:23
Database * m_database
The Database taken into account by queries made through this object. Do not modify.
Definition: queryutils.h:94
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
Finds a triangle that contains the m_inputPos3f 2d coords by testing m_seedTrianglePtr and m_seedTria...
Definition: trianglefromposandtriangleseedquery.h:37
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
WorkingMemory * m_workingMemory
Contains memory buffers used for performing queries and storing results. For internal use...
Definition: queryutils.h:95
Utilities for dealing with NavData coordinates, which are expressed in a world space based on integer...
Definition: worldintegerpos.h:19
PerformQueryStat
Definition: iquery.h:62
This class is an helper used internally by the Queries to factorize Code that is used in many Queries...
Definition: queryutils.h:28
Each instance of this class uniquely identifies a single NavHalfEdge in a NavFloor.
Definition: navhalfedgeptr.h:16
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:17
bool FindTriangleFromPositionIfNotValid(NavTrianglePtr &navTrianglePtr, const Vec3f &pos, const PositionSpatializationRange &range)
if navTrianglePtr is not valid, updates navTrianglePtr with the one spatialied {pos.x, pos.y, pos.z}.
Definition: queryutils.cpp:48
#define KyInt64MAXVAL
KyInt64 max value
Definition: types.h:63
Particuliar class used to represent the ThinCapsule for QueryUtils::IsHalfEdgeCompatibleWithThinCapsu...
Definition: queryutils.h:102
Each instance of this class uniquely identifies a single NavHalfEdge in a NavFloor.
Definition: navhalfedgerawptr.h:23
3d vector using 32bits floating points.
Definition: vec3f.h:16