- Home /
Relationship between FOV and aspect ratio..
Hi there, I'm currently trying to make a panoramic camera capture script, in order to capture some really high res landscape aspect images, but I'm stuck at how the horizontal FOV is related to the game aspect ratio.
So, with a camera FOV of 90, and a 1:1 aspect ratio, I get a horizonal angle of 90 degrees, as can be seen in this image:
This is 8 cameras from above, FOV of 90, each rotated 45 degree each time.
However, if I set the game window to 500 x 1000, I'd expect that this would make the horizontal angle of the cameras to be 45 degrees, but the result is slightly larger:
What should the maths behind this be? Ideally what I need to do is work out the current horizontal field of view, from the camera's FOV and the game window aspect ratio, and then depending on the number of slices, I need to change the game window width to make the camera horizontal angle the correct amount.
So, for example, a 90 degree image with 2 slices, I need to change the game window so that the horizontal field of view ends up at 45, and then I can rotate the camera 22.5 degrees anti clockwise, take the first image, then rotate clockwise 45 degree and take the second image..
Bit stuck, thanks in advance..
Answer by Paulius-Liekis · Jan 28, 2015 at 09:04 PM
FOV is field-of-view angle, so it's not directly proportional to screen aspect ratio:
tan(FOV/2) = (screenSize/2) / screenPlaneDistance
You can make two equasions:
tan(FOV_H/2) = (screen_width/2) / screenPlaneDistance
tan(FOV_V/2) = (screen_height/2) / screenPlaneDistance
So:
tan(FOV_H/2) / screen_width = tan(FOV_V/2) / screen_height
You should be able to work out what you need from here.
Thanks, I'll have an investigate, but still a bit confused..
$$anonymous$$y assumption of screen ratio being related to the horiz FOV comes from the fact that if you half your game window, the vertical FOV stays the same, but now the width of the screen plane is halved. In my out-of practise math-brain this means that the horizontal FOV angle has halved - if you can explain why this is wrong I think I might be closer to getting it..
You need to catch up on your trigonometry;)
Let's say you have a screen size 1000x1000 and FOV=90 deg (both horizontal and vertical). Now let's double screen width to 2000x1000, do you want to say that horizontal FOV would become 180 deg? As you know 180 deg FOV is illogical. New FOV would be:
// calculate screenPlaneDistance from vertical FOV
screenPlaneDistance = (1000/2) / tan(90/2) = 500
// calcuate horizontal fov
tan(FOV_H/2) = (2000/2) / 500
FOV_H = atan((2000/2) / 500) * 2 = 126.869898 deg
Aha, yes!!! 90 degrees to 180 degrees was the best way of explaining it to me..
I didn't get a chance to experiment the other day, but I'm going to delve right in now and hopefully have some success.
Thanks!