forked from mirror/DotRecast
heap memory optimization
This commit is contained in:
parent
ebb77c5465
commit
cd39cbbd36
|
@ -0,0 +1,14 @@
|
|||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
public struct IsectRaySegResult
|
||||
{
|
||||
public readonly bool result;
|
||||
public readonly float htmin;
|
||||
|
||||
public IsectRaySegResult(bool result, float htmin)
|
||||
{
|
||||
this.result = result;
|
||||
this.htmin = htmin;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -207,21 +207,24 @@ namespace DotRecast.Detour.Crowd
|
|||
return new SweepCircleCircleResult(true, (b - rd) * a, (b + rd) * a);
|
||||
}
|
||||
|
||||
Tuple<bool, float> isectRaySeg(Vector3f ap, Vector3f u, Vector3f bp, Vector3f bq)
|
||||
IsectRaySegResult isectRaySeg(Vector3f ap, Vector3f u, Vector3f bp, Vector3f bq)
|
||||
{
|
||||
Vector3f v = vSub(bq, bp);
|
||||
Vector3f w = vSub(ap, bp);
|
||||
float d = vPerp2D(u, v);
|
||||
if (Math.Abs(d) < 1e-6f)
|
||||
return Tuple.Create(false, 0f);
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
d = 1.0f / d;
|
||||
float t = vPerp2D(v, w) * d;
|
||||
if (t < 0 || t > 1)
|
||||
return Tuple.Create(false, 0f);
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
float s = vPerp2D(u, w) * d;
|
||||
if (s < 0 || s > 1)
|
||||
return Tuple.Create(false, 0f);
|
||||
return Tuple.Create(true, t);
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
return new IsectRaySegResult(true, t);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -310,10 +313,11 @@ namespace DotRecast.Detour.Crowd
|
|||
}
|
||||
else
|
||||
{
|
||||
Tuple<bool, float> ires = isectRaySeg(pos, vcand, seg.p, seg.q);
|
||||
if (!ires.Item1)
|
||||
var ires = isectRaySeg(pos, vcand, seg.p, seg.q);
|
||||
if (!ires.result)
|
||||
continue;
|
||||
htmin = ires.Item2;
|
||||
|
||||
htmin = ires.htmin;
|
||||
}
|
||||
|
||||
// Avoid less when facing walls.
|
||||
|
|
|
@ -20,7 +20,7 @@ freely, subject to the following restrictions:
|
|||
|
||||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
public class SweepCircleCircleResult
|
||||
public struct SweepCircleCircleResult
|
||||
{
|
||||
public readonly bool intersection;
|
||||
public readonly float htmin;
|
||||
|
|
Loading…
Reference in New Issue