Three.js - 算法来设置相机,使整个场景显示了? [英] Three.js - Algorithm to set the camera so the whole scene shows?
问题描述
当我安装我的场景,添加的几何形状等等,我怎么设置相机,所以我可以看到我的整个场景?我想要实现使用boundingboxes的算法,但我有点卡住了。
When I setup my scene, add geometries etc, how do I set the camera so I can see my whole scene? I'm trying to implement an algorithm using boundingboxes, but I'm kinda stuck.
推荐答案
您真的只需要使用找到所有的变量之间的最大绝对值Math.abs(数量)
,一旦找到了最伟大的,你可以设置相机的深度(position.z),以这个数字的。我做了一个简单的函数接收2号和返回是最大的。
You really only need to find the greatest absolute value between all your variables by using Math.abs(number)
, once you have found the greatest of all you can set the depth(position.z) of the camera to that number. I have made a simple function which receives 2 numbers and returns the greatest.
function findGreatestAbsolute( firstNumber, secondNumber ) {
if( Math.abs( firstNumber ) > Math.abs( secondNumber )) {
return Math.abs( firstNumber );
} else { return Math.abs( secondNumber ); }
}
您还可以使用数组,如果有太多的数字。 一旦你找到了你的号码,你做的:
You can also use Arrays if there are too many numbers. Once you have found your number you do:
camera = new THREE.PerspectiveCamera( cameraFov, windowHalfX / windowHalfY , 1, someDepth );
camera.position.z(greatestNumber);
或
camera.position.set(yourX, yourY, greatestNumber);
嗯,我希望它能帮助。
Well I hope it helps.
这篇关于Three.js - 算法来设置相机,使整个场景显示了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!