85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace ServerCore;
|
|
|
|
|
|
// HANDOVER: 3차원 기반 회전 함수를 제공 한다.
|
|
// TransformHelper.rotate() 짐벌락 (Gimbal Lock) 이슈가 있기 때문에 본 함수를 사용하면 안되고,
|
|
// QuaternionHelper 클래스의 함수를 사용해야 한다.
|
|
|
|
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;
|
|
}
|
|
}
|