gwnavruntime/queries/utils/crossedsectioncapsuleintersector.h Source File

crossedsectioncapsuleintersector.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_CrossedSectionCapsuleIntersector_H
13 #define Navigation_CrossedSectionCapsuleIntersector_H
14 
20 
21 namespace Kaim
22 {
23 
24 /*
25 class CrossedSectionCapsuleIntersector
26 */
27 class CrossedSectionCapsuleIntersector
28 {
29  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
30 
31 public:
32  CrossedSectionCapsuleIntersector(const BaseDiskCastQuery& query, KyFloat32 distOnRight, KyFloat32 distOnLeft) :
33  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision), m_startCenter(query.GetStartPos()), m_normalizedDir2d(query.GetNormalizedDir2d()),
34  m_dist(query.GetMaxDist()), m_radius(query.GetRadius())
35  {
36  const Vec2f normalizedDir_ortho(m_normalizedDir2d.PerpCCW());
37  const Vec3f normalizedDir3D(m_normalizedDir2d.x, m_normalizedDir2d.y, 0.f);
38  const Vec3f normalizedDir3D_ortho(normalizedDir_ortho.x, normalizedDir_ortho.y, 0.f);
39 
40  m_centerOfTheEndHalfDisk = m_startCenter + (normalizedDir3D * m_dist);
41 
42  const Vec3f orientedBox2d_a(m_startCenter - (normalizedDir3D_ortho * distOnRight));
43  const Vec3f m_BBoxOfTheEndHalfDisk_a(m_centerOfTheEndHalfDisk - (normalizedDir3D_ortho * distOnRight));
44 
45  m_orientedBox2d.Set(orientedBox2d_a, m_normalizedDir2d, m_dist, distOnRight + distOnLeft, 0.f);
46  m_BBoxOfTheEndHalfDisk.Set(m_BBoxOfTheEndHalfDisk_a, m_normalizedDir2d, m_radius, distOnRight + distOnLeft, 0.f);
47  }
48 
49  CrossedSectionCapsuleIntersector(const BaseDiskCanGoQuery& query, KyFloat32 distOnRight, KyFloat32 distOnLeft) :
50  m_integerPrecision(query.m_database->GetDatabaseGenMetrics().m_integerPrecision), m_startCenter(query.GetStartPos()), m_radius(query.GetRadius())
51  {
52  Vec3f dir(query.GetDestPos() - query.GetStartPos());
53  dir.z = 0.f;
54  m_dist = dir.Normalize();
55  m_normalizedDir2d.Set(dir.x, dir.y);
56 
57  const Vec2f normalizedDir_ortho(m_normalizedDir2d.PerpCCW());
58  const Vec3f normalizedDir3D(m_normalizedDir2d.x, m_normalizedDir2d.y, 0.f);
59  const Vec3f normalizedDir3D_ortho(normalizedDir_ortho.x, normalizedDir_ortho.y, 0.f);
60 
61  m_centerOfTheEndHalfDisk = m_startCenter + (normalizedDir3D * m_dist);
62 
63  const Vec3f orientedBox2d_a(m_startCenter - (normalizedDir3D_ortho * distOnRight));
64  const Vec3f m_BBoxOfTheEndHalfDisk_a(m_centerOfTheEndHalfDisk - (normalizedDir3D_ortho * distOnRight));
65 
66  m_orientedBox2d.Set(orientedBox2d_a, m_normalizedDir2d, m_dist, distOnRight + distOnLeft, 0.f);
67  m_BBoxOfTheEndHalfDisk.Set(m_BBoxOfTheEndHalfDisk_a, m_normalizedDir2d, m_radius, distOnRight + distOnLeft, 0.f);
68  }
69 
70  bool DoesIntersectEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos)
71  {
72  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
73  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
74 
75  return Intersections::SegmentVsCrossSectionCapsule2d(startEdgePos, endEdgePos, m_orientedBox2d, m_centerOfTheEndHalfDisk, m_radius, m_BBoxOfTheEndHalfDisk);
76  }
77 
78  void ComputeCollisionPosOnEdge(const CoordPos64& startEdgeCoordPos, const CoordPos64& endEdgeCoordPos, Vec3f& collisionPos, KyFloat32& squareDistToCollisionPos)
79  {
80  const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
81  const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
82 
83  ClosestPoint::OnSegmentVsDiskCast2d(startEdgePos, endEdgePos, m_startCenter, m_radius, m_normalizedDir2d, m_dist, collisionPos, squareDistToCollisionPos);
84  }
85 
86  void ComputeTriangleCost(const CoordPos64& v0CoordPos, const CoordPos64& v1CoordPos, const CoordPos64& v2CoordPos, KyFloat32& cost)
87  {
88  const Vec3f v0(v0CoordPos.x * m_integerPrecision, v0CoordPos.y * m_integerPrecision, 0.f);
89  const Vec3f v1(v1CoordPos.x * m_integerPrecision, v1CoordPos.y * m_integerPrecision, 0.f);
90  const Vec3f v2(v2CoordPos.x * m_integerPrecision, v2CoordPos.y * m_integerPrecision, 0.f);
91 
92  Vec3f unused;
93  ClosestPoint::OnTriangleVsDiskCast2d(v0, v1, v2, m_startCenter, m_radius, m_normalizedDir2d, m_dist, unused, cost);
94  }
95 
96 private:
97  KyFloat32 m_integerPrecision;
98 
99  Vec3f m_startCenter;
100  Vec2f m_normalizedDir2d;
101  KyFloat32 m_dist;
102  KyFloat32 m_radius;
103 
104  OrientedBox2d m_orientedBox2d;
105  OrientedBox2d m_BBoxOfTheEndHalfDisk;
106  Vec3f m_centerOfTheEndHalfDisk;
107 };
108 
109 
110 }
111 
112 
113 #endif //Navigation_CrossedSectionCapsuleIntersector_H
114 
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