MatrixExtensions.cs 901 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. namespace MonoGame.Extended
  4. {
  5. public static class MatrixExtensions
  6. {
  7. public static bool Decompose(this Matrix matrix, out Vector2 position, out float rotation, out Vector2 scale)
  8. {
  9. Vector3 position3, scale3;
  10. Quaternion rotationQuaternion;
  11. if (matrix.Decompose(out scale3, out rotationQuaternion, out position3))
  12. {
  13. var direction = Vector2.Transform(Vector2.UnitX, rotationQuaternion);
  14. rotation = (float) Math.Atan2(direction.Y, direction.X);
  15. position = new Vector2(position3.X, position3.Y);
  16. scale = new Vector2(scale3.X, scale3.Y);
  17. return true;
  18. }
  19. position = Vector2.Zero;
  20. rotation = 0;
  21. scale = Vector2.One;
  22. return false;
  23. }
  24. }
  25. }