Jump to content
  • Advertisement
Sign in to follow this  
detlion1643

basic 2d rotation / geometry

This topic is 2534 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

Please bare with me on this, I'm still new and figuring stuff out.

So far I'm displaying an image file onto the screen with GDI, and have some code to turn the image 90 degrees based on mouse movement. However, I would like the image to rotate all the time based on the mouse coordinates.

If I think logically about it, I should create a downward line from the image middle point, create a line from the image middle point to the current mouse cooridinates, and measure the opening of that angle. Then rotate the image to the new measurement angle - the previous rotation percentage (this should provide fluid rotation instead of always from an original facing image).

However, the geometry escapes my mind since it's been 11 years since I've seen anything geometry related, and every rotation and matrix example deals with opengl/dx/other api/library functions/calls.

Any help in trying to figure out the math of finding the angles would be greatly appreciated!

Example: Image of 50x50 at x=50 y=50 location (middle rotation point = 75,75). Imaginary downward line = 75,0 to 75,y where y=anything > 75. New line = 75,75 to mouselocx,mouselocy. Need to find the angle between those two lines going clockwise

Share this post


Link to post
Share on other sites
Advertisement
You can find the angle with the help of a function called atan2. People usually use the right side of the x axis instead of your downward line. In the more standard convention and with the center of rotation being at the origin, the angle required to move the right side of the x axis to the point (a,b) is atan2(b,a).

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!