diff options
author | chai <chaifix@163.com> | 2021-09-20 00:42:33 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-20 00:42:33 +0800 |
commit | 02b44c07adfcf921da594120b4cd8fc18b982725 (patch) | |
tree | 723e001ed8c5f7c39419cc4a50a3202a0cf59961 /Assets/Scripts/Utils/QuaternionUtility.cs | |
parent | d4581317f904b870c482a3274e7cc47d1732a673 (diff) |
+command buffer
Diffstat (limited to 'Assets/Scripts/Utils/QuaternionUtility.cs')
-rw-r--r-- | Assets/Scripts/Utils/QuaternionUtility.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Assets/Scripts/Utils/QuaternionUtility.cs b/Assets/Scripts/Utils/QuaternionUtility.cs new file mode 100644 index 00000000..d491b1fe --- /dev/null +++ b/Assets/Scripts/Utils/QuaternionUtility.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class QuaternionUtility +{ + + public static Matrix4x4 ToMatrix(ref this Quaternion q) + { + Matrix4x4 m = new Matrix4x4(); + + // Precalculate coordinate products + float x = q.x * 2.0F; + float y = q.y * 2.0F; + float z = q.z * 2.0F; + float xx = q.x * x; + float yy = q.y * y; + float zz = q.z * z; + float xy = q.x * y; + float xz = q.x * z; + float yz = q.y * z; + float wx = q.w * x; + float wy = q.w * y; + float wz = q.w * z; + + // Calculate 3x3 matrix from orthonormal basis + m[0] = 1.0f - (yy + zz); + m[1] = xy + wz; + m[2] = xz - wy; + m[3] = 0.0F; + + m[4] = xy - wz; + m[5] = 1.0f - (xx + zz); + m[6] = yz + wx; + m[7] = 0.0F; + + m[8] = xz + wy; + m[9] = yz - wx; + m[10] = 1.0f - (xx + yy); + m[11] = 0.0F; + + m[12] = 0.0F; + m[13] = 0.0F; + m[14] = 0.0F; + m[15] = 1.0F; + + return m; + } + + +} |