using System; using UnityEngine; namespace Utils { /// /// 旋转工具类 /// public static class RotateUtils { private static Matrix4x4 _matrix; /// /// 获得绕X轴旋转矩阵 /// /// 旋转的角度 /// public static Matrix4x4 RotateAxisX(float degree) { var sin = MathF.Sin(degree); var cos = MathF.Cos(degree); _matrix.SetRow(0 ,new Vector4(1,0,0,0)); _matrix.SetRow(1, new Vector4(0, cos, -sin, 0)); _matrix.SetRow(2, new Vector4(0, sin, cos, 0)); _matrix.SetRow(3, new Vector4(0, 0, 0, 1)); return _matrix; } /// /// 获得绕Y轴旋转矩阵 /// /// 旋转的角度 /// public static Matrix4x4 RotateAxisY(float degree) { var sin = MathF.Sin(degree); var cos = MathF.Cos(degree); _matrix.SetRow(0, new Vector4(cos, 0, sin, 0)); _matrix.SetRow(1, new Vector4(0, 1, 0, 1)); _matrix.SetRow(2, new Vector4(-sin, 0, cos, 0)); _matrix.SetRow(3, new Vector4(0, 0, 0, 1)); return _matrix; } /// /// 获得绕Z轴旋转矩阵 /// /// 旋转的角度 /// public static Matrix4x4 RotateAxisZ(float degree) { var sin = MathF.Sin(degree); var cos = MathF.Cos(degree); _matrix.SetRow(0, new Vector4(cos, -sin, 0, 0)); _matrix.SetRow(1, new Vector4(sin, cos, 0, 0)); _matrix.SetRow(2, new Vector4(0, 0, 1, 0)); _matrix.SetRow(3, new Vector4(0, 0, 0, 1)); return _matrix; } } }