forked from mirror/DotRecast
move class
This commit is contained in:
parent
7d5f37f415
commit
5c2a654de5
|
@ -0,0 +1,11 @@
|
|||
namespace DotRecast.Core
|
||||
{
|
||||
public class IntersectResult
|
||||
{
|
||||
public bool intersects;
|
||||
public float tmin;
|
||||
public float tmax = 1f;
|
||||
public int segMin = -1;
|
||||
public int segMax = -1;
|
||||
}
|
||||
}
|
|
@ -810,14 +810,7 @@ namespace DotRecast.Core
|
|||
return r;
|
||||
}
|
||||
|
||||
public class IntersectResult
|
||||
{
|
||||
public bool intersects;
|
||||
public float tmin;
|
||||
public float tmax = 1f;
|
||||
public int segMin = -1;
|
||||
public int segMax = -1;
|
||||
}
|
||||
|
||||
|
||||
public static IntersectResult IntersectSegmentPoly2D(Vector3f p0, Vector3f p1, float[] verts, int nverts)
|
||||
{
|
||||
|
|
|
@ -901,7 +901,7 @@ namespace DotRecast.Detour.Crowd
|
|||
|
||||
_telemetry.Stop("buildNeighbours");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<CrowdNeighbour> GetNeighbours(Vector3f pos, float height, float range, CrowdAgent skip, ProximityGrid grid)
|
||||
{
|
||||
|
@ -1373,23 +1373,5 @@ namespace DotRecast.Detour.Crowd
|
|||
{
|
||||
return Clamp((t - t0) / (t1 - t0), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
/// Provides neighbor data for agents managed by the crowd.
|
||||
/// @ingroup crowd
|
||||
/// @see dtCrowdAgent::neis, dtCrowd
|
||||
public class CrowdNeighbour
|
||||
{
|
||||
public readonly CrowdAgent agent;
|
||||
|
||||
/// < The index of the neighbor in the crowd.
|
||||
public readonly float dist;
|
||||
|
||||
/// < The distance between the current agent and the neighbor.
|
||||
public CrowdNeighbour(CrowdAgent agent, float dist)
|
||||
{
|
||||
this.agent = agent;
|
||||
this.dist = dist;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -73,7 +73,7 @@ namespace DotRecast.Detour.Crowd
|
|||
public float topologyOptTime;
|
||||
|
||||
/// The known neighbors of the agent.
|
||||
public List<Crowd.CrowdNeighbour> neis = new List<Crowd.CrowdNeighbour>();
|
||||
public List<CrowdNeighbour> neis = new List<CrowdNeighbour>();
|
||||
|
||||
/// The desired speed.
|
||||
public float desiredSpeed;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
/// Provides neighbor data for agents managed by the crowd.
|
||||
/// @ingroup crowd
|
||||
/// @see dtCrowdAgent::neis, dtCrowd
|
||||
public class CrowdNeighbour
|
||||
{
|
||||
public readonly CrowdAgent agent;
|
||||
|
||||
/// < The index of the neighbor in the crowd.
|
||||
public readonly float dist;
|
||||
|
||||
/// < The distance between the current agent and the neighbor.
|
||||
public CrowdNeighbour(CrowdAgent agent, float dist)
|
||||
{
|
||||
this.agent = agent;
|
||||
this.dist = dist;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -33,38 +33,6 @@ namespace DotRecast.Detour.Crowd
|
|||
/// < Max numver of adaptive divs.
|
||||
public const int DT_MAX_PATTERN_RINGS = 4;
|
||||
|
||||
/// < Max number of adaptive rings.
|
||||
public class ObstacleCircle
|
||||
{
|
||||
/** Position of the obstacle */
|
||||
public Vector3f p = new Vector3f();
|
||||
|
||||
/** Velocity of the obstacle */
|
||||
public Vector3f vel = new Vector3f();
|
||||
|
||||
/** Velocity of the obstacle */
|
||||
public Vector3f dvel = new Vector3f();
|
||||
|
||||
/** Radius of the obstacle */
|
||||
public float rad;
|
||||
|
||||
/** Use for side selection during sampling. */
|
||||
public Vector3f dp = new Vector3f();
|
||||
|
||||
/** Use for side selection during sampling. */
|
||||
public Vector3f np = new Vector3f();
|
||||
}
|
||||
|
||||
public class ObstacleSegment
|
||||
{
|
||||
/** End points of the obstacle segment */
|
||||
public Vector3f p = new Vector3f();
|
||||
|
||||
/** End points of the obstacle segment */
|
||||
public Vector3f q = new Vector3f();
|
||||
|
||||
public bool touch;
|
||||
}
|
||||
|
||||
private ObstacleAvoidanceParams m_params;
|
||||
private float m_invHorizTime;
|
||||
|
@ -214,16 +182,16 @@ namespace DotRecast.Detour.Crowd
|
|||
float d = VPerp2D(u, v);
|
||||
if (Math.Abs(d) < 1e-6f)
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
|
||||
d = 1.0f / d;
|
||||
float t = VPerp2D(v, w) * d;
|
||||
if (t < 0 || t > 1)
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
|
||||
float s = VPerp2D(u, w) * d;
|
||||
if (s < 0 || s > 1)
|
||||
return new IsectRaySegResult(false, 0f);
|
||||
|
||||
|
||||
return new IsectRaySegResult(true, t);
|
||||
}
|
||||
|
||||
|
@ -316,7 +284,7 @@ namespace DotRecast.Detour.Crowd
|
|||
var ires = IsectRaySeg(pos, vcand, seg.p, seg.q);
|
||||
if (!ires.result)
|
||||
continue;
|
||||
|
||||
|
||||
htmin = ires.htmin;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
/// < Max number of adaptive rings.
|
||||
public class ObstacleCircle
|
||||
{
|
||||
/** Position of the obstacle */
|
||||
public Vector3f p = new Vector3f();
|
||||
|
||||
/** Velocity of the obstacle */
|
||||
public Vector3f vel = new Vector3f();
|
||||
|
||||
/** Velocity of the obstacle */
|
||||
public Vector3f dvel = new Vector3f();
|
||||
|
||||
/** Radius of the obstacle */
|
||||
public float rad;
|
||||
|
||||
/** Use for side selection during sampling. */
|
||||
public Vector3f dp = new Vector3f();
|
||||
|
||||
/** Use for side selection during sampling. */
|
||||
public Vector3f np = new Vector3f();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
public class ObstacleSegment
|
||||
{
|
||||
/** End points of the obstacle segment */
|
||||
public Vector3f p = new Vector3f();
|
||||
|
||||
/** End points of the obstacle segment */
|
||||
public Vector3f q = new Vector3f();
|
||||
|
||||
public bool touch;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ using DotRecast.Core;
|
|||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
using static DotRecast.Core.RecastMath;
|
||||
|
||||
public interface IPolygonByCircleConstraint
|
||||
{
|
||||
|
@ -36,77 +35,5 @@ namespace DotRecast.Detour
|
|||
{
|
||||
return new StrictPolygonByCircleConstraint();
|
||||
}
|
||||
|
||||
public class NoOpPolygonByCircleConstraint : IPolygonByCircleConstraint
|
||||
{
|
||||
public float[] Aply(float[] polyVerts, Vector3f circleCenter, float radius)
|
||||
{
|
||||
return polyVerts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the intersection between a polygon and a circle. A dodecagon is used as an approximation of the circle.
|
||||
*/
|
||||
public class StrictPolygonByCircleConstraint : IPolygonByCircleConstraint
|
||||
{
|
||||
private const int CIRCLE_SEGMENTS = 12;
|
||||
private static float[] unitCircle;
|
||||
|
||||
public float[] Aply(float[] verts, Vector3f center, float radius)
|
||||
{
|
||||
float radiusSqr = radius * radius;
|
||||
int outsideVertex = -1;
|
||||
for (int pv = 0; pv < verts.Length; pv += 3)
|
||||
{
|
||||
if (VDist2DSqr(center, verts, pv) > radiusSqr)
|
||||
{
|
||||
outsideVertex = pv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (outsideVertex == -1)
|
||||
{
|
||||
// polygon inside circle
|
||||
return verts;
|
||||
}
|
||||
|
||||
float[] qCircle = Circle(center, radius);
|
||||
float[] intersection = ConvexConvexIntersection.Intersect(verts, qCircle);
|
||||
if (intersection == null && PointInPolygon(center, verts, verts.Length / 3))
|
||||
{
|
||||
// circle inside polygon
|
||||
return qCircle;
|
||||
}
|
||||
|
||||
return intersection;
|
||||
}
|
||||
|
||||
private float[] Circle(Vector3f center, float radius)
|
||||
{
|
||||
if (unitCircle == null)
|
||||
{
|
||||
unitCircle = new float[CIRCLE_SEGMENTS * 3];
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS; i++)
|
||||
{
|
||||
double a = i * Math.PI * 2 / CIRCLE_SEGMENTS;
|
||||
unitCircle[3 * i] = (float)Math.Cos(a);
|
||||
unitCircle[3 * i + 1] = 0;
|
||||
unitCircle[3 * i + 2] = (float)-Math.Sin(a);
|
||||
}
|
||||
}
|
||||
|
||||
float[] circle = new float[12 * 3];
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS * 3; i += 3)
|
||||
{
|
||||
circle[i] = unitCircle[i] * radius + center.x;
|
||||
circle[i + 1] = center.y;
|
||||
circle[i + 2] = unitCircle[i + 2] * radius + center.z;
|
||||
}
|
||||
|
||||
return circle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2993,18 +2993,6 @@ namespace DotRecast.Detour
|
|||
return Results.Success(new FindLocalNeighbourhoodResult(resultRef, resultParent));
|
||||
}
|
||||
|
||||
public class SegInterval
|
||||
{
|
||||
public long refs;
|
||||
public int tmin, tmax;
|
||||
|
||||
public SegInterval(long refs, int tmin, int tmax)
|
||||
{
|
||||
this.refs = refs;
|
||||
this.tmin = tmin;
|
||||
this.tmax = tmax;
|
||||
}
|
||||
}
|
||||
|
||||
protected void InsertInterval(List<SegInterval> ints, int tmin, int tmax, long refs)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
public class NoOpPolygonByCircleConstraint : IPolygonByCircleConstraint
|
||||
{
|
||||
public float[] Aply(float[] polyVerts, Vector3f circleCenter, float radius)
|
||||
{
|
||||
return polyVerts;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
namespace DotRecast.Detour
|
||||
{
|
||||
public class SegInterval
|
||||
{
|
||||
public long refs;
|
||||
public int tmin;
|
||||
public int tmax;
|
||||
|
||||
public SegInterval(long refs, int tmin, int tmax)
|
||||
{
|
||||
this.refs = refs;
|
||||
this.tmin = tmin;
|
||||
this.tmax = tmax;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
using static DotRecast.Core.RecastMath;
|
||||
|
||||
/**
|
||||
* Calculate the intersection between a polygon and a circle. A dodecagon is used as an approximation of the circle.
|
||||
*/
|
||||
public class StrictPolygonByCircleConstraint : IPolygonByCircleConstraint
|
||||
{
|
||||
private const int CIRCLE_SEGMENTS = 12;
|
||||
private static float[] unitCircle;
|
||||
|
||||
public float[] Aply(float[] verts, Vector3f center, float radius)
|
||||
{
|
||||
float radiusSqr = radius * radius;
|
||||
int outsideVertex = -1;
|
||||
for (int pv = 0; pv < verts.Length; pv += 3)
|
||||
{
|
||||
if (VDist2DSqr(center, verts, pv) > radiusSqr)
|
||||
{
|
||||
outsideVertex = pv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (outsideVertex == -1)
|
||||
{
|
||||
// polygon inside circle
|
||||
return verts;
|
||||
}
|
||||
|
||||
float[] qCircle = Circle(center, radius);
|
||||
float[] intersection = ConvexConvexIntersection.Intersect(verts, qCircle);
|
||||
if (intersection == null && PointInPolygon(center, verts, verts.Length / 3))
|
||||
{
|
||||
// circle inside polygon
|
||||
return qCircle;
|
||||
}
|
||||
|
||||
return intersection;
|
||||
}
|
||||
|
||||
private float[] Circle(Vector3f center, float radius)
|
||||
{
|
||||
if (unitCircle == null)
|
||||
{
|
||||
unitCircle = new float[CIRCLE_SEGMENTS * 3];
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS; i++)
|
||||
{
|
||||
double a = i * Math.PI * 2 / CIRCLE_SEGMENTS;
|
||||
unitCircle[3 * i] = (float)Math.Cos(a);
|
||||
unitCircle[3 * i + 1] = 0;
|
||||
unitCircle[3 * i + 2] = (float)-Math.Sin(a);
|
||||
}
|
||||
}
|
||||
|
||||
float[] circle = new float[12 * 3];
|
||||
for (int i = 0; i < CIRCLE_SEGMENTS * 3; i += 3)
|
||||
{
|
||||
circle[i] = unitCircle[i] * radius + center.x;
|
||||
circle[i + 1] = center.y;
|
||||
circle[i + 2] = unitCircle[i + 2] * radius + center.z;
|
||||
}
|
||||
|
||||
return circle;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Recast
|
||||
{
|
||||
/// Represents a heightfield layer within a layer set.
|
||||
/// @see rcHeightfieldLayerSet
|
||||
public class HeightfieldLayer
|
||||
{
|
||||
public Vector3f bmin = new Vector3f();
|
||||
|
||||
/// < The minimum bounds in world space. [(x, y, z)]
|
||||
public Vector3f bmax = new Vector3f();
|
||||
|
||||
/// < The maximum bounds in world space. [(x, y, z)]
|
||||
public float cs;
|
||||
|
||||
/// < The size of each cell. (On the xz-plane.)
|
||||
public float ch;
|
||||
|
||||
/// < The height of each cell. (The minimum increment along the y-axis.)
|
||||
public int width;
|
||||
|
||||
/// < The width of the heightfield. (Along the x-axis in cell units.)
|
||||
public int height;
|
||||
|
||||
/// < The height of the heightfield. (Along the z-axis in cell units.)
|
||||
public int minx;
|
||||
|
||||
/// < The minimum x-bounds of usable data.
|
||||
public int maxx;
|
||||
|
||||
/// < The maximum x-bounds of usable data.
|
||||
public int miny;
|
||||
|
||||
/// < The minimum y-bounds of usable data. (Along the z-axis.)
|
||||
public int maxy;
|
||||
|
||||
/// < The maximum y-bounds of usable data. (Along the z-axis.)
|
||||
public int hmin;
|
||||
|
||||
/// < The minimum height bounds of usable data. (Along the y-axis.)
|
||||
public int hmax;
|
||||
|
||||
/// < The maximum height bounds of usable data. (Along the y-axis.)
|
||||
public int[] heights;
|
||||
|
||||
/// < The heightfield. [Size: width * height]
|
||||
public int[] areas;
|
||||
|
||||
/// < Area ids. [Size: Same as #heights]
|
||||
public int[] cons; /// < Packed neighbor connection information. [Size: Same as #heights]
|
||||
}
|
||||
}
|
|
@ -27,55 +27,6 @@ namespace DotRecast.Recast
|
|||
/// @see rcAllocHeightfieldLayerSet, rcFreeHeightfieldLayerSet
|
||||
public class HeightfieldLayerSet
|
||||
{
|
||||
/// Represents a heightfield layer within a layer set.
|
||||
/// @see rcHeightfieldLayerSet
|
||||
public class HeightfieldLayer
|
||||
{
|
||||
public Vector3f bmin = new Vector3f();
|
||||
|
||||
/// < The minimum bounds in world space. [(x, y, z)]
|
||||
public Vector3f bmax = new Vector3f();
|
||||
|
||||
/// < The maximum bounds in world space. [(x, y, z)]
|
||||
public float cs;
|
||||
|
||||
/// < The size of each cell. (On the xz-plane.)
|
||||
public float ch;
|
||||
|
||||
/// < The height of each cell. (The minimum increment along the y-axis.)
|
||||
public int width;
|
||||
|
||||
/// < The width of the heightfield. (Along the x-axis in cell units.)
|
||||
public int height;
|
||||
|
||||
/// < The height of the heightfield. (Along the z-axis in cell units.)
|
||||
public int minx;
|
||||
|
||||
/// < The minimum x-bounds of usable data.
|
||||
public int maxx;
|
||||
|
||||
/// < The maximum x-bounds of usable data.
|
||||
public int miny;
|
||||
|
||||
/// < The minimum y-bounds of usable data. (Along the z-axis.)
|
||||
public int maxy;
|
||||
|
||||
/// < The maximum y-bounds of usable data. (Along the z-axis.)
|
||||
public int hmin;
|
||||
|
||||
/// < The minimum height bounds of usable data. (Along the y-axis.)
|
||||
public int hmax;
|
||||
|
||||
/// < The maximum height bounds of usable data. (Along the y-axis.)
|
||||
public int[] heights;
|
||||
|
||||
/// < The heightfield. [Size: width * height]
|
||||
public int[] areas;
|
||||
|
||||
/// < Area ids. [Size: Same as #heights]
|
||||
public int[] cons; /// < Packed neighbor connection information. [Size: Same as #heights]
|
||||
}
|
||||
|
||||
public HeightfieldLayer[] layers; /// < The layers in the set. [Size: #nlayers]
|
||||
}
|
||||
}
|
|
@ -25,12 +25,6 @@ namespace DotRecast.Recast
|
|||
{
|
||||
public static class ObjImporter
|
||||
{
|
||||
public class ObjImporterContext
|
||||
{
|
||||
public List<float> vertexPositions = new List<float>();
|
||||
public List<int> meshFaces = new List<int>();
|
||||
}
|
||||
|
||||
public static IInputGeomProvider Load(byte[] chunck)
|
||||
{
|
||||
var context = LoadContext(chunck);
|
||||
|
@ -136,4 +130,4 @@ namespace DotRecast.Recast
|
|||
return posi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Recast
|
||||
{
|
||||
public class ObjImporterContext
|
||||
{
|
||||
public List<float> vertexPositions = new List<float>();
|
||||
public List<int> meshFaces = new List<int>();
|
||||
}
|
||||
}
|
|
@ -418,10 +418,10 @@ namespace DotRecast.Recast
|
|||
bmax.z -= borderSize * chf.cs;
|
||||
|
||||
HeightfieldLayerSet lset = new HeightfieldLayerSet();
|
||||
lset.layers = new HeightfieldLayerSet.HeightfieldLayer[layerId];
|
||||
lset.layers = new HeightfieldLayer[layerId];
|
||||
for (int i = 0; i < lset.layers.Length; i++)
|
||||
{
|
||||
lset.layers[i] = new HeightfieldLayerSet.HeightfieldLayer();
|
||||
lset.layers[i] = new HeightfieldLayer();
|
||||
}
|
||||
|
||||
// Store layers.
|
||||
|
@ -429,7 +429,7 @@ namespace DotRecast.Recast
|
|||
{
|
||||
int curId = i;
|
||||
|
||||
HeightfieldLayerSet.HeightfieldLayer layer = lset.layers[i];
|
||||
HeightfieldLayer layer = lset.layers[i];
|
||||
|
||||
int gridSize = lw * lh;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace DotRecast.Detour.Test;
|
|||
[Parallelizable]
|
||||
public class PolygonByCircleConstraintTest
|
||||
{
|
||||
private readonly IPolygonByCircleConstraint constraint = new IPolygonByCircleConstraint.StrictPolygonByCircleConstraint();
|
||||
private readonly IPolygonByCircleConstraint constraint = new StrictPolygonByCircleConstraint();
|
||||
|
||||
[Test]
|
||||
public void ShouldHandlePolygonFullyInsideCircle()
|
||||
|
|
|
@ -87,7 +87,7 @@ public class TestTileLayerBuilder : AbstractTileLayersBuilder
|
|||
TileCacheBuilder builder = new TileCacheBuilder();
|
||||
for (int i = 0; i < lset.layers.Length; ++i)
|
||||
{
|
||||
HeightfieldLayerSet.HeightfieldLayer layer = lset.layers[i];
|
||||
HeightfieldLayer layer = lset.layers[i];
|
||||
|
||||
// Store header
|
||||
TileCacheLayerHeader header = new TileCacheLayerHeader();
|
||||
|
|
Loading…
Reference in New Issue