【问题标题】:Calculate camera zoom required for object to fit in screen height计算对象所需的相机缩放以适应屏幕高度
【发布时间】:2013-12-02 07:13:49
【问题描述】:

在 Three.js 中,我使用这个公式来计算可见宽度和高度

var vFOV = camera.fov * Math.PI / 180;        // convert vertical fov to radians
var height = 2 * Math.tan( vFOV / 2 ) * dist; // visible height

var aspect = window.width / window.height;
var width = height * aspect;                  // visible width

然后我计算出物体所需的相机变焦,以按宽度完全适合渲染区域

var zoom = (ObjectHeight/aspect) / (2*Math.tan(vFOV/2)) + ObjectDepth;

如何计算物体所需的相机缩放比例,以按高度完全适合渲染区域?

感谢 GuyGood,我找到了解决方案:

var zoom = (ObjectHeight/2) / Math.tan(vFOV/2) - ObjectDepth;

【问题讨论】:

  • stackoverflow.com/questions/15331358/… 的重复如果你知道dist,那么你求解vFov
  • 我知道 dist ,我知道 vFov。我需要变焦 (camera.position.z)
  • 我们怎样才能为正交相机做到这一点,因为它们没有 fov 参数。

标签: javascript 3d three.js


【解决方案1】:

我正在根据 boundingSphere 半径执行以下操作:

geometry.computeBoundingSphere();
radius = geometry.boundingSphere.radius;
distanceFactor = Math.abs( aspect * radius / Math.sin( fov/2 );

这是基于这里的东西,我希望我以正确的方式解释它: http://www.flipcode.com/forums/thread/4172

distanceFactor 是您需要沿其观察方向移动相机以使其正确适配的因素。目前我不确定它是高度还是宽度,但也许它可以帮助你弄清楚。 :)

【讨论】:

  • 我得到半径了吗?
  • 所有标准对象都有为它们计算的boundingSphere和boundingBox,如果没有,您可以调用geometry.computeBoundingBox/computeBoundingSphere btw。也许也可以在这里看到这个帖子:stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene
  • 如果正交相机没有 fov 参数,你会怎么做呢?
猜你喜欢
  • 2014-01-18
  • 1970-01-01
  • 2021-05-28
  • 2023-03-11
  • 2016-01-17
  • 2019-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多