From 8260ebbe52ff301003e5d0e35ca449e23e37f361 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 16 Apr 2023 17:34:04 +0900 Subject: [PATCH] changed new float[] -> Vector3f --- src/DotRecast.Core/RecastMath.cs | 10 ---------- src/DotRecast.Core/Vector2f.cs | 2 +- .../Unity/Astar/OffMeshLinkCreator.cs | 4 ++-- src/DotRecast.Detour/NavMeshQuery.cs | 15 ++++++--------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/DotRecast.Core/RecastMath.cs b/src/DotRecast.Core/RecastMath.cs index 59b1f9c..1c1c5fe 100644 --- a/src/DotRecast.Core/RecastMath.cs +++ b/src/DotRecast.Core/RecastMath.cs @@ -939,16 +939,6 @@ namespace DotRecast.Core return Tuple.Create(s, t); } - - public static float[] vScale(float[] @in, float scale) - { - float[] @out = new float[3]; - @out[0] = @in[0] * scale; - @out[1] = @in[1] * scale; - @out[2] = @in[2] * scale; - return @out; - } - public static Vector3f vScale(Vector3f @in, float scale) { var @out = new Vector3f(); diff --git a/src/DotRecast.Core/Vector2f.cs b/src/DotRecast.Core/Vector2f.cs index 6a13434..71e4627 100644 --- a/src/DotRecast.Core/Vector2f.cs +++ b/src/DotRecast.Core/Vector2f.cs @@ -7,7 +7,7 @@ namespace DotRecast.Core public float x; public float y; - public static readonly Vector2f Zero = new Vector2f { x = 0, y = 0 }; + public static Vector2f Zero { get; } = new Vector2f { x = 0, y = 0 }; public float Get(int idx) { diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs index d9af41a..005a2c4 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs @@ -48,8 +48,8 @@ namespace DotRecast.Detour.Extras.Unity.Astar connection.poly = poly; connection.pos = new float[] { - l.clamped1.x, l.clamped1.y, l.clamped1.z, l.clamped2.x, l.clamped2.y, - l.clamped2.z + l.clamped1.x, l.clamped1.y, l.clamped1.z, + l.clamped2.x, l.clamped2.y, l.clamped2.z }; connection.rad = 0.1f; connection.side = startTile == endTile diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index 69307df..025d7c7 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -2241,7 +2241,8 @@ namespace DotRecast.Detour float[] verts = new float[m_nav.getMaxVertsPerPoly() * 3 + 3]; - Vector3f curPos = new Vector3f(), lastPos = new Vector3f(); + Vector3f curPos = Vector3f.Zero; + Vector3f lastPos = Vector3f.Zero; curPos = startPos; var dir = vSub(endPos, startPos); @@ -2369,9 +2370,7 @@ namespace DotRecast.Detour + (tile.data.verts[right + 2] - tile.data.verts[left + 2]) * (link.bmax * s); if (lmin > lmax) { - float temp = lmin; - lmin = lmax; - lmax = temp; + (lmin, lmax) = (lmax, lmin); } // Find Z intersection. @@ -2391,9 +2390,7 @@ namespace DotRecast.Detour + (tile.data.verts[right] - tile.data.verts[left]) * (link.bmax * s); if (lmin > lmax) { - float temp = lmin; - lmin = lmax; - lmax = temp; + (lmin, lmax) = (lmax, lmin); } // Find X intersection. @@ -2692,7 +2689,7 @@ namespace DotRecast.Detour m_nodePool.clear(); m_openList.clear(); - float[] centerPos = new float[] { 0, 0, 0 }; + Vector3f centerPos = Vector3f.Zero; for (int i = 0; i < nverts; ++i) { centerPos[0] += verts[i * 3]; @@ -2706,7 +2703,7 @@ namespace DotRecast.Detour centerPos[2] *= scale; Node startNode = m_nodePool.getNode(startRef); - vCopy(ref startNode.pos, centerPos); + startNode.pos = centerPos; startNode.pidx = 0; startNode.cost = 0; startNode.total = 0;