Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem with FOV that fits a volume


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Mchart   Members   -  Reputation: 130

Like
0Likes
Like

Posted 06 July 2014 - 01:37 PM

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

 

 FOV = 2 * arctan(radius/distance) 

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, 06 July 2014 - 01:55 PM.


Sponsor:

#2 Wh0p   Members   -  Reputation: 340

Like
0Likes
Like

Posted 07 July 2014 - 04:15 AM

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.



#3 Mchart   Members   -  Reputation: 130

Like
0Likes
Like

Posted 07 July 2014 - 04:43 AM

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, 07 July 2014 - 04:46 AM.


#4 Wh0p   Members   -  Reputation: 340

Like
0Likes
Like

Posted 07 July 2014 - 08:56 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS