unity 获取水平FOV


  unity中Camera的Field of View是指的垂直FOV,水平FOV可以经过计算得到。

创建脚本如下,把脚本挂载到摄像机上即可得到水平FOV:

public class GetHorizontalFov : MonoBehaviour {

  Camera myCamera;
  float distance = 10 - 0.015f;
  void Start () {
    myCamera = gameObject.GetComponent<Camera>();
    float cameraHeight = 2.0f * distance * Mathf.Tan(myCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);//视锥体高度
    var cameraWidth = cameraHeight * myCamera.aspect;//视锥体宽度
    var horizontalfov = 2 * Mathf.Atan(cameraWidth * 0.5f / distance) * Mathf.Rad2Deg;//水平FOV
    Debug.LogError("horizontalfov: " + horizontalfov);
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM