Last visit was: It is currently Thu Mar 28, 2024 7:27 pm


All times are UTC-05:00




Post new topic Reply to topic  [10 posts ] 
    Author Message
     Post subject:SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sat May 17, 2008 10:40 am 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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.

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Last edited by adam_0 on Sat May 17, 2008 6:01 pm, edited 2 times in total.

    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sat May 17, 2008 5:45 pm 
    Literally Nine
    User avatar
     

    Joined:Sat Apr 02, 2005 3:31 pm
    Posts:1171
    Location:The vicinity of an area adjacent to a location.
    What event are you handling here? Mouse movement, I guess?

    _________________
    - Tycho

    Image


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sat May 17, 2008 5:59 pm 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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?

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sat May 17, 2008 6:00 pm 
    Literally Nine
    User avatar
     

    Joined:Sat Apr 02, 2005 3:31 pm
    Posts:1171
    Location:The vicinity of an area adjacent to a location.
    Should be.

    _________________
    - Tycho

    Image


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sat May 17, 2008 6:05 pm 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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.

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sun May 18, 2008 5:56 am 
    Connoisseur of the Godawful
    User avatar
     

    Joined:Tue Mar 01, 2005 9:00 am
    Posts:456
    ICQ:286315965
    Website:http://rabidtinker.mine.nu/
    Yahoo Messenger:alistair_lynn
    AOL:Agent_Vast@mac.com
    Location:127.0.0.1
    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.

    _________________
    Alastair Lynn / Alumnus / Onlink Team


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sun May 18, 2008 10:00 am 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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?

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sun May 18, 2008 3:46 pm 
    Connoisseur of the Godawful
    User avatar
     

    Joined:Tue Mar 01, 2005 9:00 am
    Posts:456
    ICQ:286315965
    Website:http://rabidtinker.mine.nu/
    Yahoo Messenger:alistair_lynn
    AOL:Agent_Vast@mac.com
    Location:127.0.0.1
    Probably you're not using an identity matrix :3

    _________________
    Alastair Lynn / Alumnus / Onlink Team


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sun May 18, 2008 4:39 pm 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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")

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Top
    Offline  
     Post subject:Re: SDL is being weird on me (SDL, OGL, C++)
    PostPosted:Sun May 18, 2008 6:07 pm 
    User avatar
     

    Joined:Sun May 11, 2008 8:40 pm
    Posts:33
    Website:http://adam-0.tripod.com/index.html
    Location:Karith Station
    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!

    _________________
    - adam_0
    StarCraft 2: Immortal
    "The Undeveloped Story" (my blog)


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 12 guests


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova