Fixes using gameobject like chairs, also fixes indoor checks

This commit is contained in:
hondacrx
2022-07-13 15:02:06 -04:00
parent 206c5afcca
commit d05595e44c
9 changed files with 168 additions and 48 deletions
@@ -1,4 +1,5 @@
using System;
using System.Numerics;
public static partial class Detour
{
@@ -180,6 +181,22 @@ public static partial class Detour
return dx * dx + dz * dz;
}
public static float dtDistancePtSegSqr2D(float[] pt, int ptStart, Vector3 p, Vector3 q, ref float t)
{
float pqx = q.GetAt(0) - p.GetAt(0);
float pqz = q.GetAt(2) - p.GetAt(2);
float dx = pt[ptStart + 0] - p.GetAt(0);
float dz = pt[ptStart + 2] - p.GetAt(2);
float d = pqx * pqx + pqz * pqz;
t = pqx * dx + pqz * dz;
if (d > 0) t /= d;
if (t < 0) t = 0;
else if (t > 1) t = 1;
dx = p.GetAt(0) + t * pqx - pt[ptStart + 0];
dz = p.GetAt(2) + t * pqz - pt[ptStart + 2];
return dx * dx + dz * dz;
}
/// Derives the centroid of a convex polygon.
/// @param[out] tc The centroid of the polgyon. [(x, y, z)]
/// @param[in] idx The polygon indices. [(vertIndex) * @p nidx]
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
/**
@typedef dtPolyRef
@par
@@ -735,31 +737,30 @@ public static partial class Detour
float tmin = 0;
int pmin = 0;
int pmax = 0;
float[] v = new float[0];
Vector3[] v = new Vector3[3];
for (int i = 0; i < pd.triCount; i++)
{
int trisIndex = (int)((pd.triBase + i) * 4);
Span<byte> tris = tile.detailTris.AsSpan().Slice((int)(pd.triBase + i) * 4);
const int ANY_BOUNDARY_EDGE =
((int)dtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 0) |
((int)dtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 2) |
((int)dtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 4);
if (onlyBoundary && (tile.detailTris[trisIndex + 3] & ANY_BOUNDARY_EDGE) == 0)
if (onlyBoundary && (tris[3] & ANY_BOUNDARY_EDGE) == 0)
continue;
v = new float[3];
for (int j = 0; j < 3; ++j)
{
if (tile.detailTris[trisIndex + j] < poly.vertCount)
v[j] = tile.verts[poly.verts[tile.detailTris[trisIndex + j]] * 3];
if (tris[j] < poly.vertCount)
v[j] = new(tile.verts.AsSpan(poly.verts[tris[j]] * 3));
else
v[j] = tile.detailVerts[(pd.vertBase + (tile.detailTris[trisIndex + j] - poly.vertCount)) * 3];
v[j] = new(tile.detailVerts.AsSpan((int)(pd.vertBase + (tris[j] - poly.vertCount)) * 3));
}
for (int k = 0, j = 2; k < 3; j = k++)
{
if ((dtGetDetailTriEdgeFlags(tile.detailTris[trisIndex + 3], j) & (int)dtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY) == 0 &&
(onlyBoundary || tile.detailTris[trisIndex + j] < tile.detailTris[trisIndex + k]))
if ((dtGetDetailTriEdgeFlags(tris[3], j) & (int)dtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY) == 0 &&
(onlyBoundary || tris[j] < tris[k]))
{
// Only looking at boundary edges and this is internal, or
// this is an inner edge that we will see again or have already seen.
@@ -767,7 +768,7 @@ public static partial class Detour
}
float t = 0;
float d = dtDistancePtSegSqr2D(pos, 0, v, j, v, k, ref t);
float d = dtDistancePtSegSqr2D(pos, 0, v[j], v[k], ref t);
if (d < dmin)
{
dmin = d;
@@ -778,7 +779,7 @@ public static partial class Detour
}
}
dtVlerp(closest, 0, v, pmin, v, pmax, tmin);
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)
@@ -1911,7 +1911,7 @@ public static partial class Detour
for (int i = 0; i < pathSize; ++i)
{
float[] left = new float[3];//, right[3];
float[] left = new float[3];
float[] right = new float[3];
byte fromType = 0, toType = 0;