[java] Rotation with AffineTransform
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
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement