gwnavruntime/queries/utils/crossedsectioncapsuleintersector.h Source File

crossedsectioncapsuleintersector.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 #pragma once
8 
14 
15 namespace Kaim
16 {
17 
18 class CrossedSectionCapsuleIntersector
19 {
20  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
21 
22 public:
23  CrossedSectionCapsuleIntersector(const BaseDiskCastQuery& query, KyFloat32 distOnRight, KyFloat32 distOnLeft) :
24  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision), m_startCenter(query.GetStartPos()), m_normalizedDir2d(query.GetNormalizedDir2d()),
25  m_dist(query.GetMaxDist()), m_radius(query.GetRadius())
26  {
27  const Vec2f normalizedDir_ortho(m_normalizedDir2d.PerpCCW());
28  const Vec3f normalizedDir3D(m_normalizedDir2d.x, m_normalizedDir2d.y, 0.f);
29  const Vec3f normalizedDir3D_ortho(normalizedDir_ortho.x, normalizedDir_ortho.y, 0.f);
30 
31  m_centerOfTheEndHalfDisk = m_startCenter + (normalizedDir3D * m_dist);
32 
33  const Vec3f orientedBox2d_a(m_startCenter - (normalizedDir3D_ortho * distOnRight));
34  const Vec3f m_BBoxOfTheEndHalfDisk_a(m_centerOfTheEndHalfDisk - (normalizedDir3D_ortho * distOnRight));
35 
36  m_orientedBox2d.Set(orientedBox2d_a, m_normalizedDir2d, m_dist, distOnRight + distOnLeft, 0.f);
37  m_BBoxOfTheEndHalfDisk.Set(m_BBoxOfTheEndHalfDisk_a, m_normalizedDir2d, m_radius, distOnRight + distOnLeft, 0.f);
38  }
39 
40  CrossedSectionCapsuleIntersector(const BaseDiskCanGoQuery& query, KyFloat32 distOnRight, KyFloat32 distOnLeft) :
41  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision), m_startCenter(query.GetStartPos()), m_radius(query.GetRadius())
42  {
43  Vec3f dir(query.GetDestPos() - query.GetStartPos());
44  dir.z = 0.f;
45  m_dist = dir.Normalize();
46  m_normalizedDir2d.Set(dir.x, dir.y);
47 
48  const Vec2f normalizedDir_ortho(m_normalizedDir2d.PerpCCW());
49  const Vec3f normalizedDir3D(m_normalizedDir2d.x, m_normalizedDir2d.y, 0.f);
50  const Vec3f normalizedDir3D_ortho(normalizedDir_ortho.x, normalizedDir_ortho.y, 0.f);
51 
52  m_centerOfTheEndHalfDisk = m_startCenter + (normalizedDir3D * m_dist);
53 
54  const Vec3f orientedBox2d_a(m_startCenter - (normalizedDir3D_ortho * distOnRight));
55  const Vec3f m_BBoxOfTheEndHalfDisk_a(m_centerOfTheEndHalfDisk - (normalizedDir3D_ortho * distOnRight));
56 
57  m_orientedBox2d.Set(orientedBox2d_a, m_normalizedDir2d, m_dist, distOnRight + distOnLeft, 0.f);
58  m_BBoxOfTheEndHalfDisk.Set(m_BBoxOfTheEndHalfDisk_a, m_normalizedDir2d, m_radius, distOnRight + distOnLeft, 0.f);
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::SegmentVsCrossSectionCapsule2f(startEdgePos, endEdgePos, m_orientedBox2d, m_centerOfTheEndHalfDisk, m_radius, m_BBoxOfTheEndHalfDisk);
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::OnSegmentVsDiskCast2d(startEdgePos, endEdgePos, m_startCenter, m_radius, m_normalizedDir2d, m_dist, 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::OnTriangleVsDiskCast2d(v0, v1, v2, m_startCenter, m_radius, m_normalizedDir2d, m_dist, unused, cost);
85  }
86 
87 private:
88  KyFloat32 m_integerPrecision;
89 
90  Vec3f m_startCenter;
91  Vec2f m_normalizedDir2d;
92  KyFloat32 m_dist;
93  KyFloat32 m_radius;
94 
95  OrientedBox2d m_orientedBox2d;
96  OrientedBox2d m_BBoxOfTheEndHalfDisk;
97  Vec3f m_centerOfTheEndHalfDisk;
98 };
99 
100 
101 }
102 
103 
104 
#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