Advertisement Jump to content
Sign in to follow this  

basic 2d rotation / geometry

This topic is 2686 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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!