[java] Rotation with AffineTransform

Started by
2 comments, last by capn_midnight 19 years, 2 months ago
May apologies for bothering everyone... AffineTransform's getRotateInstance() gets an instance that rotates it around the top-left corner instead of the middle... and if I use the getRotateInstance() with an anchor point, it rotates my image out into the middle of nowhere... Any ideas? Thanks in advance and best of wishes, xycos
"For sweetest things turn sour'st by their deeds;Lilies that fester smell far worse than weeds."- William Shakespere, Sonnet 94
Advertisement
Quote:Original post by xycos
May apologies for bothering everyone...

AffineTransform's getRotateInstance() gets an instance that rotates it around the top-left corner instead of the middle... and if I use the getRotateInstance() with an anchor point, it rotates my image out into the middle of nowhere... Any ideas?

Thanks in advance and best of wishes,
xycos

you need three transformations
translate(width/2, height/2);
rotate(angle);
translate(-width/2, -height/2);

you need to put the center of your object at the origin (that's the third line), rotate (second), and then put the object back (first line).

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Wow that was... exactly what I needed. Thank you SO much!

Best of wishes,
xycos
"For sweetest things turn sour'st by their deeds;Lilies that fester smell far worse than weeds."- William Shakespere, Sonnet 94
reading up on AffineTransform.getRotateInstance(double theta, int x, int y), you should use this method and pass -width/2 for x and -height/2 for y. It will do the same as my 3 steps above, but will be 3 times faster (only one transform).

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement