gwnavruntime/queries/utils/polylinecastintersector.h Source File

polylinecastintersector.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 
11 
12 namespace Kaim
13 {
14 
15 class DatabaseGenMetrics;
16 
17 class PolylineCastIntersector
18 {
19  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
20 
21 public:
22  enum VolumeType { Quad, TriangleAroundRight, TriangleAroundLeft };
23 
24  class BorderEdge
25  {
26  public:
27  BorderEdge() : m_startAxis_f(0.f), m_endAxis_f(0.f), m_startOrdinate_f(0.f), m_endOrdinate_f(0.f) {}
28  void Init(KyFloat32 startAxis, KyFloat32 endAxis, KyFloat32 startOrdinate, KyFloat32 endOrdinate, const Vec3f& startPos, const Vec3f& endPos);
29 
30  public:
31  KyFloat32 m_startAxis_f; // between 0 and 1
32  KyFloat32 m_endAxis_f; // between 0 and 1
33  KyFloat32 m_startOrdinate_f;
34  KyFloat32 m_endOrdinate_f;
35  Vec3f m_startPos;
36  Vec3f m_endPos;
37  NavHalfEdgeRawPtr m_edgeRawPtr;
38  };
39 
40  PolylineCastIntersector();
41  ~PolylineCastIntersector();
42 
43  void InitTrapezoid(const Vec3f& pathEdgeStartPos3f, const Vec3f& pathEdgeEndPos3f, const Vec3f& onStartLeft, const Vec3f& onEndLeft, const Vec3f& onStartRight,
44  const Vec3f& onEndRight, const DatabaseGenMetrics& genMetrics);
45 
46  void InitTriangleAroundRight(const Vec3f& pathEdgeStartPos3f, const Vec3f& pathEdgeEndPos3f, const Vec3f& onStartLeft, const Vec3f& onEndLeft, const Vec3f& onRight,
47  const DatabaseGenMetrics& genMetrics);
48 
49  void InitTriangleAroundLeft(const Vec3f& pathEdgeStartPos3f, const Vec3f& pathEdgeEndPos3f, const Vec3f& onLeft, const Vec3f& onStartRight, const Vec3f& onEndRight,
50  const DatabaseGenMetrics& genMetrics);
51 
52  bool IsEdgeVisible(const CoordPos64& /*startEdgeCoordPos*/, const CoordPos64& /*endEdgeCoordPos*/, const NavHalfEdgeRawPtr& edgeRawPtr, bool edgeIsCrossable);
53 
54  void ComputeTriangleCost(const CoordPos64& v0CoordPos, const CoordPos64& v1CoordPos, const CoordPos64& v2CoordPos, KyFloat32& cost);
55 
56 protected:
57  void Init(VolumeType volumeType, KyFloat32 integerPrecision, const Vec3f& pathEdgeStartPos3f, const Vec3f& pathEdgeEndPos3f, const Vec3f& onStartLeft, const Vec3f& onEndLeft,
58  const Vec3f& onStartRight, const Vec3f& onEndRight);
59 
60  bool ProcessCrossableEdge(KyFloat32 firstAxis, KyFloat32 lastAxis, const Vec3f& firstPos, const Vec3f& lastPos);
61 
62  bool ProcessNonCrossableEdge(const Vec3f& firstPos, const Vec3f& lastPos, KyFloat32 firstAxis, KyFloat32 lastAxis, KyFloat32 axisEdgeStart, KyFloat32 axisEdgeEnd,
63  const NavHalfEdgeRawPtr& edgeRawPtr);
64 
65  bool BoundEdgeToBorderEdgeAxis(const Vec3f& firstPos, const Vec3f& lastPos, KyFloat32& firstAxis, KyFloat32& lastAxis, KyFloat32 borderEdgeAxisStart,
66  KyFloat32 borderEdgeAxisEnd, Vec3f& startPosForThisBorder, Vec3f& endPosForThisBorder);
67 
68  bool SnapExtremityIfNeeded(const Vec3f& firstPos, const Vec3f& lastPos, bool onLeft, BorderEdge* currentBorderEdge, Vec3f& startPosForThisBorder, Vec3f& endPosForThisBorder,
69  KyFloat32& snappedFirstAxis, KyFloat32& snappedLastAxis, KyFloat32& ordinateForStartPosForThisBorder, KyFloat32& ordinateForEndPosForThisBorder);
70 
71  bool SnappedEdgeStartToBorderStartAxis(const Vec3f& firstPos, const Vec3f& lastPos, BorderEdge* currentBorderEdge, bool onLeft, Vec3f& startPosForThisBorder,
72  KyFloat32& ordinateForStartPosForThisBorder);
73 
74  bool SnappedEdgeEndToBorderEndAxis(const Vec3f& firstPos, const Vec3f& lastPos, BorderEdge* currentBorderEdge, bool onLeft, Vec3f& endPosForThisBorder,
75  KyFloat32& ordinateForEndPosForThisBorder);
76 
77  bool IsVisibleForBorderLeft(const Vec3f& startPosForThisBorder, const Vec3f& endPosForThisBorder, PolylineCastIntersector::BorderEdge* borderEdgeOnLeft);
78  bool IsVisibleForBorderRight(const Vec3f& startPosForThisBorder, const Vec3f& endPosForThisBorder, PolylineCastIntersector::BorderEdge* borderEdgeOnRight);
79 
80  bool DoesEdgeIntersectVolume(const Vec3f& startEdgePos, const Vec3f& endEdgePos);
81 
82  KyFloat32 GetAxisValue(const Vec3f& pos);
83  KyFloat32 GetOrdinateValue(const Vec3f& pos) { return CrossProduct_z(m_endO - m_startO, pos - m_startO); }
84 
85  bool GetPointAtAxisOnEdgeRatio(const Vec3f& startEdgePos, const Vec3f& endEdgePos, KyFloat32 wantedAxis, KyFloat32& ratio);
86  bool GetPointAtAxisOnEdge(const Vec3f& startEdgePos, const Vec3f& endEdgePos, KyFloat32 wantedAxis, Vec3f& pos);
87 
88  bool BoundEdgeToTrapezoidEdge(Vec3f& startEdgePos, Vec3f& endEdgePos, const Vec3f& trapezoidEdgeStart, const Vec3f& trapezoidEdgeEnd);
89  bool BoundEdgeToTrapezoidLimit(Vec3f& startEdgePos, Vec3f& endEdgePos);
90 
91 public:
92  Vec3f m_startO;
93  Vec3f m_endO;
94 
95  Vec3f m_startL;
96  Vec3f m_startR;
97 
98  Vec3f m_endL;
99  Vec3f m_endR;
100 
101  Vec3f m_edgeDir2D;
102  Vec3f m_edgeExtentForTest;
103 
104  KyFloat32 m_ABxAC;
105  KyFloat32 m_ABxCD;
106  KyFloat32 m_ACxCD;
107  KyFloat32 m_axisMultFactor;
108  KyFloat32 m_edgeLenght2d;
109  KyFloat32 m_minDistanceStep;
110  KyFloat32 m_axisStepMin;
111  KyFloat32 m_integerPrecision;
112  KyFloat32 m_maxOrdinateOnLeft;
113  KyFloat32 m_minOrdinateOnRight;
114 
115  VolumeType m_type;
116 
117  SharedPoolList<BorderEdge> m_borderEdgesOnLeft;
118  SharedPoolList<BorderEdge> m_borderEdgesOnRight;
119  SharedPoolList<BorderEdge>::NodePool m_borderEdgePool;
120 };
121 
122 }
123 
124 
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Vec2LL CoordPos64
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:16
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyFloat32 CrossProduct_z(const Vec2f &v1, const Vec2f &v2)
alias for CrossProduct, useful in some template functions
Definition: vec2f.h:123
float KyFloat32
float
Definition: types.h:32