bugfix - Arrays.Copy -> vector3f operator =

This commit is contained in:
ikpil 2023-04-01 00:51:17 +09:00
parent 00c3cd57f3
commit c81c2aded9
5 changed files with 67 additions and 80 deletions

View File

@ -116,15 +116,6 @@ namespace DotRecast.Core
/// @param[in] v1 The base vector. [(x, y, z)]
/// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)]
/// @param[in] s The amount to scale @p v2 by before adding to @p v1.
public static float[] vMad(float[] v1, float[] v2, float s)
{
Vector3f dest = new Vector3f();
dest[0] = v1[0] + v2[0] * s;
dest[1] = v1[1] + v2[1] * s;
dest[2] = v1[2] + v2[2] * s;
return dest.ToArray();
}
public static Vector3f vMad(Vector3f v1, Vector3f v2, float s)
{
Vector3f dest = new Vector3f();
@ -160,15 +151,6 @@ namespace DotRecast.Core
return dest.ToArray();
}
public static float[] vLerp(float[] v1, float[] v2, float t)
{
Vector3f dest = new Vector3f();
dest[0] = v1[0] + (v2[0] - v1[0]) * t;
dest[1] = v1[1] + (v2[1] - v1[1]) * t;
dest[2] = v1[2] + (v2[2] - v1[2]) * t;
return dest.ToArray();
}
public static Vector3f vLerp(Vector3f v1, Vector3f v2, float t)
{
Vector3f dest = new Vector3f();
@ -225,17 +207,6 @@ namespace DotRecast.Core
return dest;
}
public static float[] vAdd(float[] v1, float[] v2)
{
Vector3f dest = new Vector3f();
dest[0] = v1[0] + v2[0];
dest[1] = v1[1] + v2[1];
dest[2] = v1[2] + v2[2];
return dest.ToArray();
}
public static Vector3f vAdd(Vector3f v1, Vector3f v2)
{
Vector3f dest = new Vector3f();
@ -245,23 +216,6 @@ namespace DotRecast.Core
return dest;
}
public static float[] vCopy(float[] @in)
{
float[] @out = new float[3];
@out[0] = @in[0];
@out[1] = @in[1];
@out[2] = @in[2];
return @out;
}
public static void vSet(float[] @out, float a, float b, float c)
{
@out[0] = a;
@out[1] = b;
@out[2] = c;
}
public static void vSet(ref Vector3f @out, float a, float b, float c)
{
@out.x = a;
@ -269,14 +223,6 @@ namespace DotRecast.Core
@out.z = c;
}
public static void vCopy(float[] @out, float[] @in)
{
@out[0] = @in[0];
@out[1] = @in[1];
@out[2] = @in[2];
}
public static void vCopy(float[] @out, Vector3f @in)
{
@out[0] = @in[0];

View File

@ -2068,8 +2068,13 @@ namespace DotRecast.Detour
if (fromTile.links[i].refs == to)
{
int v = fromTile.links[i].edge;
Array.Copy(fromTile.data.verts, fromPoly.verts[v] * 3, left.ToArray(), 0, 3);
Array.Copy(fromTile.data.verts, fromPoly.verts[v] * 3, right.ToArray(), 0, 3);
left[0] = fromTile.data.verts[fromPoly.verts[v] * 3];
left[1] = fromTile.data.verts[fromPoly.verts[v] * 3 + 1];
left[2] = fromTile.data.verts[fromPoly.verts[v] * 3 + 2];
right[0] = fromTile.data.verts[fromPoly.verts[v] * 3];
right[1] = fromTile.data.verts[fromPoly.verts[v] * 3 + 1];
right[2] = fromTile.data.verts[fromPoly.verts[v] * 3 + 2];
return Results.success(new PortalResult(left, right, fromType, toType));
}
}
@ -2084,8 +2089,14 @@ namespace DotRecast.Detour
if (toTile.links[i].refs == from)
{
int v = toTile.links[i].edge;
Array.Copy(toTile.data.verts, toPoly.verts[v] * 3, left.ToArray(), 0, 3);
Array.Copy(toTile.data.verts, toPoly.verts[v] * 3, right.ToArray(), 0, 3);
left[0] = toTile.data.verts[toPoly.verts[v] * 3];
left[1] = toTile.data.verts[toPoly.verts[v] * 3 + 1];
left[2] = toTile.data.verts[toPoly.verts[v] * 3 + 2];
right[0] = toTile.data.verts[toPoly.verts[v] * 3];
right[1] = toTile.data.verts[toPoly.verts[v] * 3 + 1];
right[2] = toTile.data.verts[toPoly.verts[v] * 3 + 2];
return Results.success(new PortalResult(left, right, fromType, toType));
}
}
@ -2096,8 +2107,13 @@ namespace DotRecast.Detour
// Find portal vertices.
int v0 = fromPoly.verts[link.edge];
int v1 = fromPoly.verts[(link.edge + 1) % fromPoly.vertCount];
Array.Copy(fromTile.data.verts, v0 * 3, left.ToArray(), 0, 3);
Array.Copy(fromTile.data.verts, v1 * 3, right.ToArray(), 0, 3);
left[0] = fromTile.data.verts[v0 * 3];
left[1] = fromTile.data.verts[v0 * 3 + 1];
left[2] = fromTile.data.verts[v0 * 3 + 2];
right[0] = fromTile.data.verts[v1 * 3];
right[1] = fromTile.data.verts[v1 * 3 + 1];
right[2] = fromTile.data.verts[v1 * 3 + 2];
// If the link is at tile boundary, dtClamp the vertices to
// the link width.

View File

@ -27,7 +27,6 @@ using static DotRecast.Recast.RecastConstants;
namespace DotRecast.Recast
{
public class RecastMeshDetail
{
public const int MAX_VERTS = 127;
@ -109,7 +108,6 @@ namespace DotRecast.Recast
}
private static float vdistSq2(float[] p, float[] verts, int q)
{
float dx = verts[q + 0] - p[0];
@ -193,7 +191,7 @@ namespace DotRecast.Recast
return false;
}
private static float distPtTri(float[] p, float[] verts, int a, int b, int c)
private static float distPtTri(Vector3f p, float[] verts, int a, int b, int c)
{
Vector3f v0 = new Vector3f();
Vector3f v1 = new Vector3f();
@ -255,6 +253,34 @@ namespace DotRecast.Recast
return dx * dx + dy * dy + dz * dz;
}
private static float distancePtSeg2d(Vector3f verts, float[] poly, int p, int q)
{
float pqx = poly[q + 0] - poly[p + 0];
float pqz = poly[q + 2] - poly[p + 2];
float dx = verts[0] - poly[p + 0];
float dz = verts[2] - poly[p + 2];
float d = pqx * pqx + pqz * pqz;
float t = pqx * dx + pqz * dz;
if (d > 0)
{
t /= d;
}
if (t < 0)
{
t = 0;
}
else if (t > 1)
{
t = 1;
}
dx = poly[p + 0] + t * pqx - verts[0];
dz = poly[p + 2] + t * pqz - verts[2];
return dx * dx + dz * dz;
}
private static float distancePtSeg2d(float[] verts, int pt, float[] poly, int p, int q)
{
float pqx = poly[q + 0] - poly[p + 0];
@ -283,7 +309,7 @@ namespace DotRecast.Recast
return dx * dx + dz * dz;
}
private static float distToTriMesh(float[] p, float[] verts, int nverts, List<int> tris, int ntris)
private static float distToTriMesh(Vector3f p, float[] verts, int nverts, List<int> tris, int ntris)
{
float dmin = float.MaxValue;
for (int i = 0; i < ntris; ++i)
@ -306,7 +332,7 @@ namespace DotRecast.Recast
return dmin;
}
private static float distToPoly(int nvert, float[] verts, float[] p)
private static float distToPoly(int nvert, float[] verts, Vector3f p)
{
float dmin = float.MaxValue;
int i, j;
@ -321,7 +347,7 @@ namespace DotRecast.Recast
c = !c;
}
dmin = Math.Min(dmin, distancePtSeg2d(p, 0, verts, vj, vi));
dmin = Math.Min(dmin, distancePtSeg2d(p, verts, vj, vi));
}
return c ? -dmin : dmin;
@ -1009,7 +1035,7 @@ namespace DotRecast.Recast
pt[1] = (bmax[1] + bmin[1]) * 0.5f;
pt[2] = z * sampleDist;
// Make sure the samples are not too close to the edges.
if (distToPoly(nin, @in, pt.ToArray()) > -sampleDist / 2)
if (distToPoly(nin, @in, pt) > -sampleDist / 2)
{
continue;
}
@ -1050,7 +1076,7 @@ namespace DotRecast.Recast
pt[0] = samples[s + 0] * sampleDist + getJitterX(i) * cs * 0.1f;
pt[1] = samples[s + 1] * chf.ch;
pt[2] = samples[s + 2] * sampleDist + getJitterY(i) * cs * 0.1f;
float d = distToTriMesh(pt.ToArray(), verts, nverts, tris, tris.Count / 4);
float d = distToTriMesh(pt, verts, nverts, tris, tris.Count / 4);
if (d < 0)
{
continue; // did not hit the mesh.

View File

@ -177,7 +177,7 @@ namespace DotRecast.Recast
e0[2] = i[2] - verts[j + 2];
}
public static void sub(ref Vector3f e0, float[] i, float[] verts, int j)
public static void sub(ref Vector3f e0, Vector3f i, float[] verts, int j)
{
e0[0] = i[0] - verts[j];
e0[1] = i[1] - verts[j + 1];

View File

@ -56,8 +56,7 @@ public class FindLocalNeighbourhoodTest : AbstractDetourTest
for (int i = 0; i < startRefs.Length; i++)
{
Vector3f startPos = startPoss[i];
Result<FindLocalNeighbourhoodResult> poly = query.findLocalNeighbourhood(startRefs[i], startPos, 3.5f,
filter);
Result<FindLocalNeighbourhoodResult> poly = query.findLocalNeighbourhood(startRefs[i], startPos, 3.5f, filter);
Assert.That(poly.result.getRefs().Count, Is.EqualTo(REFS[i].Length));
for (int v = 0; v < REFS[i].Length; v++)
{