MatrixExtensions.cs 541 B

1234567891011121314151617181920212223
  1. using System;
  2. using UnityEngine;
  3. namespace TriLib
  4. {
  5. public static class MatrixExtensions
  6. {
  7. public static Quaternion ExtractRotation(this Matrix4x4 matrix)
  8. {
  9. return Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
  10. }
  11. public static Vector3 ExtractPosition(this Matrix4x4 matrix)
  12. {
  13. return matrix.GetColumn(3);
  14. }
  15. public static Vector3 ExtractScale(this Matrix4x4 matrix)
  16. {
  17. return new Vector3(matrix.GetColumn(0).magnitude, matrix.GetColumn(1).magnitude, matrix.GetColumn(2).magnitude);
  18. }
  19. }
  20. }