屏幕分辨率(camera.aspect)和camera fov关系如上图
怎么根据不同分辨率算出对应的fov来适配
假设距离为distance = 1000 默认fov = 35
知道距离和角度算默认屏幕高度
double Height = 2.0 * distance * Mathf.Tan(fov * 0.5f * Mathf.Deg2Rad);
这里算出对应的屏幕高度,以1920*1080分辨率为准,计算当前屏幕高度(aspect是camera.aspect)
float currentHeight = (float)Height * (1920f / 1080f) / aspect;
知道屏幕高度和距离计算对应的角度,就是fov
float CurrentFov = 2 * Mathf.Atan(currentHeight * 0.5f / distance ) * Mathf.Rad2Deg;
代码如下:
复制代码
1
2
3
4
5
6
7
8
9
10public static float CameraView(float aspect,float fov) { double frustumHeight = 2.0 * 1000 * Mathf.Tan(fov * 0.5f * Mathf.Deg2Rad); float CurrentFov = 2 * Mathf.Atan((float)frustumHeight * (1920f / 1080f) / aspect * 0.5f / 1000) * Mathf.Rad2Deg; if(CurrentFov > fov) { return CurrentFov; } return fov; }
最后
以上就是傻傻棉花糖最近收集整理的关于Unity 3d镜头适配,分辨率aspect和fov的关系的全部内容,更多相关Unity内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复