diff --git a/Assets/MainBehaviour.cs b/Assets/MainBehaviour.cs index c3272ce..347103e 100644 --- a/Assets/MainBehaviour.cs +++ b/Assets/MainBehaviour.cs @@ -88,9 +88,7 @@ private void CreateNodes() private void CreateBonds() { - //shit code,it's my fault - Bonds temp; - temp = new Bonds(_nodes[0], _nodes[4], _scale); + var temp = new Bonds(_nodes[0], _nodes[4], _scale); _bonds.Add(temp); temp = new Bonds(_nodes[0], _nodes[1], _scale); @@ -219,49 +217,4 @@ private void OnReceive(List landmarks) _poseTransforms[(int)landmark.Type] = poseTransform; } } - - //绕X轴旋转 - private Matrix4x4 RotateAxisX(float rot) - { - var matrix = new Matrix4x4(); - float cosrot = MathF.Cos(rot); - float sinrot = MathF.Sin(rot); - - matrix.SetRow(0, new Vector4(1,0,0,0)); - matrix.SetRow(1, new Vector4(0,cosrot,-sinrot,0)); - matrix.SetRow(2, new Vector4(0,sinrot,cosrot,0)); - matrix.SetRow(3, new Vector4(0,0,0,1)); - - return matrix; - } - - //绕Y轴旋转 - private Matrix4x4 RotateAxisY(float rot) - { - var matrix = new Matrix4x4(); - float cosrot = MathF.Cos(rot); - float sinrot = MathF.Sin(rot); - - matrix.SetRow(0, new Vector4(cosrot,0,sinrot,0)); - matrix.SetRow(1, new Vector4(0,1,0,0)); - matrix.SetRow(2, new Vector4(-sinrot,0,cosrot,0)); - matrix.SetRow(3, new Vector4(0,0,0,1)); - - return matrix; - } - - //绕Z轴旋转 - private Matrix4x4 RotateAxisZ(float rot) - { - var matrix = new Matrix4x4(); - float cosrot = MathF.Cos(rot); - float sinrot = MathF.Sin(rot); - - matrix.SetRow(0, new Vector4(cosrot,-sinrot,0,0)); - matrix.SetRow(1, new Vector4(sinrot,cosrot,0,0)); - matrix.SetRow(2, new Vector4(0,0,1,0)); - matrix.SetRow(3, new Vector4(0,0,0,1)); - - return matrix; - } } diff --git a/Assets/Utils/RotateUtils.cs b/Assets/Utils/RotateUtils.cs new file mode 100644 index 0000000..5a8e52f --- /dev/null +++ b/Assets/Utils/RotateUtils.cs @@ -0,0 +1,67 @@ +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; + } + } +} \ No newline at end of file diff --git a/Assets/Utils/RotateUtils.cs.meta b/Assets/Utils/RotateUtils.cs.meta new file mode 100644 index 0000000..3f6599f --- /dev/null +++ b/Assets/Utils/RotateUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d748c6669d714e65a5ca9164c5798583 +timeCreated: 1677319275 \ No newline at end of file