forked from bit/DotRecastNetSim
int[] CalcTileLoc(pos) -> void CalcTileLoc(pos, out, out)
This commit is contained in:
parent
5bcacd8e7c
commit
328fcdaca7
|
@ -22,6 +22,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.QueryResults;
|
using DotRecast.Detour.QueryResults;
|
||||||
|
|
||||||
|
@ -210,11 +211,10 @@ namespace DotRecast.Detour
|
||||||
* The world position for the query. [(x, y, z)]
|
* The world position for the query. [(x, y, z)]
|
||||||
* @return 2-element int array with (tx,ty) tile location
|
* @return 2-element int array with (tx,ty) tile location
|
||||||
*/
|
*/
|
||||||
public int[] CalcTileLoc(Vector3f pos)
|
public void CalcTileLoc(Vector3f pos, out int tx, out int ty)
|
||||||
{
|
{
|
||||||
int tx = (int)Math.Floor((pos.x - m_orig.x) / m_tileWidth);
|
tx = (int)Math.Floor((pos.x - m_orig.x) / m_tileWidth);
|
||||||
int ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight);
|
ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight);
|
||||||
return new int[] { tx, ty };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<Tuple<MeshTile, Poly>> GetTileAndPolyByRef(long refs)
|
public Result<Tuple<MeshTile, Poly>> GetTileAndPolyByRef(long refs)
|
||||||
|
|
|
@ -710,12 +710,9 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
Vector3f bmin = center.Subtract(halfExtents);
|
Vector3f bmin = center.Subtract(halfExtents);
|
||||||
Vector3f bmax = center.Add(halfExtents);
|
Vector3f bmax = center.Add(halfExtents);
|
||||||
int[] minxy = m_nav.CalcTileLoc(bmin);
|
m_nav.CalcTileLoc(bmin, out var minx, out var miny);
|
||||||
int minx = minxy[0];
|
m_nav.CalcTileLoc(bmax, out var maxx, out var maxy);
|
||||||
int miny = minxy[1];
|
|
||||||
int[] maxxy = m_nav.CalcTileLoc(bmax);
|
|
||||||
int maxx = maxxy[0];
|
|
||||||
int maxy = maxxy[1];
|
|
||||||
List<MeshTile> tiles = new List<MeshTile>();
|
List<MeshTile> tiles = new List<MeshTile>();
|
||||||
for (int y = miny; y <= maxy; ++y)
|
for (int y = miny; y <= maxy; ++y)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,8 +60,8 @@ public class UnityAStarPathfindingImporterTest
|
||||||
NavMesh mesh = LoadNavMesh("test_boundstree.zip");
|
NavMesh mesh = LoadNavMesh("test_boundstree.zip");
|
||||||
Vector3f position = Vector3f.Of(387.52988f, 19.997f, 368.86282f);
|
Vector3f position = Vector3f.Of(387.52988f, 19.997f, 368.86282f);
|
||||||
|
|
||||||
int[] tilePos = mesh.CalcTileLoc(position);
|
mesh.CalcTileLoc(position, out var tileX, out var tileY);
|
||||||
long tileRef = mesh.GetTileRefAt(tilePos[0], tilePos[1], 0);
|
long tileRef = mesh.GetTileRefAt(tileX, tileY, 0);
|
||||||
MeshTile tile = mesh.GetTileByRef(tileRef);
|
MeshTile tile = mesh.GetTileByRef(tileRef);
|
||||||
MeshData data = tile.data;
|
MeshData data = tile.data;
|
||||||
BVNode[] bvNodes = data.bvTree;
|
BVNode[] bvNodes = data.bvTree;
|
||||||
|
@ -137,4 +137,4 @@ public class UnityAStarPathfindingImporterTest
|
||||||
using var os = new BinaryWriter(fs);
|
using var os = new BinaryWriter(fs);
|
||||||
writer.Write(os, mesh, RcByteOrder.LITTLE_ENDIAN, true);
|
writer.Write(os, mesh, RcByteOrder.LITTLE_ENDIAN, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue