forked from bit/DotRecastNetSim
refactor: support .netstandard2.1 vector3
This commit is contained in:
parent
2e7a75624c
commit
5176ee036a
|
@ -49,15 +49,6 @@ namespace DotRecast.Core.Numerics
|
||||||
Z = f;
|
Z = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
// public RcVec3f(ReadOnlySpan<float> values)
|
|
||||||
// {
|
|
||||||
// X = values[0];
|
|
||||||
// Y = values[1];
|
|
||||||
// Z = values[2];
|
|
||||||
// }
|
|
||||||
|
|
||||||
public float this[int index]
|
public float this[int index]
|
||||||
{
|
{
|
||||||
get => GetElement(index);
|
get => GetElement(index);
|
||||||
|
|
|
@ -217,9 +217,9 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
RcVec3f a = new RcVec3f(1f - 2 * (float)random.NextDouble(), 0.01f + (float)random.NextDouble(), 1f - 2 * (float)random.NextDouble());
|
RcVec3f a = new RcVec3f(1f - 2 * (float)random.NextDouble(), 0.01f + (float)random.NextDouble(), 1f - 2 * (float)random.NextDouble());
|
||||||
a = RcVec3f.Normalize(a);
|
a = RcVec3f.Normalize(a);
|
||||||
float len = 2f + (float)random.NextDouble() * 20f;
|
float len = 2f + (float)random.NextDouble() * 20f;
|
||||||
a[0] *= len;
|
a.X *= len;
|
||||||
a[1] *= len;
|
a.Y *= len;
|
||||||
a[2] *= len;
|
a.Z *= len;
|
||||||
RcVec3f start = new RcVec3f(p.X, p.Y, p.Z);
|
RcVec3f start = new RcVec3f(p.X, p.Y, p.Z);
|
||||||
RcVec3f end = new RcVec3f(p.X + a.X, p.Y + a.Y, p.Z + a.Z);
|
RcVec3f end = new RcVec3f(p.X + a.X, p.Y + a.Y, p.Z + a.Z);
|
||||||
var collider = new DtCylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
var collider = new DtCylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
||||||
|
|
|
@ -126,8 +126,8 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||||
|
|
||||||
int tx = (int)((pos.X - bmin[0]) / ts);
|
int tx = (int)((pos.X - bmin.X) / ts);
|
||||||
int ty = (int)((pos.Z - bmin[2]) / ts);
|
int ty = (int)((pos.Z - bmin.Z) / ts);
|
||||||
|
|
||||||
return BuildTile(geom, settings, navMesh, tx, ty, out tileBuildTicks, out tileTriCount, out tileMemUsage);
|
return BuildTile(geom, settings, navMesh, tx, ty, out tileBuildTicks, out tileTriCount, out tileMemUsage);
|
||||||
}
|
}
|
||||||
|
@ -141,8 +141,8 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
|
|
||||||
var bmin = geom.GetMeshBoundsMin();
|
var bmin = geom.GetMeshBoundsMin();
|
||||||
|
|
||||||
int tx = (int)((pos.X - bmin[0]) / ts);
|
int tx = (int)((pos.X - bmin.X) / ts);
|
||||||
int ty = (int)((pos.Z - bmin[2]) / ts);
|
int ty = (int)((pos.Z - bmin.Z) / ts);
|
||||||
|
|
||||||
var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
|
var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
|
||||||
navMesh.RemoveTile(tileRef);
|
navMesh.RemoveTile(tileRef);
|
||||||
|
|
|
@ -647,8 +647,8 @@ namespace DotRecast.Recast
|
||||||
RcCompactCell cell = compactHeightfield.cells[x + z * zStride];
|
RcCompactCell cell = compactHeightfield.cells[x + z * zStride];
|
||||||
int maxSpanIndex = cell.index + cell.count;
|
int maxSpanIndex = cell.index + cell.count;
|
||||||
|
|
||||||
float cellX = compactHeightfield.bmin[0] + ((float)x + 0.5f) * compactHeightfield.cs;
|
float cellX = compactHeightfield.bmin.X + ((float)x + 0.5f) * compactHeightfield.cs;
|
||||||
float cellZ = compactHeightfield.bmin[2] + ((float)z + 0.5f) * compactHeightfield.cs;
|
float cellZ = compactHeightfield.bmin.Z + ((float)z + 0.5f) * compactHeightfield.cs;
|
||||||
float deltaX = cellX - position[0];
|
float deltaX = cellX - position[0];
|
||||||
float deltaZ = cellZ - position[2];
|
float deltaZ = cellZ - position[2];
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ freely, subject to the following restrictions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Test;
|
namespace DotRecast.Detour.Test;
|
||||||
|
@ -27,11 +26,13 @@ public class FindNearestPolyTest : AbstractDetourTest
|
||||||
{
|
{
|
||||||
private static readonly long[] POLY_REFS = { 281474976710696L, 281474976710773L, 281474976710680L, 281474976710753L, 281474976710733L };
|
private static readonly long[] POLY_REFS = { 281474976710696L, 281474976710773L, 281474976710680L, 281474976710753L, 281474976710733L };
|
||||||
|
|
||||||
private static readonly float[][] POLY_POS =
|
private static readonly RcVec3f[] POLY_POS =
|
||||||
{
|
{
|
||||||
new[] { 22.606520f, 10.197294f, -45.918674f }, new[] { 22.331268f, 10.197294f, -1.040187f },
|
new RcVec3f(22.606520f, 10.197294f, -45.918674f),
|
||||||
new[] { 18.694363f, 15.803535f, -73.090416f }, new[] { 0.745335f, 10.197294f, -5.940050f },
|
new RcVec3f(22.331268f, 10.197294f, -1.040187f),
|
||||||
new[] { -20.651257f, 5.904126f, -13.712508f }
|
new RcVec3f(18.694363f, 15.803535f, -73.090416f),
|
||||||
|
new RcVec3f(0.745335f, 10.197294f, -5.940050f),
|
||||||
|
new RcVec3f(-20.651257f, 5.904126f, -13.712508f)
|
||||||
};
|
};
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -45,10 +46,9 @@ public class FindNearestPolyTest : AbstractDetourTest
|
||||||
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _);
|
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _);
|
||||||
Assert.That(status.Succeeded(), Is.True);
|
Assert.That(status.Succeeded(), Is.True);
|
||||||
Assert.That(nearestRef, Is.EqualTo(POLY_REFS[i]));
|
Assert.That(nearestRef, Is.EqualTo(POLY_REFS[i]));
|
||||||
for (int v = 0; v < POLY_POS[i].Length; v++)
|
Assert.That(nearestPt.X, Is.EqualTo(POLY_POS[i].X).Within(0.001f));
|
||||||
{
|
Assert.That(nearestPt.Y, Is.EqualTo(POLY_POS[i].Y).Within(0.001f));
|
||||||
Assert.That(nearestPt[v], Is.EqualTo(POLY_POS[i][v]).Within(0.001f));
|
Assert.That(nearestPt.Z, Is.EqualTo(POLY_POS[i].Z).Within(0.001f));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +63,9 @@ public class FindNearestPolyTest : AbstractDetourTest
|
||||||
var status = query.FindNearestPoly(startPos, extents, DtQueryEmptyFilter.Shared, out var nearestRef, out var nearestPt, out var _);
|
var status = query.FindNearestPoly(startPos, extents, DtQueryEmptyFilter.Shared, out var nearestRef, out var nearestPt, out var _);
|
||||||
Assert.That(status.Succeeded(), Is.True);
|
Assert.That(status.Succeeded(), Is.True);
|
||||||
Assert.That(nearestRef, Is.EqualTo(0L));
|
Assert.That(nearestRef, Is.EqualTo(0L));
|
||||||
for (int v = 0; v < POLY_POS[i].Length; v++)
|
Assert.That(nearestPt.X, Is.EqualTo(startPos.X).Within(0.001f));
|
||||||
{
|
Assert.That(nearestPt.Y, Is.EqualTo(startPos.Y).Within(0.001f));
|
||||||
Assert.That(nearestPt[v], Is.EqualTo(startPos[v]).Within(0.001f));
|
Assert.That(nearestPt.Z, Is.EqualTo(startPos.Z).Within(0.001f));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,6 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Test;
|
namespace DotRecast.Detour.Test;
|
||||||
|
@ -199,11 +198,9 @@ public class FindPathTest : AbstractDetourTest
|
||||||
for (int j = 0; j < STRAIGHT_PATHS[i].Length; j++)
|
for (int j = 0; j < STRAIGHT_PATHS[i].Length; j++)
|
||||||
{
|
{
|
||||||
Assert.That(straightPath[j].refs, Is.EqualTo(STRAIGHT_PATHS[i][j].refs));
|
Assert.That(straightPath[j].refs, Is.EqualTo(STRAIGHT_PATHS[i][j].refs));
|
||||||
for (int v = 0; v < 3; v++)
|
Assert.That(straightPath[j].pos.X, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.X).Within(0.01f));
|
||||||
{
|
Assert.That(straightPath[j].pos.Y, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.Y).Within(0.01f));
|
||||||
Assert.That(straightPath[j].pos[v], Is.EqualTo(STRAIGHT_PATHS[i][j].pos[v]).Within(0.01f));
|
Assert.That(straightPath[j].pos.Z, Is.EqualTo(STRAIGHT_PATHS[i][j].pos.Z).Within(0.01f));
|
||||||
}
|
|
||||||
|
|
||||||
Assert.That(straightPath[j].flags, Is.EqualTo(STRAIGHT_PATHS[i][j].flags));
|
Assert.That(straightPath[j].flags, Is.EqualTo(STRAIGHT_PATHS[i][j].flags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Test;
|
namespace DotRecast.Detour.Test;
|
||||||
|
@ -57,13 +56,13 @@ public class MoveAlongSurfaceTest : AbstractDetourTest
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly float[][] POSITION =
|
private static readonly RcVec3f[] POSITION =
|
||||||
{
|
{
|
||||||
new[] { 6.457663f, 10.197294f, -18.334061f },
|
new RcVec3f(6.457663f, 10.197294f, -18.334061f),
|
||||||
new[] { -1.433933f, 10.197294f, -1.359993f },
|
new RcVec3f(-1.433933f, 10.197294f, -1.359993f),
|
||||||
new[] { 12.184784f, 9.997294f, -18.941269f },
|
new RcVec3f(12.184784f, 9.997294f, -18.941269f),
|
||||||
new[] { 0.863553f, 10.197294f, -10.310320f },
|
new RcVec3f(0.863553f, 10.197294f, -10.310320f),
|
||||||
new[] { 18.784092f, 10.197294f, 3.054368f }
|
new RcVec3f(18.784092f, 10.197294f, 3.054368f),
|
||||||
};
|
};
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -78,14 +77,13 @@ public class MoveAlongSurfaceTest : AbstractDetourTest
|
||||||
RcVec3f endPos = endPoss[i];
|
RcVec3f endPos = endPoss[i];
|
||||||
var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, ref visited);
|
var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, ref visited);
|
||||||
Assert.That(status.Succeeded(), Is.True);
|
Assert.That(status.Succeeded(), Is.True);
|
||||||
|
|
||||||
for (int v = 0; v < 3; v++)
|
Assert.That(result.X, Is.EqualTo(POSITION[i].X).Within(0.01f));
|
||||||
{
|
Assert.That(result.Y, Is.EqualTo(POSITION[i].Y).Within(0.01f));
|
||||||
Assert.That(result[v], Is.EqualTo(POSITION[i][v]).Within(0.01f));
|
Assert.That(result.Z, Is.EqualTo(POSITION[i].Z).Within(0.01f));
|
||||||
}
|
|
||||||
|
|
||||||
Assert.That(visited.Count, Is.EqualTo(VISITED[i].Length));
|
Assert.That(visited.Count, Is.EqualTo(VISITED[i].Length));
|
||||||
for (int j = 0; j < POSITION[i].Length; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
Assert.That(visited[j], Is.EqualTo(VISITED[i][j]));
|
Assert.That(visited[j], Is.EqualTo(VISITED[i][j]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue