gwnavruntime/queries/utils/coneintersector.h Source File

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