gwnavruntime/navmesh/closestpoint.h Source File

closestpoint.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_ClosestPoint_H
13 #define Navigation_ClosestPoint_H
14 
16 
17 namespace Kaim
18 {
19 
20 class ClosestPoint // class with static functions only
21 {
22 public :
23 // oneShape1VsShape2 = compute the closest point of Shape1 from Shape2
24 
25 // Compute the point of the Segment [ab] the is closest from the Point p
26 static void OnSegmentVsPoint2d(const Vec3f& a, const Vec3f& b, const Vec3f& p, Vec3f& closestPointOnSegment, KyFloat32& squareDist2d);
27 static void OnSegmentVsPoint2d(const CoordPos64& a, const CoordPos64& b, const CoordPos64& p, CoordPos64& closestPointOnSegment, KyInt64& squareDist2d);
28 
29 // Compute the point the Triangle [v1, v2, v3] the is closest from the Point p
30 static void OnTriangleVsPoint2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& p, Vec3f& closestPointOnTriangle, KyFloat32& squareDist2d);
31 
32 // Compute the point of the Segment [v1v2] that is the closest from the Segment[ab]
33 static void OnSegmentVsSegmentCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& a, const Vec3f& b,
34  const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
35 // Compute the point the Triangle [v1, v2, v3] the is closest from the Segment [ab]
36 static void OnTriangleVsSegmentCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& a,
37  const Vec3f& b, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
38 
39 // Compute the point the Segment [v1v2] the is closest from the Disk (center, radius)
40 static void OnSegmentVsDiskCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& center, const KyFloat32 radius,
41  const Vec2f& normalizedDir2D, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
42 // Compute the point the Triangle [v1, v2, v3] the is closest from the Disk (center, radius)
43 static void OnTriangleVsDiskCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& center, const KyFloat32 radius,
44  const Vec2f& normalizedDir2D, const KyFloat32 distCast, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
45 
46 // Compute the point the Segment [v1v2] the is closest from the Cone (apex, normalizedDir2D, length, halfAngleSine)
47 static void OnSegmentVsConeCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& apex, const Vec2f& normalizedDir2D, KyFloat32 length,
48  const KyFloat32 halfAngleSine, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
49 // Compute the point the Triangle [v1, v2, v3] the is closest from the Cone (apex, normalizedDir2D, length, halfAngleSine)
50 static void OnTriangleVsConeCast2d(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, const Vec3f& apex, const Vec2f& normalizedDir2D,
51  KyFloat32 length, const KyFloat32 halfAngleSine, Vec3f& closestPointonTriangle, KyFloat32& squareDist2d);
52 
53 // Compute only the square distance between a segment and a point
54 static KyUInt64 GetSquareDistancePointToSegment(const CoordPos64& P, const CoordPos64& A, const CoordPos64& B, const KyInt64& sqDistAB);
55 
56 // Compute only the square distance between a segment and a point multiplied by the segment square length
57 // NOTE: Be cautious to cases where sqDistAB == 0 !
58 static KyUInt64 GetSquareDistancePointToSegmentFactorSegmentSquareLength(const CoordPos64& P, const CoordPos64& A, const CoordPos64& B, const KyInt64& sqDistAB);
59 
60 // Compute only the square distance between two segments
61 static KyUInt64 GetSquareDistanceSegmentToSegment(const CoordPos64& P, const CoordPos64& Q, const CoordPos64& A, const CoordPos64& B);
62 
63 // The same as the previous ones, but in float metrics.
64 static KyFloat32 GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B);
65 static KyFloat32 GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B, const KyFloat32& sqDistAB);
66 static KyFloat32 GetSquareDistancePointToSegmentFactorSegmentSquareLength(const Vec2f& P, const Vec2f& A, const Vec2f& B, KyFloat32 sqDistAB);
67 static KyFloat32 GetSquareDistanceSegmentToSegment(const Vec2f& P, const Vec2f& Q, const Vec2f& A, const Vec2f& B);
68 
69 static bool OnSegmentVsDisk2dIfIntersection(const Vec3f& A, const Vec3f& B, const Vec3f& C, KyFloat32 radius, Vec3f& intersection);
70 static bool OnSegmentCapsule2dIfIntersection(const Vec3f& P, const Vec3f& Q, const Vec3f& A, const Vec3f& B, KyFloat32 radius, Vec3f& intersection);
71 };
72 
73 KY_INLINE KyFloat32 ClosestPoint::GetSquareDistancePointToSegment(const Vec2f& P, const Vec2f& A, const Vec2f& B) { return GetSquareDistancePointToSegment(P, A, B, SquareDistance(A, B)); }
74 
75 }
76 
77 #endif // Navigation_ClosestPoint_H
78 
KyFloat32 SquareDistance(const Vec2f &v1, const Vec2f &v2)
Returns the square of the distance between v1 and v2.
Definition: vec2f.h:194
unsigned __int64 KyUInt64
Type used internally to represent an unsigned 64-bit integer.
Definition: types.h:38
Vec2LL CoordPos64
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:19
Definition: gamekitcrowddispersion.h:20
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43