btj*_*kes 6 trigonometry perspectivecamera three.js
我有一个以相机前面为中心的球体,其半径和距相机的距离已知。如何调整相机的视野 (FOV),使相机与任意视口大小内的球体精确匹配?
这个答案是类似的,但我想调整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);
Run Code Online (Sandbox Code Playgroud)
这将以弧度给出答案。将 hFOV 或 vFOV 乘以度数fov * (180 / Math.PI)
并应用于camera.fov
。
我最初遇到了使用错误三角形的陷阱。正如这个答案所述 “球体被剪裁的原因相同,如果你站在一个大球体附近,你就看不到它的“北极”
归档时间: |
|
查看次数: |
1443 次 |
最近记录: |