I'm trying to simply rotate a shape about its centre or a specific point but I can not seem to get the right result. My code is below...
1 2 3 4 5 6 7 8 9 10
Graphics g(pDC->GetSafeHdc());
SolidBrush brush(Color(200,88,88,88));
int x = 100, y = 100;
int w = 50, h = 80;
g.FillRectangle(&brush, x, y, w, h); // Original Rectangle
g.TranslateTransform(x+(w/2), y+(y/2), MatrixOrderAppend); // Fix position
g.RotateTransform(45); // Rotate 45 degrees
g.FillRectangle(&brush, x, y, w, h); // Rotated Rectangle
g.ResetTransform();
It seems to be rotating around a different point instead of the center of my rectangle. I must be misunderstanding the TranslateTransform part. Can anyone see what I am doing wrong?
g.TranslateTransform(x+(w/2), y+(y/2), MatrixOrderAppend); // Fix position
Shouldn't this be g.TranslateTransform(x+(w/2), y+(h/2), MatrixOrderAppend); // Fix position