Advertisement
Guest User

Untitled

a guest
May 27th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // Copyright 2015 Nicholas Costello <NicholasJCostello@gmail.com>
  2.  
  3. using UnityEngine;
  4.  
  5. namespace Assets.Scripts.Extensions
  6. {
  7. /// <summary>
  8. /// Camera frustum extensions
  9. /// </summary>
  10. public static class CameraFrustumExtensions
  11. {
  12. /// <summary>
  13. /// Returns the frustum's height at the given distance from the camera.
  14. /// This returns the entire height from top to bottom, so if your camera is at 0,0
  15. /// the frustums top is at: Frustrumheight/2 and bottom is at: -Frustrumheight/2
  16. /// </summary>
  17. /// <param name="camera"></param>
  18. /// <param name="distance"></param>
  19. /// <returns></returns>
  20. public static float FrustumHeightAtDistace(this Camera camera, float distance)
  21. {
  22. return 2.0f * distance * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
  23. }
  24.  
  25. /// <summary>
  26. /// Returns the distance from camera a given frustrum height can be found
  27. /// </summary>
  28. /// <param name="camera"></param>
  29. /// <param name="frustumHeight"></param>
  30. /// <returns></returns>
  31. public static float DistanceAtFrustumHeight(this Camera camera, float frustumHeight)
  32. {
  33. return frustumHeight*0.5f/Mathf.Tan(camera.fieldOfView*0.5f*Mathf.Deg2Rad);
  34. }
  35.  
  36. /// <summary>
  37. /// Returns the frustum's width at a given distance from the camera.
  38. /// </summary>
  39. /// <param name="camera"></param>
  40. /// <param name="frustumHeight"></param>
  41. /// <returns></returns>
  42. public static float FrustumWidthAtFrustumHeight(this Camera camera, float frustumHeight)
  43. {
  44. return frustumHeight*camera.aspect;
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement