Jump to content
  • Advertisement
Sign in to follow this  

SDL rotating a surface to face the mouse

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

How would i rotate a surface in SDL to face the mouse?
If you're asking how to compute the angle (which isn't specific to SDL), you can use the following method:
float angle = atan2(mouse.y - object.y, mouse.x - object.x);
If you're asking how to rotate the surface itself for rendering purposes, that depends. If you're using software rendering, you could use pre-rotated sprites, or use an external library to perform the image rotation (I've never used it, but I believe there's an add-on library for SDL that offers image rotation and other image manipulation functions). If you're using hardware rendering (e.g. via OpenGL or Direct3D), then you basically get sprite rotation for free (you just need to compute the rotation angle and set up your transforms appropriately).

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!