I thought about it myself, finally. Most loans refer to this blog post .
You can use this method to decompose your matrix:
private void DecomposeMatrix(ref Matrix matrix, out Vector2 position, out float rotation, out Vector2 scale) { Vector3 position3, scale3; Quaternion rotationQ; matrix.Decompose(out scale3, out rotationQ, out position3); Vector2 direction = Vector2.Transform(Vector2.UnitX, rotationQ); rotation = (float)Math.Atan2((double)(direction.Y), (double)(direction.X)); position = new Vector2(position3.X, position3.Y); scale = new Vector2(scale3.X, scale3.Y); }
Then you can build the transformation matrix so that your sheets can do this:
Matrix transform = Matrix.CreateScale(new Vector3(this.Scale, 1.0f)) * Matrix.CreateRotationZ(this.Rotation) * Matrix.CreateTranslation(new Vector3(this.Position, 0));
For parent sprites, specify the source:
Matrix transform = Matrix.CreateTranslation(new Vector3(-this.Origin, 0)) * Matrix.CreateScale(new Vector3(this.Scale, 1.0f)) * Matrix.CreateRotationZ(this.Rotation) * Matrix.CreateTranslation(new Vector3(this.position, 0));
Multiply all matrices on the stack in reverse order.
source share