2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB
C#

2 years ago
using UnityEngine;
namespace Game
{
public abstract partial class Util
{
//返回角度值(-180,180],(1,0,0)为0
//只关注y=0平面的向量
public static float Vec3ToRot(Vector3 vector)
{
var rot = Quaternion.FromToRotation(vector, Vector3.right);
return rot.eulerAngles.y;
}
public static Vector3 IgnoreY(Vector3 vector)
{
return new Vector3(vector.x, 0, vector.z);
}
2 years ago
public static Quaternion Rot2Quaternion(float rot)
{
return Quaternion.AngleAxis(rot, Vector3.forward);
}
/// <summary>
/// 角度转弧度
/// </summary>
/// <param name="rot"></param>
/// <returns></returns>
public static float ToRadian(float rot)
{
return rot * Mathf.PI / 180f;
}
/// <summary>
/// 弧度转角度
/// </summary>
/// <param name="rot"></param>
/// <returns></returns>
public static float ToAngle(float rot)
{
return rot * 180f / Mathf.PI;
}
}
}