如何在三个js中计算透视相机的fov? [英] How to calculate fov for the Perspective camera in three js?
问题描述
我想将 CubeGeometry
触摸设置为画布,我使用了这个 fov
Formula 但它没有成功.这个 CubeGeometry
即将脱离画布.
I want to set CubeGeometry
touch to the canvas and I used this fov
Formula but it didn't work out. This CubeGeometry
is going out of canvas.
var height = 500;
var distance = 1000;
var fov = 2 * Math.atan((height) / (2 * distance)) * (180 / Math.PI);
itsLeftCamera = new THREE.PerspectiveCamera(fov , 400 / 500, 1.0, 1000);
如果我计算错了,请指导我如何克服这个问题?并且我想以通用方式设置它,以便在透视相机的任何位置,此几何图形将完美地贴合我的画布,并且此几何图形应位于画布的中心.
If I am calculating wrong so, please guide me how to overcome this problem? and I want to set this in generalize way so at any position of Perspective camera, this geometry would perfectly touch to my canvas and this geometry should be in center of the canvas.
推荐答案
IMO 你应该在 fov 计算器中计算对角线而不是高度,因为在计算高度时,你专注于高度,从而切断宽度大于高度的部分....当你做对角线时,你的相机会聚焦在整个矩形上......所以代码imo应该是
IMO you should calculate for the diagonal instead of the height in the fov calculator because when doing for height you focus on height thereby cutting off width portion greater than height.... When you do for diagonal your camera focus on the entire rectangle...so code imo should be
var height = 500;
var width = 400
var distance = 1000;
var diag = Math.sqrt((height*height)+(width*width))
var fov = 2 * Math.atan((diag) / (2 * distance)) * (180 / Math.PI);
itsLeftCamera = new THREE.PerspectiveCamera(fov , width / height, 0.1, distance);
这篇关于如何在三个js中计算透视相机的fov?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!