# How do I rotate a sprite around a pivot point using SDL_gfx's rotozoomSurface?

Using SDL_gfx's rotozoomSurface function to rotate a 38x58 sprite....naturally when it rotates it creates a new surface with a new size, and the rotation isn't going around the center point. I am actually having issues trying to figure out how to make it seem like its spinning around an axis...

Here is the image that I am using:

And here is the code that I have thus far:

  #define ANGLE_STEPS 32
#define ANGLE_STEP  (360 / ANGLE_STEPS)
...
int angle = 0;
SDL_Rect cpos;
cpos.x = cpos.y = 100;
...
// create chopper angled surfaces
for (int i = 0; i < ANGLE_STEPS; i++)
{
choppers[i] = rotozoomSurface(chopper, i * ANGLE_STEP, 1, 0);
}
...

// blit the currently requested angle
SDL_BlitSurface(choppers[angle], NULL, screen, &cpos);
...

// handle rotating the chopper
if (keystate[keys[LEFTKEY]])
{
angle = (angle + 1) & (ANGLE_STEPS - 1);
cpos.x = ?
cpos.y = ?
}
if (keystate[keys[RIGHTKEY]])
{
angle = (angle - 1) & (ANGLE_STEPS - 1);
cpos.x = ?
cpos.y = ?
}

• You should look up some basic 2D linear algebra texts. The answer you figured out on your own is the basic principle of needing to translate your coordinate system to the appropriate origin before rotation. Graphics tutorials often cover this topic as well, so those may be a good place to look for a good linear algebra introduction. Sorry that I don't have a good link on hand to give you, but Google should find you some useful material. – Sean Middleditch Jan 5 '12 at 11:38
• Yea, that's a good point. Honestly been forever since I've had to use this kind of math and its a wakeup call to how much I've forgotten over time. – the_e Jan 5 '12 at 19:41