Ferrous Moon
http://www.ferrousmoon.com:80/forums/

SDL is being weird on me (SDL, OGL, C++)
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1366
Page 1 of 1

Author:  adam_0 [Sat May 17, 2008 10:40 am ]
Post subject:  SDL is being weird on me (SDL, OGL, C++)

I've had these 10 lines of code bugging me for the longest time:
Code:
if (inverted_axes == false) { xrotcam = xrotcam + event.motion.yrel / 2.0f; yrotcam = yrotcam + event.motion.xrel / 2.0f; } else { xrotcam = xrotcam - event.motion.yrel / 2.0f; yrotcam = yrotcam + event.motion.xrel / 2.0f; } draw_arena();
(for clarification, xrotcam is the variable I use for rotating the camera along the x axis, same but different for yrotcam)

From looking at it, there's a few problems with it: xrotcam takes orders from event.motion.yrel, and vice versa. The second thing is that ~yrel freaks out when I hit buttons. After debugging and commenting out code, I found out that ~yrel stores the ASCII value of the button that I hit - escape stores 27 in ~yrel, "a" stores 97, etc. This then subtracts 97 degrees from xrotcam, making the screen flip out.

1. Is it something I'm doing, or is it SDL's fault?
1a. If it is SDL's fault, is there an easy way to go about fixing this?
1a1. If it's not easy to fix, should I abandon SDL and go for something else? If so, what do you recommend?

EDIT: Posted updated code.

Author:  Tycho [Sat May 17, 2008 5:45 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

What event are you handling here? Mouse movement, I guess?

Author:  adam_0 [Sat May 17, 2008 5:59 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Yes, and I just talked to Alastair, who helped me with the glitch problem. Now my only problem is that x is y and y is x. Aren't SDL x and y the same as OpenGL x and y?

Author:  Tycho [Sat May 17, 2008 6:00 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Should be.

Author:  adam_0 [Sat May 17, 2008 6:05 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Well, with the above code in place, this is the build:

http:/adam-0.tripod.com/quicksilver_app.zip (536k)

(hit green to go, wasd are strafing keys, x turns off the mouse, left arrow fullscreens, right arrow windows, mouse turns camera)

EDIT: I noticed that the "x" key moves the camera severely. Working on it... the output says that when I hit "x", the value for ~yrel becomes a big number (three outputs: 293, -91, 185) and the computer hesitates for around 400ms.

Author:  prophile [Sun May 18, 2008 5:56 am ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

WRONG. SDL and OpenGL x and y are not the same.

With a basic identity matrix applied, 0,0 is the centre of the screen in OpenGL, and the x axis goes from -1 (left) to 1 (right) and the y axis goes from -1 (bottom) to 1 (top).

In SDL, 0,0 is the top left corner, and x goes from 0 to the screen width in pixels right, and y increases as it goes DOWN to the screen height in pixels.

Author:  adam_0 [Sun May 18, 2008 10:00 am ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Quote:
WRONG. SDL and OpenGL x and y are not the same.

With a basic identity matrix applied, 0,0 is the centre of the screen in OpenGL, and the x axis goes from -1 (left) to 1 (right) and the y axis goes from -1 (bottom) to 1 (top).

In SDL, 0,0 is the top left corner, and x goes from 0 to the screen width in pixels right, and y increases as it goes DOWN to the screen height in pixels.
Well I knew that, but what I meant is that the x and y run the same way - y is the vertical component and x is the horizontal component, thus SDL y values should line up with OpenGL y values, same for x. So why does it not match up?

Author:  prophile [Sun May 18, 2008 3:46 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Probably you're not using an identity matrix :3

Author:  adam_0 [Sun May 18, 2008 4:39 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

Oh well, as you said one time prophile - if it ain't broke, don't fix it. :P

(side note: I just got your "location" - there's no place like "127.0.0.1")

Author:  adam_0 [Sun May 18, 2008 6:07 pm ]
Post subject:  Re: SDL is being weird on me (SDL, OGL, C++)

I asked for help on gamedev.net, and the guy explained it nicely: since I'm rotating in OpenGL and translating in SDL, the axes are switched. When you rotate around the x axis, the y values change, not the x values!

Thank you both for your help!

Page 1 of 1 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/