提交 3781d021 编写于 作者: 魔术师Dix's avatar 魔术师Dix

更新API;

上级 816d22df
......@@ -390,6 +390,88 @@ namespace Oroxylum
return x + z;
}
public static Vector2 XZ(this Vector3 pos) { return new Vector2(pos.x, pos.z); }
public static Vector2 XY(this Vector3 pos) { return new Vector2(pos.x, pos.y); }
public static Vector2 ZY(this Vector3 pos) { return new Vector2(pos.z, pos.y); }
/// <summary>
/// 看向某个目标时,旋转的欧拉角
/// </summary>
/// <param name="pos"></param>
/// <param name="target">目标点</param>
/// <returns>旋转欧拉角</returns>
public static Vector3 LookAtEulerAngle(this Vector3 pos, Vector3 target)
{
Vector3 fwd = target - pos;
return Quaternion.LookRotation(fwd, Vector3.up).eulerAngles;
}
public static int ToInt(this long val)
{
//极值判定;
if (val > int.MaxValue)
{
Logger.LogError($"传入值过大: {val}");
return int.MaxValue;
}
if (val < int.MinValue)
{
Logger.LogError($"传入值过小: {val}");
return int.MinValue;
}
return System.Convert.ToInt32(val);
}
public static int Add(this int a, long b)
{
long addRet = a + b;
return addRet.ToInt();
}
/// <summary>
/// 是否是有效的 Vector3;
/// </summary>
public static bool IsVaild(this Vector3 point)
{
if (float.IsNaN(point.x) || float.IsNaN(point.y) || float.IsNaN(point.z))
return false;
if (float.IsInfinity(point.x) || float.IsInfinity(point.y) || float.IsInfinity(point.z))
return false;
return true;
}
public static Vector3 Div(this Vector3 a, Vector3 b)
{
float x = a.x / b.x;
float y = a.y / b.y;
float z = a.z / b.z;
return new Vector3(x, y, z);
}
public static Vector2 Div(this Vector2 a, Vector2 b)
{
float x = a.x / b.x;
float y = a.y / b.y;
return new Vector2(x, y);
}
public static Vector3 Mul(this Vector3 a, Vector3 b)
{
float x = a.x * b.x;
float y = a.y * b.y;
float z = a.z * b.z;
return new Vector3(x, y, z);
}
public static Vector2 Mul(this Vector2 a, Vector2 b)
{
float x = a.x * b.x;
float y = a.y * b.y;
return new Vector2(x, y);
}
#endregion
......
......@@ -12,59 +12,16 @@ namespace Oroxylum
/// <returns></returns>
public static float Square(this float value) { return value * value; }
public static Vector2 XZ(this Vector3 pos) { return new Vector2(pos.x, pos.z); }
public static float2 XZ_float2(this Vector3 v) { return new float2(v.x, v.z); }
public static Vector2 XY(this Vector3 pos) { return new Vector2(pos.x, pos.y); }
public static float2 XY_float2(this Vector3 pos) { return new float2(pos.x, pos.y); }
public static Vector2 ZY(this Vector3 pos) { return new Vector2(pos.z, pos.y); }
public static float2 ZY_float2(this Vector3 pos) { return new float2(pos.z, pos.y); }
/// <summary>
/// 看向某个目标时,旋转的欧拉角
/// </summary>
/// <param name="pos"></param>
/// <param name="target">目标点</param>
/// <returns>旋转欧拉角</returns>
public static Vector3 LookAtEulerAngle(this Vector3 pos, Vector3 target)
{
Vector3 fwd = target - pos;
return Quaternion.LookRotation(fwd, Vector3.up).eulerAngles;
}
public static int ToInt(this long val)
{
//极值判定;
if (val > int.MaxValue)
{
Logger.LogError($"传入值过大: {val}");
return int.MaxValue;
}
if (val < int.MinValue)
{
Logger.LogError($"传入值过小: {val}");
return int.MinValue;
}
return System.Convert.ToInt32(val);
}
public static int Add(this int a, long b)
{
long addRet = a + b;
return addRet.ToInt();
}
/// <summary>
/// 是否是有效的 Vector3;
/// </summary>
public static bool IsVaild(this Vector3 point)
public static bool IsVaild(this float3 point)
{
if (float.IsNaN(point.x) || float.IsNaN(point.y) || float.IsNaN(point.z))
return false;
......@@ -75,22 +32,37 @@ namespace Oroxylum
return true;
}
public static Vector3 DivByVector3(this Vector3 a, Vector3 b)
{
public static float3 Div(this float3 a, float3 b)
{
float x = a.x / b.x;
float y = a.y / b.y;
float z = a.z / b.z;
return new Vector3(x, y, z);
return new float3(x, y, z);
}
public static float2 Div(this float2 a, float2 b)
{
float x = a.x / b.x;
float y = a.y / b.y;
return new float2(x, y);
}
public static Vector3 MulByVector3(this Vector3 a, Vector3 b)
public static float3 Mul(this float3 a, float3 b)
{
float x = a.x * b.x;
float y = a.y * b.y;
float z = a.z * b.z;
return new Vector3(x, y, z);
return new float3(x, y, z);
}
public static float2 Mul(this float2 a, float2 b)
{
float x = a.x * b.x;
float y = a.y * b.y;
return new float2(x, y);
}
public static long Int2ToLong(int2 v)
{
int q = v.x, r = v.y;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册