looking and moving up and down(pitch) using glRotate()

This is a discussion on looking and moving up and down(pitch) using glRotate() within the Game Programming forums, part of the General Programming Boards category; I have a OpenGL program that is like a space simulator. I have the thing correctly turning and flying straight, ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    162

    looking and moving up and down(pitch) using glRotate()

    I have a OpenGL program that is like a space simulator. I have the thing correctly turning and flying straight, but things start to get difficult when I try to look up and down. To look up and down, or pitch, I have the program increase pitch by one is down and decrease if up, when the up or down key is pressed. Then, in the draw function, I have the glRotatef function rotate on the x axis up and down according to pitch. Like:
    Code:
    glRotatef(pitch,1.0f,0,0);
    And this works fine if I am facing along the x axis(0(360) or 180 degrees), but say I face 90 degrees on the z axis, the screen rotates around in a circle. I hope you follow me on this. I can't figure out how to fix this, so any suggestions would be great. Thanks!

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    if i get what your saying correctly, it's because at 90 degrees you should be rotating on the z axis to go up and down... the way you are attempting to do this is fairly complicated,
    you could try

    Code:
    void gluLookAt(
      GLdouble eyex,      
      GLdouble eyey,      
      GLdouble eyez,      
      GLdouble centerx,   
      GLdouble centery,   
      GLdouble centerz,   
      GLdouble upx,       
      GLdouble upy,       
      GLdouble upz        
    );
    
    eyex, eyey, eyez 
    The position of the eye point. 
    centerx, centery, centerz 
    The position of the reference point. 
    upx, upy, upz 
    The direction of the up vector.
    and/or look into vector math and trigonomotry...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    Ok, I looked up that function and it will work, but there is one thing I don't know about it, and that is the up vector. When I change the values it doesn't seem to have any effect. What does it do?

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    it specifies the up "Vector" technically its the up Axis

    so if you use (0.0,1.0,0.0) then positive y is up
    if you use (0.0,-1.0,0.0) negative y is up
    if you us (1.0,0.0,0.0) positive x is up

    get it?

    using decimal points wont really change anything...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21