Hey all. I need to set the camera’s FOV to a certain value, but that value is given to me as the ‘diagonal FOV’. And Unity’s cameras FOV is ‘vertical FOV’. So I need to do this conversion. I realize it means using the aspect ratio, right? or somehow getting the view frustum?
Does anyone know the formula for this?
I believe this should work, its just some trigonometry:
var diagonalFOV : float = 100;
private var camAspect : float;
private var diagonalRatio : float;
private var verticalFOV : float;
function Start () {
camAspect = camera.aspect;
diagonalRatio = Mathf.Sqrt(1 + Mathf.Pow(camAspect, 2));
verticalFOV = (Mathf.Atan(Mathf.Tan(diagonalFOV*(Mathf.Deg2Rad/2.0))/diagonalRatio))*Mathf.Rad2Deg*2;
camera.fieldOfView = verticalFOV;
}
I have tested this so it doesn’t give errors though I’m unable to test if it is the correct output angle, so hopefully my maths is correct!
Scribe