• Advertisement
Sign in to follow this  

SDL rotating a surface to face the mouse

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

Advertisement
Quote:
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
Thanks for the answer, i will look into the SDL add on library that you mentioned

Share this post


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

  • Advertisement