gwnavruntime/queries/utils/diskintersector.h Source File

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