gwnavruntime/queries/utils/polylinecastintersector.h Source File

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