diff options
Diffstat (limited to 'Assets/Scripts/Utils/TransformUtility.cs')
-rw-r--r-- | Assets/Scripts/Utils/TransformUtility.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Assets/Scripts/Utils/TransformUtility.cs b/Assets/Scripts/Utils/TransformUtility.cs new file mode 100644 index 00000000..62a28ece --- /dev/null +++ b/Assets/Scripts/Utils/TransformUtility.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class TransformUtility +{ + + public static Matrix4x4 GetLocalToWorldMatrix(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while(transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTRS2(transform.localPosition, transform.localRotation, transform.localScale); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixNoScale(Transform transform) + { + Matrix4x4 mat = Matrix4x4.identity; + while (transform != null) + { + Matrix4x4 m = Matrix4x4.identity; + m.SetTR(transform.localPosition, transform.localRotation); + mat = m * mat; + transform = transform.parent; + } + + return mat; + } + + public static Matrix4x4 GetLocalToWorldMatrixRootBone(Transform transform) + { + //Matrix4x4 mat = Matrix4x4.identity; + //while (transform != null) + //{ + // Matrix4x4 m = Matrix4x4.identity; + // m = Matrix4x4.Rotate(transform.localRotation); + // mat = m * mat; + // transform = transform.parent; + //} + //mat.SetColumn(3, new Vector4(trans.position.x, trans.position.y, trans.position.z, 1)); + + Matrix4x4 mat = Matrix4x4.Rotate(transform.rotation); + mat.SetColumn(3, new Vector4(transform.position.x, transform.position.y, transform.position.z, 1)); + + return mat; + } + +}
\ No newline at end of file |