mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
126 lines
5.0 KiB
C#
126 lines
5.0 KiB
C#
/*
|
|
* @FileName: LMath.LVector.cs
|
|
* @Date: 2024-04-20 20:06:15
|
|
* @LastEditTime: 2024-04-22 22:58:25
|
|
* @Description: 定点数向量计算相关数学方法
|
|
*/
|
|
|
|
namespace JNGame.Math
|
|
{
|
|
public static partial class LMath
|
|
{
|
|
public static LVector3 Transform(ref LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z,
|
|
ref LVector3 trans)
|
|
{
|
|
return new LVector3(true,
|
|
((axis_x.RawX * point.RawX + axis_y.RawX * point.RawY + axis_z.RawX * point.RawZ) / LFloat.Precision) + trans.RawX,
|
|
((axis_x.RawY * point.RawX + axis_y.RawY * point.RawY + axis_z.RawY * point.RawZ) / LFloat.Precision) + trans.RawY,
|
|
((axis_x.RawZ * point.RawX + axis_y.RawZ * point.RawY + axis_z.RawZ * point.RawZ) / LFloat.Precision) + trans.RawZ);
|
|
}
|
|
|
|
public static LVector3 Transform(LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z,
|
|
ref LVector3 trans)
|
|
{
|
|
return new LVector3(true,
|
|
((axis_x.RawX * point.RawX + axis_y.RawX * point.RawY + axis_z.RawX * point.RawZ) / LFloat.Precision) + trans.RawX,
|
|
((axis_x.RawY * point.RawX + axis_y.RawY * point.RawY + axis_z.RawY * point.RawZ) / LFloat.Precision) + trans.RawY,
|
|
((axis_x.RawZ * point.RawX + axis_y.RawZ * point.RawY + axis_z.RawZ * point.RawZ) / LFloat.Precision) + trans.RawZ);
|
|
}
|
|
|
|
public static LVector3 Transform(ref LVector3 point, ref LVector3 axis_x, ref LVector3 axis_y, ref LVector3 axis_z,
|
|
ref LVector3 trans, ref LVector3 scale)
|
|
{
|
|
long num = (long) point.RawX * (long) scale.RawX /LFloat.Precision;
|
|
long num2 = (long) point.RawY * (long) scale.RawX/LFloat.Precision;
|
|
long num3 = (long) point.RawZ * (long) scale.RawX/LFloat.Precision;
|
|
return new LVector3(true,
|
|
(int) (((long) axis_x.RawX * num + (long) axis_y.RawX * num2 + (long) axis_z.RawX * num3) /LFloat.Precision) +
|
|
trans.RawX,
|
|
(int) (((long) axis_x.RawY * num + (long) axis_y.RawY * num2 + (long) axis_z.RawY * num3) /LFloat.Precision) +
|
|
trans.RawY,
|
|
(int) (((long) axis_x.RawZ * num + (long) axis_y.RawZ * num2 + (long) axis_z.RawZ * num3) /LFloat.Precision) +
|
|
trans.RawZ);
|
|
}
|
|
|
|
public static LVector3 Transform(ref LVector3 point, ref LVector3 forward, ref LVector3 trans)
|
|
{
|
|
LVector3 up = LVector3.Up;
|
|
LVector3 vInt = Cross(LVector3.Up, forward);
|
|
return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans);
|
|
}
|
|
|
|
public static LVector3 Transform(LVector3 point, LVector3 forward, LVector3 trans)
|
|
{
|
|
LVector3 up = LVector3.Up;
|
|
LVector3 vInt = Cross(LVector3.Up, forward);
|
|
return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans);
|
|
}
|
|
|
|
public static LVector3 Transform(LVector3 point, LVector3 forward, LVector3 trans, LVector3 scale)
|
|
{
|
|
LVector3 up = LVector3.Up;
|
|
LVector3 vInt = Cross(LVector3.Up, forward);
|
|
return LMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans, ref scale);
|
|
}
|
|
|
|
public static LVector3 MoveTowards(LVector3 from, LVector3 to, LFloat dist)
|
|
{
|
|
LFloat sqrtMagnitude = (to - from).SqrMagnitude;
|
|
LFloat sprtDist = dist * dist;
|
|
if (sqrtMagnitude <= sprtDist)
|
|
{
|
|
return to;
|
|
}
|
|
LFloat f = sprtDist / sqrtMagnitude;
|
|
return LVector3.Lerp(from, to, f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 方向向量转角度
|
|
/// </summary>
|
|
/// <param name="vec"></param>
|
|
/// <returns></returns>
|
|
public static LFloat ToDeg(this in LVector2 vec)
|
|
{
|
|
var ccwDeg = LMath.Atan2(vec.y, vec.x) * LMath.Rad2Deg;
|
|
var deg = 90 - ccwDeg;
|
|
var rawVal = deg.rawValue % ((LFloat)360).rawValue;
|
|
return new LFloat(true, rawVal);
|
|
}
|
|
|
|
public static LFloat AngleInt(LVector3 lhs, LVector3 rhs)
|
|
{
|
|
return LMath.Acos(Dot(lhs, rhs));
|
|
}
|
|
|
|
public static LFloat Dot(in LVector2 u, in LVector2 v)
|
|
{
|
|
return LVector2.Dot(u, v);
|
|
}
|
|
|
|
public static LFloat Cross(in LVector2 u, in LVector2 v)
|
|
{
|
|
return LVector2.Cross(u, v);
|
|
}
|
|
|
|
public static LVector2 Lerp(in LVector2 from, in LVector2 to, in LFloat f)
|
|
{
|
|
return LVector2.Lerp(from, to, f);
|
|
}
|
|
|
|
public static LFloat Dot(in LVector3 u, in LVector3 v)
|
|
{
|
|
return LVector3.Dot(u, v);
|
|
}
|
|
|
|
public static LVector3 Cross(in LVector3 u, in LVector3 v)
|
|
{
|
|
return LVector3.Cross(u, v);
|
|
}
|
|
|
|
public static LVector3 Lerp(in LVector3 from, in LVector3 to, in LFloat f)
|
|
{
|
|
return LVector3.Lerp(from, to, f);
|
|
}
|
|
}
|
|
} |