Archived
添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。 添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。 添加了一个用于看向某个物体的旋转控制器。 添加了一个加载宏。 完善了批处理脚本流程。
This commit is contained in:
@@ -9,6 +9,8 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
public static class Vector3Extend
|
||||
{
|
||||
#region 四则运算
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector3 Add(this Vector3 a, Vector3 b)
|
||||
=> new Vector3(
|
||||
@@ -105,6 +107,9 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
a.z / b
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 扩展运算
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector3 Xonly(this Vector3 a)
|
||||
@@ -174,6 +179,9 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
public static Vector3 Floor(this Vector3 vec)
|
||||
=> new Vector3((int)vec.x, (int)vec.y, (int)vec.z);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 高级运算
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector3 Min(this Vector3 a, Vector3 b)
|
||||
@@ -242,6 +250,9 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 特殊运算
|
||||
|
||||
/// <summary>
|
||||
/// 将这个向量投影到一个给定坐标的向上的平面上,同时变换到平面坐标
|
||||
@@ -294,11 +305,37 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector3 Orthogonalization(this Vector3 vec)
|
||||
=> new Vector3(
|
||||
(float)Math.Round(vec.x),
|
||||
(float)Math.Round(vec.y),
|
||||
(float)Math.Round(vec.z)
|
||||
);
|
||||
{
|
||||
Vector3[] axes = { Vector3.right, Vector3.up, Vector3.forward };
|
||||
float minAngle = float.MaxValue;
|
||||
Vector3 minAngleAxis = Vector3.zero;
|
||||
|
||||
foreach(Vector3 axis in axes)
|
||||
{
|
||||
float dot = Vector3.Dot(vec, axis);
|
||||
float angle = Mathf.Abs(dot);
|
||||
if(angle < minAngle)
|
||||
{
|
||||
minAngle = angle;
|
||||
minAngleAxis = axis * Mathf.Sign(dot);
|
||||
}
|
||||
}
|
||||
|
||||
return minAngleAxis;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取与世界正交轴最近的一条轴线
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("可以使用Orthogonalization代替")]
|
||||
public static Vector3 GetWorldNormalAxis(this Vector3 vec)
|
||||
{
|
||||
return vec.Orthogonalization();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user