Jump to content
  • Advertisement
Sign in to follow this  
xycos

[java] Rotation with AffineTransform

This topic is 4904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!