2024-04-28 13:55:19 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.utils;
|
|
|
|
|
|
2024-06-05 13:38:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>CoordinateUtils</para>
|
|
|
|
|
/// <para>坐标工具类</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class CoordinateUtils
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>方向描述</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum OrientationDescribe
|
|
|
|
|
{
|
|
|
|
|
//上
|
2024-05-08 10:22:04 +00:00
|
|
|
|
Up,
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
//下
|
2024-05-08 10:22:04 +00:00
|
|
|
|
Down,
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
//左
|
2024-05-08 10:22:04 +00:00
|
|
|
|
Left,
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
//右
|
2024-05-08 10:22:04 +00:00
|
|
|
|
Right,
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
//原点
|
2024-05-08 10:22:04 +00:00
|
|
|
|
Origin
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Vector to direction description(Relative to the origin)</para>
|
|
|
|
|
/// <para>向量到方向描述(相对原点而言)</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="origin">
|
|
|
|
|
///<para>origin</para>
|
|
|
|
|
///<para>原点坐标</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="position">
|
|
|
|
|
///<para>position</para>
|
|
|
|
|
///<para>位置</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static OrientationDescribe[] VectorToOrientationArray(Vector2 origin, Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
var vector2 = position - origin;
|
|
|
|
|
var orientationDescribes = new OrientationDescribe[2];
|
|
|
|
|
if (vector2.X < 0)
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[0] = OrientationDescribe.Left;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
else if (vector2.X == 0)
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[0] = OrientationDescribe.Origin;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[0] = OrientationDescribe.Right;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vector2.Y > 0)
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[1] = OrientationDescribe.Down;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
else if (vector2.Y == 0)
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[0] = OrientationDescribe.Origin;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
orientationDescribes[1] = OrientationDescribe.Up;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orientationDescribes;
|
|
|
|
|
}
|
|
|
|
|
}
|