Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

enter image description here

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 = ?
share|improve this question
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. – espais Jan 5 '12 at 19:41
up vote 1 down vote accepted

Never mind, figured it out after simply sketching it out.

I calculated the center point of both the old and new sprite to be drawn, and simply subtracted that offset from the x and y points to be drawn.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.