forked from mirror/DotRecast
012->xyz
This commit is contained in:
parent
6ead61661d
commit
25132fbdd5
|
@ -49,12 +49,12 @@ namespace DotRecast.Detour.Extras
|
||||||
vMax(ref bmax, data.verts, data.polys[i].verts[j] * 3);
|
vMax(ref bmax, data.verts, data.polys[i].verts[j] * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
it.bmin[0] = clamp((int)((bmin[0] - data.header.bmin[0]) * quantFactor), 0, 0x7fffffff);
|
it.bmin[0] = clamp((int)((bmin.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff);
|
||||||
it.bmin[1] = clamp((int)((bmin[1] - data.header.bmin[1]) * quantFactor), 0, 0x7fffffff);
|
it.bmin[1] = clamp((int)((bmin.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff);
|
||||||
it.bmin[2] = clamp((int)((bmin[2] - data.header.bmin[2]) * quantFactor), 0, 0x7fffffff);
|
it.bmin[2] = clamp((int)((bmin.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff);
|
||||||
it.bmax[0] = clamp((int)((bmax[0] - data.header.bmin[0]) * quantFactor), 0, 0x7fffffff);
|
it.bmax[0] = clamp((int)((bmax.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff);
|
||||||
it.bmax[1] = clamp((int)((bmax[1] - data.header.bmin[1]) * quantFactor), 0, 0x7fffffff);
|
it.bmax[1] = clamp((int)((bmax.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff);
|
||||||
it.bmax[2] = clamp((int)((bmax[2] - data.header.bmin[2]) * quantFactor), 0, 0x7fffffff);
|
it.bmax[2] = clamp((int)((bmax.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NavMeshBuilder.subdivide(items, data.header.polyCount, 0, data.header.polyCount, 0, nodes);
|
return NavMeshBuilder.subdivide(items, data.header.polyCount, 0, data.header.polyCount, 0, nodes);
|
||||||
|
|
|
@ -34,9 +34,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
seg.gsamples[i] = s;
|
seg.gsamples[i] = s;
|
||||||
Vector3f pt = vLerp(seg.p, seg.q, u);
|
Vector3f pt = vLerp(seg.p, seg.q, u);
|
||||||
Tuple<bool, float> height = heightFunc.Invoke(pt, seg.height);
|
Tuple<bool, float> height = heightFunc.Invoke(pt, seg.height);
|
||||||
s.p[0] = pt[0];
|
s.p.x = pt.x;
|
||||||
s.p[1] = height.Item2;
|
s.p.y = height.Item2;
|
||||||
s.p[2] = pt[2];
|
s.p.z = pt.z;
|
||||||
|
|
||||||
if (!height.Item1)
|
if (!height.Item1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,9 +9,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
return new Vector3f()
|
return new Vector3f()
|
||||||
{
|
{
|
||||||
x = lerp(start[0], end[0], Math.Min(2f * u, 1f)),
|
x = lerp(start.x, end.x, Math.Min(2f * u, 1f)),
|
||||||
y = lerp(start[1], end[1], Math.Max(0f, 2f * u - 1f)),
|
y = lerp(start.y, end.y, Math.Max(0f, 2f * u - 1f)),
|
||||||
z = lerp(start[2], end[2], Math.Min(2f * u, 1f))
|
z = lerp(start.z, end.z, Math.Min(2f * u, 1f))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,12 +58,12 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
int va = mesh.polys[p + j] * 3;
|
int va = mesh.polys[p + j] * 3;
|
||||||
int vb = mesh.polys[p + nj] * 3;
|
int vb = mesh.polys[p + nj] * 3;
|
||||||
Edge e = new Edge();
|
Edge e = new Edge();
|
||||||
e.sp[0] = orig[0] + mesh.verts[vb] * cs;
|
e.sp.x = orig.x + mesh.verts[vb] * cs;
|
||||||
e.sp[1] = orig[1] + mesh.verts[vb + 1] * ch;
|
e.sp.y = orig.y + mesh.verts[vb + 1] * ch;
|
||||||
e.sp[2] = orig[2] + mesh.verts[vb + 2] * cs;
|
e.sp.z = orig.z + mesh.verts[vb + 2] * cs;
|
||||||
e.sq[0] = orig[0] + mesh.verts[va] * cs;
|
e.sq.x = orig.x + mesh.verts[va] * cs;
|
||||||
e.sq[1] = orig[1] + mesh.verts[va + 1] * ch;
|
e.sq.y = orig.y + mesh.verts[va + 1] * ch;
|
||||||
e.sq[2] = orig[2] + mesh.verts[va + 2] * cs;
|
e.sq.z = orig.z + mesh.verts[va + 2] * cs;
|
||||||
edges.Add(e);
|
edges.Add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
this.trajectory = trajectory;
|
this.trajectory = trajectory;
|
||||||
ax = vSub(edge.sq, edge.sp);
|
ax = vSub(edge.sq, edge.sp);
|
||||||
vNormalize(ref ax);
|
vNormalize(ref ax);
|
||||||
vSet(ref az, ax[2], 0, -ax[0]);
|
vSet(ref az, ax.z, 0, -ax.x);
|
||||||
vNormalize(ref az);
|
vNormalize(ref az);
|
||||||
vSet(ref ay, 0, 1, 0);
|
vSet(ref ay, 0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,9 +80,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
|
|
||||||
private void vadd(ref Vector3f dest, Vector3f v1, Vector3f v2)
|
private void vadd(ref Vector3f dest, Vector3f v1, Vector3f v2)
|
||||||
{
|
{
|
||||||
dest[0] = v1[0] + v2[0];
|
dest.x = v1.x + v2.x;
|
||||||
dest[1] = v1[1] + v2[1];
|
dest.y = v1.y + v2.y;
|
||||||
dest[2] = v1[2] + v2[2];
|
dest.z = v1.z + v2.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
|
|
||||||
private void trans2d(ref Vector3f dst, Vector3f ax, Vector3f ay, Vector2f pt)
|
private void trans2d(ref Vector3f dst, Vector3f ax, Vector3f ay, Vector2f pt)
|
||||||
{
|
{
|
||||||
dst[0] = ax[0] * pt.x + ay[0] * pt.y;
|
dst.x = ax.x * pt.x + ay.x * pt.y;
|
||||||
dst[1] = ax[1] * pt.x + ay[1] * pt.y;
|
dst.y = ax.y * pt.x + ay.y * pt.y;
|
||||||
dst[2] = ax[2] * pt.x + ay[2] * pt.y;
|
dst.z = ax.z * pt.x + ay.z * pt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,14 +73,14 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
float u = ((float)j) / (link.nspine - 1);
|
float u = ((float)j) / (link.nspine - 1);
|
||||||
Vector3f p = es.trajectory.apply(sp, ep, u);
|
Vector3f p = es.trajectory.apply(sp, ep, u);
|
||||||
link.spine0[j * 3] = p[0];
|
link.spine0[j * 3] = p.x;
|
||||||
link.spine0[j * 3 + 1] = p[1];
|
link.spine0[j * 3 + 1] = p.y;
|
||||||
link.spine0[j * 3 + 2] = p[2];
|
link.spine0[j * 3 + 2] = p.z;
|
||||||
|
|
||||||
p = es.trajectory.apply(sq, eq, u);
|
p = es.trajectory.apply(sq, eq, u);
|
||||||
link.spine1[j * 3] = p[0];
|
link.spine1[j * 3] = p.x;
|
||||||
link.spine1[j * 3 + 1] = p[1];
|
link.spine1[j * 3 + 1] = p.y;
|
||||||
link.spine1[j * 3 + 2] = p[2];
|
link.spine1[j * 3 + 2] = p.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
GroundSample p = es.end[j].gsamples[i];
|
GroundSample p = es.end[j].gsamples[i];
|
||||||
sampleGrid[i][j] = region;
|
sampleGrid[i][j] = region;
|
||||||
float h = p.p[1];
|
float h = p.p.y;
|
||||||
if (i < sampleGrid.Length - 1)
|
if (i < sampleGrid.Length - 1)
|
||||||
{
|
{
|
||||||
addNeighbour(es, queue, agentClimb, h, i + 1, j);
|
addNeighbour(es, queue, agentClimb, h, i + 1, j);
|
||||||
|
@ -121,7 +121,7 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
private void addNeighbour(EdgeSampler es, Queue<int[]> queue, float agentClimb, float h, int i, int j)
|
private void addNeighbour(EdgeSampler es, Queue<int[]> queue, float agentClimb, float h, int i, int j)
|
||||||
{
|
{
|
||||||
GroundSample q = es.end[j].gsamples[i];
|
GroundSample q = es.end[j].gsamples[i];
|
||||||
if (q.validTrajectory && Math.Abs(q.p[1] - h) < agentClimb)
|
if (q.validTrajectory && Math.Abs(q.p.y - h) < agentClimb)
|
||||||
{
|
{
|
||||||
queue.Enqueue(new int[] { i, j });
|
queue.Enqueue(new int[] { i, j });
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
return new Vector3f
|
return new Vector3f
|
||||||
{
|
{
|
||||||
x = lerp(start[0], end[0], u),
|
x = lerp(start.x, end.x, u),
|
||||||
y = interpolateHeight(start[1], end[1], u),
|
y = interpolateHeight(start.y, end.y, u),
|
||||||
z = lerp(start[2], end[2], u)
|
z = lerp(start.z, end.z, u)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,9 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
private Tuple<bool, float> getNavMeshHeight(NavMeshQuery navMeshQuery, Vector3f pt, float cs, float heightRange)
|
private Tuple<bool, float> getNavMeshHeight(NavMeshQuery navMeshQuery, Vector3f pt, float cs, float heightRange)
|
||||||
{
|
{
|
||||||
Vector3f halfExtents = new Vector3f { x = cs, y = heightRange, z = cs };
|
Vector3f halfExtents = new Vector3f { x = cs, y = heightRange, z = cs };
|
||||||
float maxHeight = pt[1] + heightRange;
|
float maxHeight = pt.y + heightRange;
|
||||||
AtomicBoolean found = new AtomicBoolean();
|
AtomicBoolean found = new AtomicBoolean();
|
||||||
AtomicFloat minHeight = new AtomicFloat(pt[1]);
|
AtomicFloat minHeight = new AtomicFloat(pt.y);
|
||||||
navMeshQuery.queryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
|
navMeshQuery.queryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
|
||||||
{
|
{
|
||||||
Result<float> h = navMeshQuery.getPolyHeight(refs, pt);
|
Result<float> h = navMeshQuery.getPolyHeight(refs, pt);
|
||||||
|
@ -94,7 +94,7 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
return Tuple.Create(true, minHeight.Get());
|
return Tuple.Create(true, minHeight.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Tuple.Create(false, pt[1]);
|
return Tuple.Create(false, pt.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,13 +35,13 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
private bool sampleTrajectory(JumpLinkBuilderConfig acfg, Heightfield solid, Vector3f pa, Vector3f pb, Trajectory tra)
|
private bool sampleTrajectory(JumpLinkBuilderConfig acfg, Heightfield solid, Vector3f pa, Vector3f pb, Trajectory tra)
|
||||||
{
|
{
|
||||||
float cs = Math.Min(acfg.cellSize, acfg.cellHeight);
|
float cs = Math.Min(acfg.cellSize, acfg.cellHeight);
|
||||||
float d = vDist2D(pa, pb) + Math.Abs(pa[1] - pb[1]);
|
float d = vDist2D(pa, pb) + Math.Abs(pa.y - pb.y);
|
||||||
int nsamples = Math.Max(2, (int)Math.Ceiling(d / cs));
|
int nsamples = Math.Max(2, (int)Math.Ceiling(d / cs));
|
||||||
for (int i = 0; i < nsamples; ++i)
|
for (int i = 0; i < nsamples; ++i)
|
||||||
{
|
{
|
||||||
float u = (float)i / (float)(nsamples - 1);
|
float u = (float)i / (float)(nsamples - 1);
|
||||||
Vector3f p = tra.apply(pa, pb, u);
|
Vector3f p = tra.apply(pa, pb, u);
|
||||||
if (checkHeightfieldCollision(solid, p[0], p[1] + acfg.groundTolerance, p[1] + acfg.agentHeight, p[2]))
|
if (checkHeightfieldCollision(solid, p.x, p.y + acfg.groundTolerance, p.y + acfg.agentHeight, p.z))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
float cs = solid.cs;
|
float cs = solid.cs;
|
||||||
float ch = solid.ch;
|
float ch = solid.ch;
|
||||||
Vector3f orig = solid.bmin;
|
Vector3f orig = solid.bmin;
|
||||||
int ix = (int)Math.Floor((x - orig[0]) / cs);
|
int ix = (int)Math.Floor((x - orig.x) / cs);
|
||||||
int iz = (int)Math.Floor((z - orig[2]) / cs);
|
int iz = (int)Math.Floor((z - orig.z) / cs);
|
||||||
|
|
||||||
if (ix < 0 || iz < 0 || ix > w || iz > h)
|
if (ix < 0 || iz < 0 || ix > w || iz > h)
|
||||||
{
|
{
|
||||||
|
@ -73,8 +73,8 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
|
|
||||||
while (s != null)
|
while (s != null)
|
||||||
{
|
{
|
||||||
float symin = orig[1] + s.smin * ch;
|
float symin = orig.y + s.smin * ch;
|
||||||
float symax = orig[1] + s.smax * ch;
|
float symax = orig.y + s.smax * ch;
|
||||||
if (overlapRange(ymin, ymax, symin, symax))
|
if (overlapRange(ymin, ymax, symin, symax))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -126,15 +126,15 @@ namespace DotRecast.Detour.Extras.Unity.Astar
|
||||||
header.detailMeshCount = nodeCount;
|
header.detailMeshCount = nodeCount;
|
||||||
header.detailTriCount = nodeCount;
|
header.detailTriCount = nodeCount;
|
||||||
header.maxLinkCount = nodeCount * 3 * 2; // XXX: Needed by Recast, not needed by recast4j
|
header.maxLinkCount = nodeCount * 3 * 2; // XXX: Needed by Recast, not needed by recast4j
|
||||||
header.bmin[0] = meta.forcedBoundsCenter.x - 0.5f * meta.forcedBoundsSize.x
|
header.bmin.x = meta.forcedBoundsCenter.x - 0.5f * meta.forcedBoundsSize.x
|
||||||
+ meta.cellSize * meta.tileSizeX * x;
|
+ meta.cellSize * meta.tileSizeX * x;
|
||||||
header.bmin[1] = ymin;
|
header.bmin.y = ymin;
|
||||||
header.bmin[2] = meta.forcedBoundsCenter.z - 0.5f * meta.forcedBoundsSize.z
|
header.bmin.z = meta.forcedBoundsCenter.z - 0.5f * meta.forcedBoundsSize.z
|
||||||
+ meta.cellSize * meta.tileSizeZ * z;
|
+ meta.cellSize * meta.tileSizeZ * z;
|
||||||
header.bmax[0] = meta.forcedBoundsCenter.x - 0.5f * meta.forcedBoundsSize.x
|
header.bmax.x = meta.forcedBoundsCenter.x - 0.5f * meta.forcedBoundsSize.x
|
||||||
+ meta.cellSize * meta.tileSizeX * (x + 1);
|
+ meta.cellSize * meta.tileSizeX * (x + 1);
|
||||||
header.bmax[1] = ymax;
|
header.bmax.y = ymax;
|
||||||
header.bmax[2] = meta.forcedBoundsCenter.z - 0.5f * meta.forcedBoundsSize.z
|
header.bmax.z = meta.forcedBoundsCenter.z - 0.5f * meta.forcedBoundsSize.z
|
||||||
+ meta.cellSize * meta.tileSizeZ * (z + 1);
|
+ meta.cellSize * meta.tileSizeZ * (z + 1);
|
||||||
header.bvQuantFactor = 1.0f / meta.cellSize;
|
header.bvQuantFactor = 1.0f / meta.cellSize;
|
||||||
header.offMeshBase = nodeCount;
|
header.offMeshBase = nodeCount;
|
||||||
|
|
|
@ -63,21 +63,21 @@ namespace DotRecast.Detour.Extras.Unity.Astar
|
||||||
// In case of external link to other tiles we must find the direction
|
// In case of external link to other tiles we must find the direction
|
||||||
private void buildExternalLink(MeshData tile, Poly node, MeshData neighbourTile)
|
private void buildExternalLink(MeshData tile, Poly node, MeshData neighbourTile)
|
||||||
{
|
{
|
||||||
if (neighbourTile.header.bmin[0] > tile.header.bmin[0])
|
if (neighbourTile.header.bmin.x > tile.header.bmin.x)
|
||||||
{
|
{
|
||||||
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin[0], 0)] = NavMesh.DT_EXT_LINK;
|
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin.x, 0)] = NavMesh.DT_EXT_LINK;
|
||||||
}
|
}
|
||||||
else if (neighbourTile.header.bmin[0] < tile.header.bmin[0])
|
else if (neighbourTile.header.bmin.x < tile.header.bmin.x)
|
||||||
{
|
{
|
||||||
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin[0], 0)] = NavMesh.DT_EXT_LINK | 4;
|
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin.x, 0)] = NavMesh.DT_EXT_LINK | 4;
|
||||||
}
|
}
|
||||||
else if (neighbourTile.header.bmin[2] > tile.header.bmin[2])
|
else if (neighbourTile.header.bmin.z > tile.header.bmin.z)
|
||||||
{
|
{
|
||||||
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin[2], 2)] = NavMesh.DT_EXT_LINK | 2;
|
node.neis[PolyUtils.findEdge(node, tile, neighbourTile.header.bmin.z, 2)] = NavMesh.DT_EXT_LINK | 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin[2], 2)] = NavMesh.DT_EXT_LINK | 6;
|
node.neis[PolyUtils.findEdge(node, tile, tile.header.bmin.z, 2)] = NavMesh.DT_EXT_LINK | 6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ namespace DotRecast.Detour.Extras.Unity.Astar
|
||||||
option.maxPolys = 32768;
|
option.maxPolys = 32768;
|
||||||
option.tileWidth = graphMeta.tileSizeX * graphMeta.cellSize;
|
option.tileWidth = graphMeta.tileSizeX * graphMeta.cellSize;
|
||||||
option.tileHeight = graphMeta.tileSizeZ * graphMeta.cellSize;
|
option.tileHeight = graphMeta.tileSizeZ * graphMeta.cellSize;
|
||||||
option.orig[0] = -0.5f * graphMeta.forcedBoundsSize.x + graphMeta.forcedBoundsCenter.x;
|
option.orig.x = -0.5f * graphMeta.forcedBoundsSize.x + graphMeta.forcedBoundsCenter.x;
|
||||||
option.orig[1] = -0.5f * graphMeta.forcedBoundsSize.y + graphMeta.forcedBoundsCenter.y;
|
option.orig.y = -0.5f * graphMeta.forcedBoundsSize.y + graphMeta.forcedBoundsCenter.y;
|
||||||
option.orig[2] = -0.5f * graphMeta.forcedBoundsSize.z + graphMeta.forcedBoundsCenter.z;
|
option.orig.z = -0.5f * graphMeta.forcedBoundsSize.z + graphMeta.forcedBoundsCenter.z;
|
||||||
NavMesh mesh = new NavMesh(option, 3);
|
NavMesh mesh = new NavMesh(option, 3);
|
||||||
foreach (MeshData t in graphMeshData.tiles)
|
foreach (MeshData t in graphMeshData.tiles)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue