Advertisement Jump to content
Sign in to follow this  
Lith

SDL rotating a surface to face the mouse

This topic is 3362 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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net 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!