View Full Version : How to calculate optimal distance for camera?

Robbo

05-14-2002, 03:48 AM

(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?

Thanks for any help you may be able to give.

no luck in beginners

Come on, 30 minutes without an answer and you come to the conclusion that noone can answer your question?

Robbo

05-14-2002, 04:50 AM

Sorry - just impatient I guess http://www.opengl.org/discussion_boards/ubb/wink.gif

LordKronos

05-14-2002, 05:18 AM

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)

Robbo

05-14-2002, 05:32 AM

Thanks. Explaination-wise, I am sure it involves some simple trigonometry http://www.opengl.org/discussion_boards/ubb/wink.gif

Robbo

05-14-2002, 07:02 AM

Originally posted by LordKronos:

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)

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?

LordKronos

05-14-2002, 08:32 AM

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).]

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.