forked from mirror/DotRecast
update RandomPointInConvexPoly()
This commit is contained in:
parent
dfbd1b2cae
commit
61e7b7a443
|
@ -68,8 +68,8 @@ namespace DotRecast.Detour
|
|||
float tsum = 0.0f;
|
||||
for (int i = 0; i < m_nav.GetMaxTiles(); i++)
|
||||
{
|
||||
DtMeshTile mt = m_nav.GetTile(i);
|
||||
if (mt == null || mt.data == null || mt.data.header == null)
|
||||
DtMeshTile t = m_nav.GetTile(i);
|
||||
if (t == null || t.data == null || t.data.header == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace DotRecast.Detour
|
|||
float u = frand.Next();
|
||||
if (u * tsum <= area)
|
||||
{
|
||||
tile = mt;
|
||||
tile = t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,9 +146,9 @@ namespace DotRecast.Detour
|
|||
}
|
||||
|
||||
float s = frand.Next();
|
||||
float t = frand.Next();
|
||||
float t0 = frand.Next();
|
||||
|
||||
var pt = DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t);
|
||||
DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t0, out var pt);
|
||||
ClosestPointOnPoly(polyRef, pt, out var closest, out var _);
|
||||
|
||||
randomRef = polyRef;
|
||||
|
@ -387,7 +387,7 @@ namespace DotRecast.Detour
|
|||
float t = frand.Next();
|
||||
|
||||
Span<float> areas = stackalloc float[randomPolyVerts.Length / 3];
|
||||
RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
|
||||
DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t, out var pt);
|
||||
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
|
||||
|
||||
randomRef = randomPolyRef;
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace DotRecast.Detour
|
|||
|
||||
// Returns a random point in a convex polygon.
|
||||
// Adapted from Graphics Gems article.
|
||||
public static RcVec3f RandomPointInConvexPoly(Span<float> pts, int npts, Span<float> areas, float s, float t)
|
||||
public static void RandomPointInConvexPoly(Span<float> pts, int npts, Span<float> areas, float s, float t, out RcVec3f @out)
|
||||
{
|
||||
// Calc triangle araes
|
||||
float areasum = 0.0f;
|
||||
|
@ -202,7 +202,7 @@ namespace DotRecast.Detour
|
|||
int pb = (tri - 1) * 3;
|
||||
int pc = tri * 3;
|
||||
|
||||
return new RcVec3f()
|
||||
@out = new RcVec3f()
|
||||
{
|
||||
X = a * pts[pa] + b * pts[pb] + c * pts[pc],
|
||||
Y = a * pts[pa + 1] + b * pts[pb + 1] + c * pts[pc + 1],
|
||||
|
|
Loading…
Reference in New Issue