DotRecastNetSim/src/DotRecast.Detour.Extras/Jumplink/AbstractGroundSampler.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
using System;
2023-03-28 19:52:26 +03:00
using DotRecast.Core;
2023-03-14 08:02:43 +03:00
using DotRecast.Recast;
2023-03-25 09:43:20 +03:00
using static DotRecast.Core.RecastMath;
2023-03-14 08:02:43 +03:00
2023-03-16 19:09:10 +03:00
namespace DotRecast.Detour.Extras.Jumplink
{
2023-03-16 19:48:49 +03:00
public abstract class AbstractGroundSampler : GroundSampler
2023-03-14 08:02:43 +03:00
{
2023-03-16 19:48:49 +03:00
protected void sampleGround(JumpLinkBuilderConfig acfg, EdgeSampler es,
2023-03-28 19:52:26 +03:00
Func<Vector3f, float, Tuple<bool, float>> heightFunc)
2023-03-16 19:48:49 +03:00
{
float cs = acfg.cellSize;
float dist = (float)Math.Sqrt(vDist2DSqr(es.start.p, es.start.q));
int ngsamples = Math.Max(2, (int)Math.Ceiling(dist / cs));
sampleGroundSegment(heightFunc, es.start, ngsamples);
foreach (GroundSegment end in es.end)
{
sampleGroundSegment(heightFunc, end, ngsamples);
}
}
2023-03-14 08:02:43 +03:00
2023-03-26 07:51:30 +03:00
public abstract void sample(JumpLinkBuilderConfig acfg, RecastBuilderResult result, EdgeSampler es);
2023-03-14 08:02:43 +03:00
2023-03-28 19:52:26 +03:00
protected void sampleGroundSegment(Func<Vector3f, float, Tuple<bool, float>> heightFunc, GroundSegment seg, int nsamples)
2023-03-16 19:48:49 +03:00
{
seg.gsamples = new GroundSample[nsamples];
for (int i = 0; i < nsamples; ++i)
{
float u = i / (float)(nsamples - 1);
GroundSample s = new GroundSample();
seg.gsamples[i] = s;
2023-03-28 19:52:26 +03:00
Vector3f pt = vLerp(seg.p, seg.q, u);
2023-03-16 19:48:49 +03:00
Tuple<bool, float> height = heightFunc.Invoke(pt, seg.height);
s.p[0] = pt[0];
s.p[1] = height.Item2;
s.p[2] = pt[2];
if (!height.Item1)
{
continue;
}
s.validHeight = true;
2023-03-14 08:02:43 +03:00
}
}
}
2023-03-16 19:09:10 +03:00
}