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; } }