Screen rotation

Hi

I want to use SDL to develop a game on a screen that is 1440x900 but with the monitor rotated 90 degrees (in a portrait position).

Does anyone know of any libraries or examples of how to calculate positions for this? My math isn’t brilliant in this kind of stuff!

Thanks__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com

A simple solution would be to just switch the X and Y coordinates of everything you draw. This might be a bit overly simplistic, depending on what you have in mind, though…

At first gloss this would seem a bit too simplistic. No matter whether you rotate the monitor to the left or right, the origin is in the wrong place. If you rotate clockwise the Y values would have to be the inverse (Y2 = pixelwidth - y1) and if you rotate counter-clockwise the X co-ordinates would suffer a similar translation.

Lilith>>> On 1/5/2008 at 1:03 PM, Mason Wheeler wrote:

A simple solution would be to just switch the X and Y coordinates of
everything you draw. This might be a bit overly simplistic, depending on
what you have in mind, though…

Yes, especially when you have graphics created for a landscape orientation!> ----- Original Message -----

From: lilith@dcccd.edu (Lilith Calbridge)
To: SDL at lists.libsdl.org
Sent: Saturday, 5 January, 2008 8:07:32 PM
Subject: Re: [SDL] Screen rotation

At first gloss this would seem a bit too simplistic. No matter whether
you rotate the monitor to the left or right, the origin is in the
wrong place. If you rotate clockwise the Y values would have to be the
inverse (Y2 = pixelwidth - y1) and if you rotate counter-clockwise the X
co-ordinates would suffer a similar translation.

Lilith

On 1/5/2008 at 1:03 PM, Mason Wheeler wrote:
A simple solution would be to just switch the X and Y coordinates of
everything you draw. This might be a bit overly simplistic,
depending on
what you have in mind, though…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

  __________________________________________________________

Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com

Well, that would be a problem - but rotating everything 90? at load
time, or doing it with some external tool, should be trivial. Check
out SGE, SDL_gfx and the like, or if you’re doing custom load time
processing anyway, just roll your own.

As for the game code, you don’t really have to do anything. Nothing
says origin must be in the top left corner - and in fact, several
graphics APIs and some image file formats put it in the bottom left
corner instead. (Having Y increase downwards is just a computer
thing, probably originating from the most common way of refreshing
CRTs.) Most of us are used to top left origo systems, but other than
that, any orientation works just fine.

Now, if you’re porting a working game that’s built for a different
orientation, or if you just can’t be arsed to think in a different
coordinate system, just throw in a thin layer over the SDL API or
something.

The “transform” for absolute coordinates:

display_x = y;
display_y = display_height - x;

Note that you’ll need to “flip” rects when dealing with SDL, as you
can’t use negative rect sizes; that is:

rect.x = y;
rect.w = h;
rect.y = (display_height - x) + w;
rect.h = w;

For blitting full surfaces (sprites) to the screen, only .x and .y are
considered, but you still need to deal with the sprite size, so:

rect.x = y;
rect.y = (display_height - x) + sprite.h;

…and of course, as I first pointed out, you’ll need to (pre-)rotate
all graphics one way or another for this to work.

(No formulae verified or anything, but they’re simple enough that I
might actually have managed to get them right. :wink:

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 05 January 2008, Edward Byard wrote:

Yes, especially when you have graphics created for a landscape
orientation!