12 #ifndef Navigation_CapsuleIntersector_H
13 #define Navigation_CapsuleIntersector_H
28 class CapsuleIntersector
33 CapsuleIntersector(const Vec3f& startPos, const Vec3f& endPos,
KyFloat32 radius,
KyFloat32 integerPrecision)
34 : m_integerPrecision(integerPrecision)
35 , m_startCenter(startPos)
40 Vec3f dir(m_endCenter - m_startCenter);
42 m_dist = dir.Normalize();
44 const Vec3f normalizedDir3D_ortho(-dir.y, dir.x, 0.f);
45 const Vec3f box_a(m_startCenter - (normalizedDir3D_ortho * m_radius));
47 m_orientedBox2d.Set(box_a, Vec2f(dir.x, dir.y), m_dist, m_radius * 2.f, 0.f);
50 CapsuleIntersector(
const Vec3f& startPos,
const Vec2f& normalizedDir2d,
KyFloat32 dist,
KyFloat32 radius,
KyFloat32 integerPrecision)
51 : m_integerPrecision(integerPrecision)
52 , m_startCenter(startPos)
53 , m_normalizedDir2d(normalizedDir2d)
57 const Vec3f normalizedDir3D_ortho(-m_normalizedDir2d.y, m_normalizedDir2d.x, 0.f);
58 const Vec3f box_a(m_startCenter - (normalizedDir3D_ortho * m_radius));
59 m_orientedBox2d.Set(box_a, m_normalizedDir2d, m_dist, m_radius * 2.f, 0.f);
61 const Vec3f normalizedDir3D(m_normalizedDir2d.x, m_normalizedDir2d.y, 0.f);
62 m_endCenter = m_startCenter + (normalizedDir3D * m_dist);
67 const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
68 const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
70 return Intersections::SegmentVsCapsule2d(startEdgePos, endEdgePos, m_orientedBox2d, m_startCenter, m_endCenter, m_radius);
73 void ComputeCollisionPosOnEdge(
const CoordPos64& startEdgeCoordPos,
const CoordPos64& endEdgeCoordPos, Vec3f& collisionPos,
KyFloat32& squareDistToCollisionPos)
75 const Vec3f startEdgePos(startEdgeCoordPos.x * m_integerPrecision, startEdgeCoordPos.y * m_integerPrecision, 0.f);
76 const Vec3f endEdgePos(endEdgeCoordPos.x * m_integerPrecision, endEdgeCoordPos.y * m_integerPrecision, 0.f);
78 ClosestPoint::OnSegmentVsDiskCast2d(startEdgePos, endEdgePos, m_startCenter, m_radius, m_normalizedDir2d, m_dist, collisionPos, squareDistToCollisionPos);
83 const Vec3f v0(v0CoordPos.x * m_integerPrecision, v0CoordPos.y * m_integerPrecision, 0.f);
84 const Vec3f v1(v1CoordPos.x * m_integerPrecision, v1CoordPos.y * m_integerPrecision, 0.f);
85 const Vec3f v2(v2CoordPos.x * m_integerPrecision, v2CoordPos.y * m_integerPrecision, 0.f);
88 ClosestPoint::OnTriangleVsDiskCast2d(v0, v1, v2, m_startCenter, m_radius, m_normalizedDir2d, m_dist, unused, cost);
96 Vec2f m_normalizedDir2d;
100 OrientedBox2d m_orientedBox2d;
107 #endif //Navigation_CapsuleIntersector_H
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