我有一个球位于摄像机前方,半径和距离都已知。如何调整摄像机的视场角(FOV),以在任意视口大小内完全适配摄像机和球?
这个回答类似,但我想调整视野而不是相机距离。
// to get the fov to fit the sphere into the camera
var vFOV = 2 * Math.asin(sphereRadius / distance);
// get the project's aspect ratio to calculate a horizontal fov
var aspect = this.width / this.height;
// more trig to calculate a horizontal fov, used to fit a sphere horizontally
var hFOV = 2 * Math.atan(Math.tan(vFOV / 2) / aspect);
fov * (180 / Math.PI)
,并应用于camera.fov
。