Log in or register to post comments

Vertical FOV in Unity

May 27, 2013 - 8:53pm #4

In reply to this post:
https://developer.vuforia.com/forum/faq/technical-how-do-i-find-vertical-field-view

It does not explain how to do this in Unity. The FOV for the Unity camera is set by a Vuforia script by directly setting the projection matrix. Due to a bug/lack of feature in Unity, you can't extract the FOV from the Editor or from Camera.main.fieldOfView because these values will be wrong when the projection matrix is modified. 

So here is how to get the correct camera parameters, including the vertical FOV:

Matrix4x4 mat = Camera.main.projectionMatrix;

float a = mat[0];
float b = mat[5];
float c = mat[10];
float d = mat[14];

float aspect_ratio = b / a;

float k = (c - 1.0f) / (c + 1.0f);
float clip_min = (d * (1.0f - k)) / (2.0f * k);
float clip_max = k * clip_min;

float RAD2DEG = 180.0f / 3.14159265358979323846f;
float fov = RAD2DEG * (2.0f * (float)Math.Atan(1.0f / b));

Note: in order to get the math functions to work you need to add "using System;" to the start of your script.

Vertical FOV in Unity

May 28, 2013 - 1:22am #3

Thanks elecman for sharing this, very helpful complement to the other post you refer to.

 

Vertical FOV in Unity

July 8, 2013 - 1:05pm #2

Thank you elecman! This is exactly what I was looking for :) 

Vertical FOV in Unity

July 8, 2013 - 1:05pm #1

Thank you elecman! This is exactly what I was looking for :) 

Log in or register to post comments