Unity3D中的FOV
⼀直以为Unity中的相机FOV指的是frustum两个对⾓边的⽅向夹⾓,所以在看⼀篇教程的时候怎么算都算不对。后来灵机⼀动,查了⼀下,才发现Unity中的Fov指的是垂直⽅向的FOV:
This is the vertical field of view; horizontal FOV varies depending on the viewport's aspect ratio.
图⽰如下:
附上我看的教程的部分代码,⽤于计算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);
unity 教程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;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论