OffMeshConnectionTool, impl

This commit is contained in:
ikpil 2023-06-28 23:12:32 +09:00
parent 1cb7bbb7a1
commit 97c426966b
3 changed files with 69 additions and 28 deletions

View File

@ -35,7 +35,6 @@ public class OffMeshConnectionTool : IRcTool
private readonly OffMeshConnectionToolImpl _impl;
private bool hitPosSet;
private RcVec3f hitPos;
private int bidir;
public OffMeshConnectionTool()
{
@ -62,24 +61,7 @@ public class OffMeshConnectionTool : IRcTool
if (shift)
{
// Delete
// Find nearest link end-point
float nearestDist = float.MaxValue;
DemoOffMeshConnection nearestConnection = null;
foreach (DemoOffMeshConnection offMeshCon in geom.GetOffMeshConnections())
{
float d = Math.Min(RcVec3f.DistSqr(p, offMeshCon.verts, 0), RcVec3f.DistSqr(p, offMeshCon.verts, 3));
if (d < nearestDist && Math.Sqrt(d) < _impl.GetSample().GetSettings().agentRadius)
{
nearestDist = d;
nearestConnection = offMeshCon;
}
}
if (nearestConnection != null)
{
geom.GetOffMeshConnections().Remove(nearestConnection);
}
_impl.Remove(p);
}
else
{
@ -91,9 +73,7 @@ public class OffMeshConnectionTool : IRcTool
}
else
{
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP;
int flags = SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP;
geom.AddOffMeshConnection(hitPos, p, _impl.GetSample().GetSettings().agentRadius, 0 == bidir, area, flags);
_impl.Add(hitPos, p);
hitPosSet = false;
}
}
@ -123,8 +103,9 @@ public class OffMeshConnectionTool : IRcTool
public void Layout()
{
ImGui.RadioButton("One Way", ref bidir, 0);
ImGui.RadioButton("Bidirectional", ref bidir, 1);
var options = _impl.GetOptions();
ImGui.RadioButton("One Way", ref options.bidir, 0);
ImGui.RadioButton("Bidirectional", ref options.bidir, 1);
}

View File

@ -1,8 +1,19 @@
namespace DotRecast.Recast.DemoTool.Tools
using System;
using DotRecast.Core;
using DotRecast.Recast.DemoTool.Builder;
using DotRecast.Recast.DemoTool.Geom;
namespace DotRecast.Recast.DemoTool.Tools
{
public class OffMeshConnectionToolImpl : ISampleTool
{
private Sample _sample;
private readonly OffMeshConnectionToolOptions _options;
public OffMeshConnectionToolImpl()
{
_options = new OffMeshConnectionToolOptions();
}
public string GetName()
{
@ -19,5 +30,47 @@
return _sample;
}
public OffMeshConnectionToolOptions GetOptions()
{
return _options;
}
public void Add(RcVec3f start, RcVec3f end)
{
DemoInputGeomProvider geom = _sample.GetInputGeom();
if (null == geom)
return;
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP;
int flags = SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP;
geom.AddOffMeshConnection(start, end, _sample.GetSettings().agentRadius, 0 == _options.bidir, area, flags);
}
public void Remove(RcVec3f p)
{
DemoInputGeomProvider geom = _sample.GetInputGeom();
if (null == geom)
return;
// Delete
// Find nearest link end-point
float nearestDist = float.MaxValue;
DemoOffMeshConnection nearestConnection = null;
foreach (DemoOffMeshConnection offMeshCon in geom.GetOffMeshConnections())
{
float d = Math.Min(RcVec3f.DistSqr(p, offMeshCon.verts, 0), RcVec3f.DistSqr(p, offMeshCon.verts, 3));
if (d < nearestDist && Math.Sqrt(d) < _sample.GetSettings().agentRadius)
{
nearestDist = d;
nearestConnection = offMeshCon;
}
}
if (nearestConnection != null)
{
geom.GetOffMeshConnections().Remove(nearestConnection);
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class OffMeshConnectionToolOptions
{
public int bidir;
}
}