计算物体适合屏幕高度所需的相机缩放 [英] Calculate camera zoom required for object to fit in screen height
问题描述
在 Three.js 中,我使用这个公式来计算可见宽度 &高度
In Three.js I'm using this formulas to calculate visible width & height
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
然后我计算了对象所需的相机变焦,以使其完全适合渲染区域的宽度
And with that I calculate the camera zoom required for object to fit exactly into render area by WIDTH
var zoom = (ObjectHeight/aspect) / (2*Math.tan(vFOV/2)) + ObjectDepth;
我如何计算对象需要的相机变焦以完全符合 HEIGHT 的渲染区域?
How do I calculate the camera zoom required for object to fit exactly into render area by HEIGHT?
感谢 GuyGood,我找到了解决方案:
Thanks to GuyGood, I found the solution:
var zoom = (ObjectHeight/2) / Math.tan(vFOV/2) - ObjectDepth;
推荐答案
我正在执行以下基于 boundingSphere 半径的操作:
I am doing the following which is based on the boundingSphere radius:
geometry.computeBoundingSphere();
radius = geometry.boundingSphere.radius;
distanceFactor = Math.abs( aspect * radius / Math.sin( fov/2 );
这是基于这里的东西,我希望我能以正确的方式解释它:http://www.flipcode.com/forums/thread/4172
This is based on this stuff right here and I hope i interpreted it the right way: http://www.flipcode.com/forums/thread/4172
这个 distanceFactor
是你需要沿着它的观察方向移动相机以正确适应它的因素.目前我不确定它是按高度还是宽度,但也许它可以帮助您弄清楚.:)
This distanceFactor
is the factor you need to move the camera along its viewing direction to fit it correctly. At the moment i am not sure if it is by height or width but maybe it helps you figure it out. :)
这篇关于计算物体适合屏幕高度所需的相机缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!