PDA

View Full Version : gluPerspective and field of view



shosking
04-25-2002, 05:02 PM
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

04-25-2002, 06:31 PM
Hey man, post in the advanced board. This is for begginners.

Zuraffo
04-25-2002, 09:18 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif

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

shosking
04-25-2002, 09:50 PM
"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".

Zuraffo
04-26-2002, 02:07 AM
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".

Furrage
04-26-2002, 06:04 AM
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.

Furrage
04-26-2002, 06:13 AM
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.

Jambolo
04-26-2002, 09:43 AM
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).]

shosking
04-28-2002, 07:01 PM
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