Created
March 18, 2015 12:23
-
-
Save tronster/9a5637f47798b7f25a74 to your computer and use it in GitHub Desktop.
Unity3d Camera cage from camera to near plane in editor.
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
using UnityEngine; | |
using System.Collections; | |
// Camera cage from camera to near plane in editor. | |
public class DrawCameraViewFrustrum : MonoBehaviour | |
{ | |
public Color clr = new Color(0.1f, 0.14f, 0.8f, 0.5f); | |
public void OnDrawGizmos() | |
{ | |
Gizmos.color= clr; | |
float near = GetComponent<Camera>().nearClipPlane; | |
if ( GetComponent<Camera>().orthographic ) | |
{ | |
// Orthographic cage | |
Gizmos.DrawWireCube( | |
transform.position + new Vector3(0,0,near/2), | |
new Vector3( | |
(GetComponent<Camera>().orthographicSize*GetComponent<Camera>().aspect)*2, | |
GetComponent<Camera>().orthographicSize*2, | |
near)); | |
} | |
else | |
{ | |
// Perspective cage | |
float angleTan = Mathf.Tan( GetComponent<Camera>().fieldOfView ); | |
Gizmos.DrawWireCube( | |
transform.position + new Vector3(0,0,near/2), | |
new Vector3( | |
(angleTan * near * GetComponent<Camera>().aspect)/2 , | |
(angleTan * near)/2, | |
near)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment