diff --git a/Source/Framework/RecastDetour/Detour/DetourCommon.cs b/Source/Framework/RecastDetour/Detour/DetourCommon.cs index 5041d6148..56b320abf 100644 --- a/Source/Framework/RecastDetour/Detour/DetourCommon.cs +++ b/Source/Framework/RecastDetour/Detour/DetourCommon.cs @@ -254,7 +254,7 @@ public static partial class Detour if (u >= 0.0f && v >= 0.0f && (u + v) <= denom) { - h = a[1] + (v0[1] * u + v1[1] * v) / denom; + h = a[aStart + 1] + (v0[1] * u + v1[1] * v) / denom; return true; } diff --git a/Source/Framework/RecastDetour/Detour/DetourNavMesh.cs b/Source/Framework/RecastDetour/Detour/DetourNavMesh.cs index 2cb80e33c..a4ebafe33 100644 --- a/Source/Framework/RecastDetour/Detour/DetourNavMesh.cs +++ b/Source/Framework/RecastDetour/Detour/DetourNavMesh.cs @@ -782,14 +782,14 @@ public static partial class Detour dtVlerp(closest, 0, new float[] { v[pmin].X, v[pmin].Y, v[pmin].Z }, 0, new float[] { v[pmax].X, v[pmax].Y, v[pmax].Z }, 0, tmin); } - public bool getPolyHeight(dtMeshTile tile, dtPoly poly, float[] pos, float height) + public bool getPolyHeight(dtMeshTile tile, dtPoly poly, float[] pos, ref float height) { // Off-mesh connections do not have detail polys and getting height // over them does not make sense. if (poly.getType() == (byte)dtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) return false; - uint ip = (uint)tile.polys.ToList().IndexOf(poly); + uint ip = (uint)Array.IndexOf(tile.polys, poly); dtPolyDetail pd = tile.detailMeshes[ip]; float[] verts = new float[DT_VERTS_PER_POLYGON * 3]; @@ -855,7 +855,7 @@ public static partial class Detour getTileAndPolyByRefUnsafe(polyRef, ref tile, ref poly); dtVcopy(closest, pos); - if (getPolyHeight(tile, poly, pos, closest[1])) + if (getPolyHeight(tile, poly, pos, ref closest[1])) { if (posOverPoly) posOverPoly = true; diff --git a/Source/Framework/RecastDetour/Detour/DetourNavMeshQuery.cs b/Source/Framework/RecastDetour/Detour/DetourNavMeshQuery.cs index 143b8ddf5..659b77c34 100644 --- a/Source/Framework/RecastDetour/Detour/DetourNavMeshQuery.cs +++ b/Source/Framework/RecastDetour/Detour/DetourNavMeshQuery.cs @@ -743,7 +743,7 @@ public static partial class Detour return DT_SUCCESS; } - return m_nav.getPolyHeight(tile, poly, pos, height) ? DT_SUCCESS : DT_FAILURE | DT_INVALID_PARAM; + return m_nav.getPolyHeight(tile, poly, pos, ref height) ? DT_SUCCESS : DT_FAILURE | DT_INVALID_PARAM; } // @} diff --git a/Source/Framework/Util/Extensions.cs b/Source/Framework/Util/Extensions.cs index 45b9332a6..bbc5f21d8 100644 --- a/Source/Framework/Util/Extensions.cs +++ b/Source/Framework/Util/Extensions.cs @@ -241,9 +241,16 @@ namespace System return a; } + public static Vector3 direction(this Vector3 vector) + { + float lenSquared = vector.LengthSquared(); + float invSqrt = 1.0f / MathF.Sqrt(lenSquared); + return new Vector3(vector.X * invSqrt, vector.Y * invSqrt, vector.Z * invSqrt); + } + public static Vector3 directionOrZero(this Vector3 vector) { - float mag = vector.Length(); + float mag = vector.LengthSquared(); if (mag < 0.0000001f) { return Vector3.Zero; diff --git a/Source/Game/Chat/Commands/MMapsCommands.cs b/Source/Game/Chat/Commands/MMapsCommands.cs index 687c3f2d4..e67023468 100644 --- a/Source/Game/Chat/Commands/MMapsCommands.cs +++ b/Source/Game/Chat/Commands/MMapsCommands.cs @@ -207,7 +207,7 @@ namespace Game.Chat for (int i = 0; i < navmesh.getMaxTiles(); ++i) { Detour.dtMeshTile tile = navmesh.getTile(i); - if (tile == null) + if (tile.header == null) continue; tileCount++; diff --git a/Source/Game/Movement/Generators/PathGenerator.cs b/Source/Game/Movement/Generators/PathGenerator.cs index f6baef3f8..b4e979e25 100644 --- a/Source/Game/Movement/Generators/PathGenerator.cs +++ b/Source/Game/Movement/Generators/PathGenerator.cs @@ -991,7 +991,7 @@ namespace Game.Movement // ok, _pathPoints[i] is too close, _pathPoints[i-1] is not, so our target point is somewhere between the two... // ... settle for a guesstimate since i'm not confident in doing trig on every chase motion tick... // (@todo review this) - _pathPoints[i] += (_pathPoints[i - 1] - _pathPoints[i]).directionOrZero() * (dist - (_pathPoints[i] - target).Length()); + _pathPoints[i] += (_pathPoints[i - 1] - _pathPoints[i]).direction() * (dist - (_pathPoints[i] - target).Length()); Array.Resize(ref _pathPoints, i + 1); }