tags:

views:

1520

answers:

2

I am building a game and the main character's arm will be following the mouse cursor, so it will be rotating quite frequently. What would be the best way to rotate it?

+1  A: 

You can use a library like SDL_gfx

Artur Soler
+5  A: 

With SDL you have a few choices.

  1. Rotate all your sprites in advance (pre-render all possible rotations) and render them like you would any other sprite. (Fast, but uses more memory and more sprites)

  2. Use something like SDL_gfx to do real-time rotation/zooming. (Not recommended, very slow)

  3. Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.

Option 3 is probably your best bet because you gain all of the advantages of using OpenGL. It's really up to you how to want to do it. It's also a possibility that you can load your sprites, perform all rotation calculations with SDL_gfx and then save the rotated versions to a SDL_Surface in memory.

EDIT: In response to your comment I would recommend checking out this GPWiki tutorial about using OpenGL with SDL. It doesn't cover rotation but it does cover basic set up and drawing. There is an OpenGl function, glRotatef, which can be useful in your case. A quick search brought back this little tidbit which could also be helpful.

Zack Mulgrew
I think I'd like to explore the OpenGL route, however, I've never worked with it. Do you have any recommendations on a website to start on a tutorial for rotation?
Justen
I've looked at some code from NeHe, and this seems incredibly tedious to set up a rotation on an image... I can't understand it at all, any help on this topic?
Justen
I don't/haven't worked with OpenGL in a long time. Your OpenGL-specific rotation question may be a good topic for a new question. You're bound to get a much better answer than I can give.
Zack Mulgrew