Results 1 to 9 of 9

Thread: gluPerspective and field of view

  1. #1
    shosking
    Guest

    gluPerspective and field of view

    Hi,
    I am simulating a basketball with x and y cordinates at zero, and it is translating directly towards the eye, along the -z axis (i.e., it does not follow a parabolic path).

    After each refresh, the basketball travels some distance along the z axis, depending on its speed. I want the basketball to be simulated at its actual visual angle for each distance on the z axis. So, if I am sitting at a fixed 60cm away from the screen, I want the basketball to be simulated at its correct visual angle.

    I've looked at the red-book, which does discuss this issue (p. 133-134), but I do not understand how calculating the visual angle of an object that I know the size of (e.g., the diameter of a basketball is 24cm), is translated to the angle variable in gluPerspective.


    Can anyone provide an explanation please or point me to a good reference for this topic?

    thanks in advance,
    Simon

  2. #2
    Guest

    Re: gluPerspective and field of view

    Hey man, post in the advanced board. This is for begginners.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    23

    Re: gluPerspective and field of view

    If I get your question correctly, you want the basketball to occupy the field of view completely at every frame, right?

    If so, you need to update your fov angle wrt to the distance bet. the ball and the camera.

    <- Diameter ->
    ------------- ^
    \ | / |
    \ | / |
    \ | / Distance
    \ | / |
    \ | / |
    \|/ v
    (Camera)

    So as the figure above shows, your fov should always be

    2 * atan( Diameter * 0.5 / Distance );


    Erm, aparently the ascii art screwed up. Use your imagination

    [This message has been edited by Zuraffo (edited 04-25-2002).]

  4. #4
    shosking
    Guest

    Re: gluPerspective and field of view

    "If I get your question correctly, you want the basketball to occupy the field of view completely at every frame, right?"

    no, i want the ball to occupy the correct visual angle for its instantaneous distance as it would occupy in the "real world".

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    23

    Re: gluPerspective and field of view

    Then you want to fix a fov and get the aspect ratio correct. Aspect ratio can be calculated by dividing your screen width by screen height. in pixels.

    I usually go with this:
    gluPerspective( 45.0, 800/600, near, far );

    Originally posted by shosking:

    "If I get your question correctly, you want the basketball to occupy the field of view completely at every frame, right?"

    no, i want the ball to occupy the correct visual angle for its instantaneous distance as it would occupy in the "real world".

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: gluPerspective and field of view

    Originally posted by bleh:
    Hey man, post in the advanced board. This is for begginners.
    Actually this is a beginners question. It seems complex because of the maths involved, but uses basic OpenGL in implementation. Advanced topics usually include multitexturing, extensions, ARBs and a whole slew of other stuff that I know nothing about. In short, things that deal with OpenGL complexity, and not just complexity in general programming or maths.

    Well that's just my opinion. The persons who use the advanced section regularly couldsay more on the subject.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: gluPerspective and field of view

    Originally posted by shosking:

    "If I get your question correctly, you want the basketball to occupy the field of view completely at every frame, right?"

    no, i want the ball to occupy the correct visual angle for its instantaneous distance as it would occupy in the "real world".
    In other words you want it like a camera at a fixed location filming the shot and you can see the ball arc through the air on it's way to the basket?

    If that is the case it's the maths you want. You'll have to assign the ball some attributes to record it's location and speed and calculate the effect of gravity on it's motion. You'll also have to know it's starting and endig position so that you can set a field of view that will capture its full range of motion.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Belmont, CA, USA
    Posts
    216

    Re: gluPerspective and field of view

    Code :
     
     
    double fov( double distance, double height )
    {
            return 2. * atan2( height * .5, distance ) * ( 360. / TWO_PI );
    }
    distance is the distance of your eye to the screen.
    height is the height of the window.

    My screen is about 25 cm tall, so my fov (at 60 cm) would be:

    fov( 60., 25. ) = 23.5 degrees


    [This message has been edited by Jambolo (edited 04-26-2002).]

  9. #9
    shosking
    Guest

    Re: gluPerspective and field of view

    thanks for all the helfull replies. i've got it all working now, including a parabolic path based on numerical intergration.l I was confusing world and sreen based coordinates. Now the whole display appears to be scaled 1:1 with "real objects"
    simon

Similar Threads

  1. Wrong field of view?
    By YuriRzhanov in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-18-2015, 08:09 AM
  2. Shadow Map field of view
    By mchartings in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 07-08-2014, 06:31 AM
  3. Field of view question
    By Stuart McDonald in forum OpenGL: General
    Replies: 1
    Last Post: 04-19-2007, 07:56 PM
  4. gluPerspective and field of view
    By shosking in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-28-2002, 08:03 PM
  5. glFrustum and field of view
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-22-2000, 07:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean