diff options
author | chai <chaifix@163.com> | 2021-04-07 21:06:10 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-04-07 21:06:10 +0800 |
commit | c7e2d8f773baa3955f17402b842eb43329c5f3a0 (patch) | |
tree | 5ba3985d20a2908a67fefa89579f6cf3a94b6a5a /Assets/Test/UIEffect/Program/Common/Matrix2x3.cs | |
parent | e7dfbec8e8634e767d78959941daf71a96e021cf (diff) |
+UI_Effect
Diffstat (limited to 'Assets/Test/UIEffect/Program/Common/Matrix2x3.cs')
-rw-r--r-- | Assets/Test/UIEffect/Program/Common/Matrix2x3.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Assets/Test/UIEffect/Program/Common/Matrix2x3.cs b/Assets/Test/UIEffect/Program/Common/Matrix2x3.cs new file mode 100644 index 0000000..ec2cb69 --- /dev/null +++ b/Assets/Test/UIEffect/Program/Common/Matrix2x3.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace Coffee.UIEffects +{ + /// <summary> + /// Matrix2x3. + /// </summary> + public struct Matrix2x3 + { + public float m00, m01, m02, m10, m11, m12; + + public Matrix2x3(Rect rect, float cos, float sin) + { + const float center = 0.5f; + float dx = -rect.xMin / rect.width - center; + float dy = -rect.yMin / rect.height - center; + m00 = cos / rect.width; + m01 = -sin / rect.height; + m02 = dx * cos - dy * sin + center; + m10 = sin / rect.width; + m11 = cos / rect.height; + m12 = dx * sin + dy * cos + center; + } + + public static Vector2 operator *(Matrix2x3 m, Vector2 v) + { + return new Vector2( + (m.m00 * v.x) + (m.m01 * v.y) + m.m02, + (m.m10 * v.x) + (m.m11 * v.y) + m.m12 + ); + } + } +} |