• Unity3D 中的FOV


    一直以为Unity中的相机FOV指的是frustum两个对角边的方向夹角,所以在看一篇教程的时候怎么算都算不对。后来灵机一动,查了一下,才发现Unity中的Fov指的是垂直方向的FOV:

    参见这里:https://docs.unity3d.com/ScriptReference/Camera-fieldOfView.html

    This is the vertical field of view; horizontal FOV varies depending on the viewport's aspect ratio. 
    

      图示如下:

    图片来源:http://rungame.me/blog/2014/05/12/u3d-projection/

    附上我看的教程的部分代码,用于计算frustum的四个边:

    private Matrix4x4 GetFrustumCorners(Camera cam)
        {
            float camFov = cam.fieldOfView;
            float camAspect = cam.aspect;
    
            Matrix4x4 frustumCorners = Matrix4x4.identity;
    
            float fovWHalf = camFov * 0.5f;
    
            float tan_fov = Mathf.Tan(fovWHalf * Mathf.Deg2Rad);
    
            Vector3 toTop = Vector3.up * tan_fov;
            Vector3 toRight = Vector3.right * tan_fov * camAspect;
    
    
            Vector3 topLeft = (-Vector3.forward - toRight + toTop);
            Vector3 topRight = (-Vector3.forward + toRight + toTop);
            Vector3 bottomRight = (-Vector3.forward + toRight - toTop);
            Vector3 bottomLeft = (-Vector3.forward - toRight - toTop);
    
            frustumCorners.SetRow(0, topLeft);
            frustumCorners.SetRow(1, topRight);
            frustumCorners.SetRow(2, bottomRight);
            frustumCorners.SetRow(3, bottomLeft);
    
            return frustumCorners;
        }
  • 相关阅读:
    《我曾》火了:人这辈子,最怕突然听懂这首歌
    SpringMVC的运行流程
    Directive 自定义指令
    Vue 过滤器
    MVC 和 MVVM的区别
    vue指令
    async
    Generator
    单词搜索
    Promise
  • 原文地址:https://www.cnblogs.com/AnKen/p/8628615.html
Copyright © 2020-2023  润新知