Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: CameraPitch: How to use it?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    CameraPitch: How to use it?

    Hello.
    I am trying to implent a simple camera in my project and I am having some problems with the code. Actually for quite a while now, so I am almost desperate for help.
    Thanks for the time.
    (Heading should be called Yaw I guessed)

    Code :
    gluLookAt(Camera.PosX, 
              Camera.PosY, 
              Camera.PosZ,    		     
              Camera.DirX, 
              Camera.DirY, 
              Camera.DirZ,
    	  0.0, 1.0, 0.0);
    //The above is in the Drawing code and not the problem actually
     
     
        DirX = PosX + HeadingSin;	
        DirZ = PosZ - HeadingCos;
    //Ok, that works fine.
     
    DirY = PosY + PitchSin;
    //That works semifine.
    The Pitch-part is the problem.
    When the value starts getting close 90
    the camera starts pointing downwards again.
    I know that makes sense and I tried lots of
    different approaches using PitchCos and so
    on... Sometimes the camera will just point
    in the reversed direction.
    I don't understand it.
    Should this not be working:
    DirY = PosY + PitchCos;
    DirZ = PosZ + PitchSin;
    ?
    I hope you have some advice. It is very appreciated.



    [This message has been edited by B_old (edited 10-16-2002).]
    I may not be good looking but I sure am dumb.

  2. #2

    Re: CameraPitch: How to use it?

    I think I had the same problem recently. Then I found out that it is quite important how you set the up-vector of the camera (the last 3 floats). That is the vector that goes perpendicular (more or less) to the upper part of the "camera". When the angle between the up-vector and the directional-vector became >=180 (or 0, I suppose), the camera would behave strangely.
    So, whenever I look more or less down the z- or x-axis, (0, 1, 0) is fine for the up-vector. But if I look down the Y-axis, I had to change the up-vector to (0, 0, -1). Now the camera top is pointing down the negative z-axis. I hope that helped.

    Dunken

    [This message has been edited by dunken69 (edited 10-16-2002).]

  3. #3

    Re: CameraPitch: How to use it?

    I think I had the same problem recently. Then I found out that it is quite important how you set the up-vector of the camera (the last 3 floats). That is the vector that goes perpendicular (more or less) to the upper part of the "camera". When the angle between the up-vector and the directional-vector became >=180 (or 0, I suppose), the camera would behave strangely.
    So, whenever I look more or less down the z- or x-axis (0, 1, 0) is fien for the up-vector. But if I look down the Y-axis, I had to change the up-vector to (0, 0, -1). Now the camera top is pointing down the negative z-axis. I hope that helped.

    Dunken

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2002
    Posts
    18

    Re: CameraPitch: How to use it?

    i think that gluLookAt is to generate the matrix indicating how the world projects in the camera!
    for example
    gluLookAt(
    GLdouble eyex,
    GLdouble eyey,
    GLdouble eyez,
    GLdouble centerx,
    GLdouble centery,
    GLdouble centerz,
    GLdouble upx,
    GLdouble upy,
    GLdouble upz
    ); according it we can get the camera's coordinates orientation in the world coordinate
    zaxis = normal(center - eye)
    xaxis = normal(cross(up, zaxis))
    yaxis = cross(zaxis, xaxis)
    then we can get the projection matrix from two coordinate

  5. #5
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: CameraPitch: How to use it?

    Dunken:
    So do you have some formula to calculate the approperiate occasion to change the last 3 values of the camera?
    I am really wondering why it is not working the way I think of it, though. Makes no sense to me.
    Thanks for the tip!

    Ignn:
    I now nothing about matrixes yet so honestly I don't understand what you are talking about. My approach is working perfectly as long I only 'turn' the camera.
    Looking up/down works to as long it's only about 80° from the orgin. Strange huh?
    Thank you for the reply.

    EDIT:
    I can disply the pitch correctly now.
    (thanks to Dunken!).
    BUT: I cannot turn it
    I guess I have to figure out a combination of the last 3 values to make it work.
    I hope I get it sometime, as all Camera-tutorials I looked at are way more complicated than mine approach. I mean I am that close. I hope I don't have to go for the complicated ones.
    Thanks for the help.

    [This message has been edited by B_old (edited 10-17-2002).]
    I may not be good looking but I sure am dumb.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •