int[] CalcTileLoc(pos) -> void CalcTileLoc(pos, out, out)

This commit is contained in:
ikpil 2023-05-31 22:13:47 +09:00
parent 5bcacd8e7c
commit 328fcdaca7
3 changed files with 10 additions and 13 deletions

View File

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using DotRecast.Core;
using DotRecast.Detour.QueryResults;
@ -210,11 +211,10 @@ namespace DotRecast.Detour
* The world position for the query. [(x, y, z)]
* @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);
int ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight);
return new int[] { tx, ty };
tx = (int)Math.Floor((pos.x - m_orig.x) / m_tileWidth);
ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight);
}
public Result<Tuple<MeshTile, Poly>> GetTileAndPolyByRef(long refs)

View File

@ -710,12 +710,9 @@ namespace DotRecast.Detour
Vector3f bmin = center.Subtract(halfExtents);
Vector3f bmax = center.Add(halfExtents);
int[] minxy = m_nav.CalcTileLoc(bmin);
int minx = minxy[0];
int miny = minxy[1];
int[] maxxy = m_nav.CalcTileLoc(bmax);
int maxx = maxxy[0];
int maxy = maxxy[1];
m_nav.CalcTileLoc(bmin, out var minx, out var miny);
m_nav.CalcTileLoc(bmax, out var maxx, out var maxy);
List<MeshTile> tiles = new List<MeshTile>();
for (int y = miny; y <= maxy; ++y)
{

View File

@ -60,8 +60,8 @@ public class UnityAStarPathfindingImporterTest
NavMesh mesh = LoadNavMesh("test_boundstree.zip");
Vector3f position = Vector3f.Of(387.52988f, 19.997f, 368.86282f);
int[] tilePos = mesh.CalcTileLoc(position);
long tileRef = mesh.GetTileRefAt(tilePos[0], tilePos[1], 0);
mesh.CalcTileLoc(position, out var tileX, out var tileY);
long tileRef = mesh.GetTileRefAt(tileX, tileY, 0);
MeshTile tile = mesh.GetTileByRef(tileRef);
MeshData data = tile.data;
BVNode[] bvNodes = data.bvTree;