forked from aly/qstbak
42 lines
1 KiB
C#
42 lines
1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using FFXIVClientStructs.FFXIV.Common.Component.BGCollision;
|
|
|
|
namespace Auspex;
|
|
|
|
public static class AxTerrainQuery
|
|
{
|
|
private static readonly Dictionary<(int, int), float> _cache = new Dictionary<(int, int), float>();
|
|
|
|
public static float GetTerrainY(float x, float z, float fallbackY = 0f)
|
|
{
|
|
float terrainYRaw = GetTerrainYRaw(x, z);
|
|
if (!float.IsNaN(terrainYRaw))
|
|
{
|
|
return terrainYRaw;
|
|
}
|
|
return fallbackY;
|
|
}
|
|
|
|
public static float GetTerrainYRaw(float x, float z)
|
|
{
|
|
int item = (int)MathF.Round(x * 4f);
|
|
int item2 = (int)MathF.Round(z * 4f);
|
|
if (_cache.TryGetValue((item, item2), out var value))
|
|
{
|
|
return value;
|
|
}
|
|
Vector3 origin = new Vector3(x, 1000f, z);
|
|
Vector3 direction = new Vector3(0f, -1f, 0f);
|
|
RaycastHit hitInfo;
|
|
float num = ((!BGCollisionModule.RaycastMaterialFilter(origin, direction, out hitInfo, 2000f)) ? float.NaN : hitInfo.Point.Y);
|
|
_cache[(item, item2)] = num;
|
|
return num;
|
|
}
|
|
|
|
public static void ClearCache()
|
|
{
|
|
_cache.Clear();
|
|
}
|
|
}
|