summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Utils/MatrixUtility.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-20 00:42:33 +0800
committerchai <chaifix@163.com>2021-09-20 00:42:33 +0800
commit02b44c07adfcf921da594120b4cd8fc18b982725 (patch)
tree723e001ed8c5f7c39419cc4a50a3202a0cf59961 /Assets/Scripts/Utils/MatrixUtility.cs
parentd4581317f904b870c482a3274e7cc47d1732a673 (diff)
+command buffer
Diffstat (limited to 'Assets/Scripts/Utils/MatrixUtility.cs')
-rw-r--r--Assets/Scripts/Utils/MatrixUtility.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Assets/Scripts/Utils/MatrixUtility.cs b/Assets/Scripts/Utils/MatrixUtility.cs
new file mode 100644
index 00000000..f3d865f2
--- /dev/null
+++ b/Assets/Scripts/Utils/MatrixUtility.cs
@@ -0,0 +1,42 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public static class MatrixUtility
+{
+
+ public static void SetTR(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q)
+ {
+ matrix = q.ToMatrix();
+ matrix[12] = pos[0];
+ matrix[13] = pos[1];
+ matrix[14] = pos[2];
+ }
+
+ public static void SetTRS2(ref this Matrix4x4 matrix, Vector3 pos, Quaternion q, Vector3 s)
+ {
+ matrix = q.ToMatrix();
+
+ matrix[0] *= s[0];
+ matrix[1] *= s[0];
+ matrix[2] *= s[0];
+ matrix[4] *= s[1];
+ matrix[5] *= s[1];
+ matrix[6] *= s[1];
+ matrix[8] *= s[2];
+ matrix[9] *= s[2];
+ matrix[10] *= s[2];
+ matrix[12] = pos[0];
+ matrix[13] = pos[1];
+ matrix[14] = pos[2];
+
+ }
+
+ public static Matrix4x4 RotateAndTranslate(Vector3 pos, Quaternion q)
+ {
+ Matrix4x4 m = new Matrix4x4();
+ m.SetTR(pos, q);
+ return m;
+ }
+
+}