Implement LineRelationship2D
This commit is contained in:
parent
ae5def1fd2
commit
801fe47cb8
5 changed files with 61 additions and 2 deletions
21
dep/RobustPredicates/RobustPredicates.License
Normal file
21
dep/RobustPredicates/RobustPredicates.License
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Modios
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
BIN
dep/RobustPredicates/RobustPredicates.dll
Normal file
BIN
dep/RobustPredicates/RobustPredicates.dll
Normal file
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
|
@ -25,6 +25,9 @@
|
|||
<Reference Include="Google.ProtocolBuffers">
|
||||
<HintPath>..\..\dep\protobuf-csharp\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobustPredicates">
|
||||
<HintPath>..\..\dep\RobustPredicates\RobustPredicates.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -8,16 +8,20 @@ namespace MHServerEmu.Games.Navi
|
|||
Attached
|
||||
}
|
||||
|
||||
public class NaviPoint
|
||||
public class NaviPoint : IComparable<NaviPoint>
|
||||
{
|
||||
public Vector3 Pos { get; internal set; }
|
||||
public NaviPointFlags Flags { get; private set; }
|
||||
public int Influence { get; private set; }
|
||||
public float InfluenceRadius { get; private set; }
|
||||
|
||||
private static ulong TotalCount = 0;
|
||||
private readonly ulong _count;
|
||||
|
||||
public NaviPoint(Vector3 pos)
|
||||
{
|
||||
Pos = pos;
|
||||
_count = TotalCount++;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -25,5 +29,9 @@ namespace MHServerEmu.Games.Navi
|
|||
return $"NaviPoint ({Pos.X:F4} {Pos.Y:F4} {Pos.Z:F4}) flg:{Flags} inf:{Influence}";
|
||||
}
|
||||
|
||||
public int CompareTo(NaviPoint other)
|
||||
{
|
||||
return _count.CompareTo(other._count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using MHServerEmu.Core.VectorMath;
|
||||
using RobustPredicates;
|
||||
|
||||
namespace MHServerEmu.Games.Navi
|
||||
{
|
||||
|
|
@ -14,5 +15,31 @@ namespace MHServerEmu.Games.Navi
|
|||
float yd = (y0 < y1) ? (y1 - y0) : (y0 - y1);
|
||||
return (xd * xd + yd * yd) <= 9.0f;
|
||||
}
|
||||
|
||||
public static bool SortInputs<T>(ref T input0, ref T input1) where T : IComparable<T>
|
||||
{
|
||||
if (input0.CompareTo(input1) < 0)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
(input0, input1) = (input1, input0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static double LineRelationship2D(NaviPoint p0, NaviPoint p1, Vector3 pos)
|
||||
{
|
||||
bool flip = SortInputs(ref p0, ref p1);
|
||||
double d = InternalOrient2D(p1.Pos, p0.Pos, pos);
|
||||
return flip ? -d : d;
|
||||
}
|
||||
|
||||
private static double InternalOrient2D(Vector3 v0, Vector3 v1, Vector3 v2)
|
||||
{
|
||||
double[] pa = { v0.X, v0.Y };
|
||||
double[] pb = { v1.X, v1.Y };
|
||||
double[] pc = { v2.X, v2.Y };
|
||||
return Orient2D.Robust(pa, pb, pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue