Archived

This topic is now archived and is closed to further replies.

Jehsup

perspective - X - FOV

Recommended Posts

Jehsup    298
Hello, Using gluLookAt, I know about the Y field of view, near\far clips, etc., but is the exact x field of view I end up with simply computed by multiplying my aspect ratio (1027 x 768 in this case) which gives a 1.3333 aspect ratio ( so this window is 1.3 times wider than high) by whatever angle I set as my vertical field of view to? In other words, say I have a 26 degree vertical field of view(for example). To get my visible x field of view do I simply multiply the 1.33333 aspect ratio from a 1024x768 window by 26 degrees to get 33.8 degrees (which represents my x field of view)? Or can xFOV be solved for by the simple ratio: 26(degrees yFOV)/768(pixels vertically) = w( degrees xFOV) / 1024(pixels horizontally) which would give me 34.67 degrees of x view. Thanks in advance for any help. J [edited by - Jehsup on January 23, 2004 4:17:42 PM]

Share this post


Link to post
Share on other sites
FReY    424
The aspect ratio is a measure of the screen width divided by the screen height so this won''t work for angles.

You''ll have to solve using:

xFOV = atan(tan(yFOV) / aspectratio)

I''ll derive it here if you need



(1) aspectratio = width / height (by defn)
(2) tan(yFOV) = height / dist (by defn)
(3) tan(xFOV) = width / dist (by defn)

By (1), height = width * aspectratio
By (2), height = tan(yFOV) * dist

(4) obtained by setting (1) == (2),
width * aspectratio = tan(yFOV) * dist;
and therefore
width = tan(yFOV) * dist / aspectratio;

By (3) and (4)
tan(xFOV) = (tan(yFOV) * dist / aspectratio) / dist
= (tan(yFOV) / aspectratio)
Therefore
xFOV = atan(tan(yFOV) / aspectratio)



Hope you understand.
FReY

Share this post


Link to post
Share on other sites
FReY    424
Eheh, he, silly me...

you can get the solution from the first 3 equations ... no need to go off on a tangent like I did..


(1) aspectratio = width / height (by defn)
(2) tan(yFOV) = height / dist (by defn)
(3) tan(xFOV) = width / dist (by defn)

aspectratio = tan(yFOV) * dist / tan(xFOV) * dist
= tan(yFOV) / tan(xFOV)



I feel silly.

Share this post


Link to post
Share on other sites
Trienco    2555
dist can be any distance between point of view and the plane. as you can see it will be removed from the equation anyway. i prefer to have things happening on a plane with dist("z") of 1, though it seems more common to think of everything being projected on the near plane.

anyway, assuming dist=1, then
height = 2*tan(fov/2);
width = 2*tan(xfov/2) = height*aspect;
tan(xfov/2)=tan(fov/2)*aspect;
xfov=2*atan(tan(fov/2)*aspect);

so now im only slightly confused. we end up with similiar results that still are a little exclusive.
one thing that always bothered me: why do i read tan(fov) everywhere and when using that it simply wont work (ie, drawing a rect at distance 1 with those dimensions wont fit). at the same, using 2*tan(fov/2) seems to work perfectly, the rect matches the viewport and using it for culling seems to give exact results.

Share this post


Link to post
Share on other sites
FReY    424
Jashup, Trienco is absolutely right on both fronts. It doesn''t matter what the ''dist'' is, although you can certainly calculate ''dist'' if you wanted.

Trienco you are absolutely right - you should be using the half-angle within the expressions above, this is because the above expressions are trigonometrically attained and it is defined on right-angle triangles only.

As a result, Trienco''s expression is more correct than mine :D

Share this post


Link to post
Share on other sites