Rotating a Picture

Greetings all,

I’ve only been on the list a couple of days. I’ve been about a week into
actively studying game programming between semesters. Since I’ve got
about another week ahead of me with nothing to do till classes end I was
hoping to see how far I got into making a Tetris type game (I heard
thats a good place to start). I’m just playing around with the SDL API
and getting comfortable with the language, I was trying to figure out
how to rotate a picture 90 degrees. I was considering trying to make an
offset using an SDL_Rect and somehow changing the upper left coordinates
to a picture, not having much success with it, anyone out there have any
ideas for me / Place to look on this subject?

Thanks in advance,

Andrew Thorell
University of Central Florida
Physics Tutor, Student Academic Resource Center
Bachelor of Science, Computer Engineering

— Andrew Thorell wrote:

I’ve only been on the list a couple of days. I’ve been about a week
into actively studying game programming between semesters. Since
I’ve got about another week ahead of me with nothing to do till
classes end I was hoping to see how far I got into making a Tetris
type game (I heard thats a good place to start). I’m just playing
around with the SDL API and getting comfortable with the language, I
was trying to figure out how to rotate a picture 90 degrees. I was
considering trying to make an offset using an SDL_Rect and somehow
changing the upper left coordinates to a picture, not having much
success with it, anyone out there have any ideas for me / Place to
look on this subject?

This particular problem is one suited to a number of different
approaches, some of which would not be suitable for more complex
images or arbitrary rotations.

The way I would do this for a Tetris-clone or similar would actually
be to not do any rotations at all. I’d have my source bitmap
containing
all the different little square cells that Tetris builds the little
four-square widgets out of, and I would blit from that surface to the
display four times, with four different destinations, to build my
little
falling widgets. There are a number of optomizations that would want
doing, if speed was an issue, that I’m glossing over, but that’d be my
first pass at it.

Doing a true rotation can be quite expensive in processor time.
Certainly, for arbitrary rotations of complex sprites, it’s very often
better simply to have your surface contain 8/16/32 different images,
one for each facing, rather than one image that is transformed at
runtime. If, for example, blits are very expensive (which is not the
case in SDL, to my experience, but I’m relatively new, too), then you
might have your surface contain images of each arrangement of blocks
at each of the four rotations, rather than building composite sprites
(as I outlined above) or doing runtime image transformation.

                                                          NBarnes__________________________________

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software