Created
July 8, 2013 20:16
-
-
Save coastwise/5952119 to your computer and use it in GitHub Desktop.
Revisions
-
coastwise created this gist
Jul 8, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ using UnityEngine; using System.Collections; /** * This class attempts to force VERT- Field of view scaling. * By default, Unity uses the HOR+ technique. * * http://en.wikipedia.org/wiki/Field_of_view_in_video_games#Scaling_methods */ [ExecuteInEditMode] [RequireComponent (typeof(Camera))] public class VertMinusCameraFOV : MonoBehaviour { public float designTimeVerticalFieldOfView = 60; public int designTimeWidth = 1280; public int designTimeHeight = 720; private float hFOVInRads; private int prevWidth; private int prevHeight; void Start () { prevWidth = designTimeWidth; prevHeight = designTimeHeight; float aspectRatio = (float) designTimeWidth / (float) designTimeHeight; float vFOVInRads = designTimeVerticalFieldOfView * Mathf.Deg2Rad; hFOVInRads = 2f * Mathf.Atan( Mathf.Tan(vFOVInRads/2f) * aspectRatio); } void Update () { if (Screen.width != prevWidth || Screen.height != prevHeight) { float aspectRatio = (float) Screen.width / (float) Screen.height; float vFOVInRads = 2f * Mathf.Atan( Mathf.Tan(hFOVInRads/2f) / aspectRatio ); Debug.Log("Screen resolution change. Recomputing aspect ratio (" + aspectRatio + ") and field of view (" + vFOVInRads*Mathf.Rad2Deg + ")"); foreach (Camera cam in GameObject.FindObjectsOfType(typeof(Camera))) { cam.fieldOfView = vFOVInRads * Mathf.Rad2Deg; } } } }