Pour régler le FOV pour adapter la sphère, je avais besoin d'utiliser les fonctions trigonométriques inverses pour calculer l'angle de la triangle formé de la distance à la sphère et le point le plus visible sur la sphère.
Image of the triangle that will give the correct angle
// 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);
Cela vous donnera la réponse en radians. Multipliez le hFOV ou le vFOV en degrés fov * (180/Math.PI)
et appliquez au camera.fov
. J'ai d'abord couru dans le piège d'utiliser le mauvais triangle. Comme this answer states « La sphère est coupée pour la même raison que si vous vous tenez près d'une grande sphère que vous ne pouvez pas voir son « pôle nord »
Dont le faire: Image of the wrong triangle for a cropped view