Skip to content

Instantly share code, notes, and snippets.

@naruse
Last active December 27, 2015 16:09
Show Gist options
  • Save naruse/7352864 to your computer and use it in GitHub Desktop.
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
//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