# Problem with FOV that fits a volume

This topic is 1658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there!

I've a bounding sphere of say radius r. I want that this sphere occupies always more or less the same portion of space in the rendered image even if the camera change its position.  To do so I've thought of changing dynamically the FOV according to the movement of the camera. Note that the camera is "looking at" the centre of the sphere.

Armed with pen and paper and my old trigonometric knowledges I've come up with the formula

that was also confirmed after a bit of googling.  This value is fed to glm::perspective.

where the distance is obtained by

distance = glm::distance(SphereCentre, cameraPosition)

I've doublechecked the centroid position and radius in world space. (directly on the data I have, I do not perform any transformation on my mesh)

My problem though is that what happens is not what I'm expecting, at all. First of all the portion of scene seen is much more than the wanted sphere, but also  if the distance become lower the "sphere" go farther away, like a zooming out effect. I would expect this if changing just the FOV, but shouldn't this be countered by the usage of the above formulas?

EDIT: If I remove the 2* in front of the previous formula (2*arctan... ) it is sort of ok-ish if not for a terrible distortion I have when the distance is very small. Why is so? (both, why the distortion and why without the 2* it is sort of ok, I'm quite certain of my calculations)

Edited by Mchart

##### Share on other sites

Depending on the way you calulate you perspective matrix fov/2 is the right value.

As for the distortion:

If the camera allways faces the center of the sphere buf the distance gets very small:

lim_(d->0) (FOV) = lim_(d->0) (2 * atan(r/d)) = PI

(or respectivly PI/2 when you re using fov/2) even PI/2 is a pretty large fov and a distortion is to be expected (youll find that an fov of PI/4 looks "normal").

On the contrary for d->inf : fov->0

Howerver I don't quite got the idea of what you are tying to achieve by this.

##### Share on other sites

Depending on the way you calulate you perspective matrix fov/2 is the right value.

As for the distortion:

If the camera allways faces the center of the sphere buf the distance gets very small:

lim_(d->0) (FOV) = lim_(d->0) (2 * atan(r/d)) = PI

(or respectivly PI/2 when you re using fov/2) even PI/2 is a pretty large fov and a distortion is to be expected (youll find that an fov of PI/4 looks "normal").

On the contrary for d->inf : fov->0

Howerver I don't quite got the idea of what you are tying to achieve by this.

First of all thanks for the reply! I'm using glm::perspective to build the matrix which I believe wants the full angle.

I want to make sure that a certain object is always in the frustum, even if the distance between camera/bounding sphere is very small.

(Also I found that for the way I compute the distance it should be asin(r/d), but still same distortion)

Edited by Mchart

##### Share on other sites

asin(r/d) yields the same problem, furthermore it is (mathmatically) defined only for the range [-1,1]. There should be an error thrown when you are calling asin() with a parameter out of range.

If you always want to have the whole object on the screen no matter how close it is to the camera, I think there is no way around that fisheye effect if scaling the object is not an alternative.

Practically speaking you cannot see the whole picture if your standing too close in front of it. And making the fov larger leads always to some unnatural distortion.

You can't make the fov arbitrarily large and still have a naturally looking projection.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 22
• 15
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634098
• Total Posts
3015518
×