Last active
December 27, 2015 16:09
-
-
Save naruse/7352864 to your computer and use it in GitHub Desktop.
Want to adjust a Quad / Plane to the size of what the camera renders for playing a video ? heres how you doit
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 characters
//Adjust the size of the transform to ocuppy the whole size of the camera being rendered | |
void Start () { | |
float distance = Vector3.Distance(Camera.main.transform.position, transform.position); | |
float sizeHeight = Mathf.Tan(Mathf.Deg2Rad * Camera.main.fieldOfView/2) * distance; | |
float radAngle = Camera.main.fieldOfView * Mathf.Deg2Rad; | |
float radHFOV = 2 * Mathf.Atan(Mathf.Tan(radAngle / 2) * Camera.main.aspect); | |
float hFOV = Mathf.Rad2Deg * radHFOV; | |
float sizeWidth = Mathf.Tan(Mathf.Deg2Rad * hFOV/2) * distance; | |
transform.localScale = new Vector3(sizeWidth*2, sizeHeight*2, 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment