diff --git a/src/DotRecast.Core/RcVec3f.cs b/src/DotRecast.Core/RcVec3f.cs index eb476011..c6c360fc 100644 --- a/src/DotRecast.Core/RcVec3f.cs +++ b/src/DotRecast.Core/RcVec3f.cs @@ -33,11 +33,6 @@ public struct RcVec3f public static RcVec3f UnitY { get; } = new RcVec3f(0.0f, 1.0f, 0.0f); public static RcVec3f UnitZ { get; } = new RcVec3f(0.0f, 0.0f, 1.0f); - public static RcVec3f Of(float[] f, int idx) - { - return new RcVec3f(f[idx + 0], f[idx + 1], f[idx + 2]); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public RcVec3f(float x, float y, float z) { diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs index 9ac0f6aa..1151a94c 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs @@ -16,6 +16,7 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ +using System; using DotRecast.Core; namespace DotRecast.Detour.Extras.Unity.Astar @@ -54,7 +55,7 @@ public void Build(GraphMeshData graphData, NodeLink2[] links, int nodeOffset) connection.rad = 0.1f; connection.side = startTile == endTile ? 0xFF - : DtNavMeshBuilder.ClassifyOffMeshPoint(RcVec3f.Of(connection.pos, 3), startTile.header.bmin, startTile.header.bmax); + : DtNavMeshBuilder.ClassifyOffMeshPoint(new RcVec3f(connection.pos.AsSpan(3)), startTile.header.bmin, startTile.header.bmax); connection.userId = (int)l.linkID; if (startTile.offMeshCons == null) { diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 5df8d3ed..ff3ec300 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -1568,8 +1568,8 @@ public DtStatus GetOffMeshConnectionPolyEndPoints(long prevRef, long polyRef, re } } - startPos = RcVec3f.Of(tile.data.verts, poly.verts[idx0] * 3); - endPos = RcVec3f.Of(tile.data.verts, poly.verts[idx1] * 3); + startPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx0] * 3)); + endPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx1] * 3)); return DtStatus.DT_SUCCSESS; } diff --git a/src/DotRecast.Detour/DtNavMeshBuilder.cs b/src/DotRecast.Detour/DtNavMeshBuilder.cs index 53716187..0b64949e 100644 --- a/src/DotRecast.Detour/DtNavMeshBuilder.cs +++ b/src/DotRecast.Detour/DtNavMeshBuilder.cs @@ -319,8 +319,8 @@ public static DtMeshData CreateNavMeshData(DtNavMeshCreateParams option) for (int i = 0; i < option.offMeshConCount; ++i) { - var p0 = RcVec3f.Of(option.offMeshConVerts, (i * 2 + 0) * 3); - var p1 = RcVec3f.Of(option.offMeshConVerts, (i * 2 + 1) * 3); + var p0 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 0) * 3)); + var p1 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 1) * 3)); offMeshConClass[i * 2 + 0] = ClassifyOffMeshPoint(p0, bmin, bmax); offMeshConClass[i * 2 + 1] = ClassifyOffMeshPoint(p1, bmin, bmax); diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 3a00a1c9..c9d630da 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -2202,7 +2202,7 @@ public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQuer int nv = 0; for (int i = 0; i < poly.vertCount; ++i) { - verts[nv] = RcVec3f.Of(tile.data.verts, poly.verts[i] * 3); + verts[nv] = new RcVec3f(tile.data.verts.AsSpan(poly.verts[i] * 3)); nv++; } @@ -3215,8 +3215,8 @@ public virtual DtStatus FindDistanceToWall(long startRef, RcVec3f centerPos, flo hitPos.Y = bestTile.data.verts[vj + 1] + (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg; hitPos.Z = bestTile.data.verts[vj + 2] + (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg; hasBestV = true; - bestvj = RcVec3f.Of(bestTile.data.verts, vj); - bestvi = RcVec3f.Of(bestTile.data.verts, vi); + bestvj = new RcVec3f(bestTile.data.verts.AsSpan(vj)); + bestvi = new RcVec3f(bestTile.data.verts.AsSpan(vi)); } for (int i = bestTile.polyLinks[bestPoly.index]; i != DtNavMesh.DT_NULL_LINK; i = bestTile.links[i].next) diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index 75ced437..0c5e5851 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -308,8 +308,8 @@ public static bool DistancePtPolyEdgesSqr(RcVec3f pt, float[] verts, int nverts, public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t) { - var vp = RcVec3f.Of(verts, p); - var vq = RcVec3f.Of(verts, q); + var vp = new RcVec3f(verts.AsSpan(p)); + var vq = new RcVec3f(verts.AsSpan(q)); return DistancePtSegSqr2D(pt, vp, vq, out t); } diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index 70cb044f..e544beed 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -753,9 +753,9 @@ public static int OffsetPoly(float[] verts, int numVerts, float offset, float[] int vertIndexB = vertIndex; int vertIndexC = (vertIndex + 1) % numVerts; - RcVec3f vertA = RcVec3f.Of(verts, vertIndexA * 3); - RcVec3f vertB = RcVec3f.Of(verts, vertIndexB * 3); - RcVec3f vertC = RcVec3f.Of(verts, vertIndexC * 3); + RcVec3f vertA = new RcVec3f(verts.AsSpan(vertIndexA * 3)); + RcVec3f vertB = new RcVec3f(verts.AsSpan(vertIndexB * 3)); + RcVec3f vertC = new RcVec3f(verts.AsSpan(vertIndexC * 3)); // From A to B on the x/z plane RcVec3f prevSegmentDir = vertB.Subtract(vertA);