Change the start of the matrix transformation

I have a System.Drawing.Drawing2D.Matrix with rotation and translation transformations that I need to apply to a sprite. Unfortunately, the start of the rotation is in the upper left corner of the sprite.

How to change the start of rotation to the center of the sprite?

+3
source share
3 answers

Unfortunately, none of the proposed solutions work for me. They seem to be good solutions and are likely to work in other scenarios, but not in my case.

However, I found a solution that works:
I changed the values ​​for the OffsetX and OffsetY fields of the matrix as follows:

OffsetX = OffsetX - M11 * hx - M21 * hy + hx;
OffsetY = OffsetY - M12 * hx - M11 * hy + hy;

Where hx is the half width, hy is half the height of the sprite, and M11, M12 and M21 are the corresponding fields of the matrix.

0
source

( ), ( ).

, :

(-half width, -half height),
( ) ( ).

+2
+2

All Articles