I’ve seen a bunch of people asking about rotating and zooming and doing both
together on here. We’ve got the zooming working, now we need rotation. And
it doesn’t seem to me that that’s all that difficult, at least not for either OpenGL
or Direct3D.
The exact implementation details vary a bit, but in both systems, you render a
rectangular texture by specifying the locations of the four corners (vertices)
and associating the resulting quad it with a texture. Thing is, there’s no
requirement for the edges of your quad to be parallel to the edges of the
screen, or even for your quad to be rectangular at all.
Rotation, then, becomes trivial to anyone with a moderate knowledge of trig.
Input the original (unrotated) rectangle and an angle, calculate the
positions of the four vertices after applying the rotation, and send those to
GL/D3D.
How about something like this:
int SDL_RenderZoom(SDL_Texture * texture, const SDL_Rect * srcrect,
const SDL_Rect * dstrect, int angle);
Using int for the angle makes it easier to calculate this by using precomputed
sine and cosine tables. This could be made a float for extra precision if
anyone really cares about rotations smaller than 1/360 of a circle. The
center of the resulting quad would be the center of dstrect.
This would be more difficult to implement on non-accelerated backends, of
course. Perhaps it could be unimplemented, or fall back to something like
the rotozoom function on SDL_gfx.
This API would, of course, be much more useful in conjunction with render
targets.
Any thoughts?