Files
caliverse_server/ServerCore/Math/TransformHelper.cs
2025-05-01 07:20:41 +09:00

80 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServerCore;
public class TransformHelper
{
public static Position rotateX(Position pos, Rotation rot)
{
double radian = (Math.PI * rot.Roll) / 180.0f;
var cosValue = Math.Cos(radian);
var sinValue = Math.Sin(radian);
double y = (pos.Y * cosValue) + (pos.Z * -sinValue);
double z = (pos.Y * sinValue) + (pos.Z * cosValue);
Position retValue = new Position
{
X = pos.X,
Y = y,
Z = z,
};
return retValue;
}
public static Position rotateY(Position pos, Rotation rot)
{
double radian = (Math.PI * rot.Pitch) / 180.0f;
var cosValue = Math.Cos(radian);
var sinValue = Math.Sin(radian);
double x = (pos.X * cosValue) + (pos.Z * -sinValue);
double z = (pos.X * sinValue) + (pos.Z * cosValue);
Position retValue = new Position
{
X = x,
Y = pos.Y,
Z = z,
};
return retValue;
}
public static Position rotateZ(Position pos, Rotation rot)
{
double radian = (Math.PI * rot.Yaw) / 180.0f;
var cosValue = Math.Cos(radian);
var sinValue = Math.Sin(radian);
double x = (pos.X * cosValue) + (pos.Y * -sinValue);
double y = (pos.X * sinValue) + (pos.Y * cosValue);
Position retValue = new Position
{
X = x,
Y = y,
Z = pos.Z,
};
return retValue;
}
public static Position rotate(Position pos, Rotation rot)
{
Position tempPos;
tempPos = rotateY(pos, rot);
tempPos = rotateZ(tempPos, rot);
tempPos = rotateX(tempPos, rot);
return tempPos;
}
}