gwnavruntime/queries/utils/coneintersector.h Source File

coneintersector.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 
9 
10 
11 // Primary contact: LAPA - secondary contact: NOBODY
12 #ifndef Navigation_ConeIntersector_H
13 #define Navigation_ConeIntersector_H
14 
20 
21 
22 namespace Kaim
23 {
24 
25 /*
26 class ConeIntersector
27 */
28 class ConeIntersector
29 {
30  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
31 
32 public:
33  ConeIntersector(const Vec3f& startCenter, const Vec3f& endCenter, KyFloat32 halfWidth, KyFloat32 integerPrecision)
34  : m_integerPrecision(integerPrecision)
35  , m_startCenter(startCenter)
36  , m_endCenter(endCenter)
37  , m_halfWidth(halfWidth)
38  {
39  m_normalizedDir2d = m_endCenter.Get2d() - m_startCenter.Get2d();
40  m_length = m_normalizedDir2d.Normalize();
41 
42  const Vec2f leftDir = m_normalizedDir2d.PerpCCW();
43  const Vec2f leftVec = m_halfWidth * leftDir;
44  m_endLeft = m_endCenter + leftVec;
45  m_endRight = m_endCenter - leftVec;
46  }
47 
48  ConeIntersector(const Vec3f& startPos, const Vec2f& normalizedDir2d, KyFloat32 length, KyFloat32 halfWidth, KyFloat32 integerPrecision)
49  : m_integerPrecision(integerPrecision)
50  , m_startCenter(startPos)
51  , m_normalizedDir2d(normalizedDir2d)
52  , m_length(length)
53  , m_halfWidth(halfWidth)
54  {
55  m_endCenter = m_startCenter + (m_normalizedDir2d * m_length);
56 
57  const Vec2f leftDir = m_normalizedDir2d.PerpCCW();
58  const Vec2f leftVec = m_halfWidth * leftDir;
59  m_endLeft = m_endCenter + leftVec;
60  m_endRight = m_endCenter - leftVec;
61  }
62 
63  bool DoesIntersectEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos)
64  {
65  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
66  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
67 
68  return Intersections::SegmentVsTriangle2d(startEdgePos, endEdgePos, m_startCenter, m_endLeft, m_endRight);
69  }
70 
71  void ComputeCollisionPosOnEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos, Vec3f& collisionPos, KyFloat32& squareDistToCollisionPos)
72  {
73  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
74  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
75 
76  ClosestPoint::OnSegmentVsConeCast2d(startEdgePos, endEdgePos, m_startCenter, m_normalizedDir2d, m_length, m_halfWidth, collisionPos, squareDistToCollisionPos);
77  }
78 
79  void ComputeTriangleCost(const CoordPos64& v0CoordPos, const CoordPos64& v1CoordPos, const CoordPos64& v2CoordPos, KyFloat32& cost)
80  {
81  const Vec3f v0(v0CoordPos.x * m_integerPrecision, v0CoordPos.y * m_integerPrecision, 0.f);
82  const Vec3f v1(v1CoordPos.x * m_integerPrecision, v1CoordPos.y * m_integerPrecision, 0.f);
83  const Vec3f v2(v2CoordPos.x * m_integerPrecision, v2CoordPos.y * m_integerPrecision, 0.f);
84 
85  Vec3f unused;
86  ClosestPoint::OnTriangleVsConeCast2d(v0, v1, v2, m_startCenter,m_normalizedDir2d, m_length, m_halfWidth, unused, cost);
87  }
88 
89 private:
90  KyFloat32 m_integerPrecision;
91 
92  Vec3f m_startCenter;
93  Vec3f m_endCenter;
94  Vec3f m_endLeft;
95  Vec3f m_endRight;
96 
97  Vec2f m_normalizedDir2d;
98  KyFloat32 m_length;
99  KyFloat32 m_halfWidth;
100 
101  OrientedBox2d m_orientedBox2d;
102 };
103 
104 
105 }
106 
107 
108 #endif //Navigation_ConeIntersector_H
109 
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