(Apologies for the cross post - no luck in beginners…).

Hi,

How can I calculate the optimal distance from a object for the camera eye-point such that all of the object is visible on screen (assume that the camera is axis aligned and that I only care about the x width of the object to look at).

As a follow up, given a cylinder of radius R, how can I calculate the optimal camera distance such that the end section (circular) of the cylinder is completely visible on screen?

Well, since you are so darn impatient, I wont even waste you time with an explanation of the theory behind this (since it would take another 30 minutes).

for your camera, you should already know the field of view in both the x and y directions.
lest say
fovX = 1/2 of the x field of view angle
fovY = 1/2 of the y field of view angle
r = radius of circle you wish to fit within the display

Originally posted by LordKronos:
[b]Well, since you are so darn impatient, I wont even waste you time with an explanation of the theory behind this (since it would take another 30 minutes).

for your camera, you should already know the field of view in both the x and y directions.
lest say
fovX = 1/2 of the x field of view angle
fovY = 1/2 of the y field of view angle
r = radius of circle you wish to fit within the display

distX = r/tan(fovX)
distY = r/tan(fovY)

best fit camera distance = max(distX, distY)[/b]

Erm - ok, but what is fovY and fovX? I have a single FOV (around 60 deg) - is this the ratio of the FOV to the width and height of the window?

Originally posted by Robbo: Erm - ok, but what is fovY and fovX? I have a single FOV (around 60 deg) - is this the ratio of the FOV to the width and height of the window?

tan(fovX) = apectRatio * tan(fovY)

If you need to find the actual fovX, you can apply the inverse tangent to both side, but it isnt necessary for these calculations.

P.S. Forgot to mention, if you are calling gluPerspective (most likely you do) then fovY is the first param, and aspectRatio is the second param.

[This message has been edited by LordKronos (edited 05-14-2002).]