SDL rotating a surface to face the mouse
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement