gwnavruntime/queries/utils/diskintersector.h Source File

diskintersector.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: JUBA - secondary contact: NOBODY
12 #ifndef Navigation_DiskIntersector_H
13 #define Navigation_DiskIntersector_H
14 
20 
21 namespace Kaim
22 {
23 
24 /*
25 class DiskIntersector
26 */
27 class DiskIntersector
28 {
29  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
30 
31 public:
32  DiskIntersector(const BaseDiskExpansionQuery& query) :
33  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision),
34  m_center3f(query.GetCenterPos()), m_radius(query.GetRadiusMax()) {}
35 
36  DiskIntersector(const BaseDiskCollisionQuery& query) :
37  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision),
38  m_center3f(query.GetCenterPos()), m_radius(query.GetRadius()) {}
39 
40  bool DoesIntersectEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos)
41  {
42  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
43  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
44 
45  return Intersections::SegmentVsDisk2d(startEdgePos, endEdgePos, m_center3f, m_radius);
46  }
47 
48  void ComputeCollisionPosOnEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos, Vec3f& collisionPos, KyFloat32& squareDistToCollisionPos)
49  {
50  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
51  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
52 
53  ClosestPoint::OnSegmentVsPoint2d(startEdgePos, endEdgePos, m_center3f, collisionPos, squareDistToCollisionPos);
54  }
55 
56  void ComputeTriangleCost(const CoordPos64& v0CoordPos, const CoordPos64& v1CoordPos, const CoordPos64& v2CoordPos, KyFloat32& cost)
57  {
58  const Vec3f v0(v0CoordPos.x * m_integerPrecision, v0CoordPos.y * m_integerPrecision, 0.f);
59  const Vec3f v1(v1CoordPos.x * m_integerPrecision, v1CoordPos.y * m_integerPrecision, 0.f);
60  const Vec3f v2(v2CoordPos.x * m_integerPrecision, v2CoordPos.y * m_integerPrecision, 0.f);
61 
62  Vec3f unused;
63  ClosestPoint::OnTriangleVsPoint2d(v0, v1, v2, m_center3f, unused, cost);
64  }
65 
66 private:
67  KyFloat32 m_integerPrecision;
68 
69  Vec3f m_center3f;
70  KyFloat32 m_radius;
71 };
72 
73 
74 }
75 
76 
77 #endif //Navigation_DiskIntersector_H
78 
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