three.js - 检查对象是否仍然在相机视野中 [英] three.js - check if object is still in view of the camera
本文介绍了three.js - 检查对象是否仍然在相机视野中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用2d画布时,如果你想检查某些内容是否不再在屏幕上,你只需执行以下操作:
When working with a 2d canvas, if you want to check if something is no longer "on screen" you simply do something like this:
if( pos.x > window.innerWidth || pos.x < 0 ||
pos.y > window.innerHeight || pos.y < 0 ) {
// has left the screen
}
我如何检查是否有什么东西是在一个three.js场景中仍然在屏幕上(在相机视图中)?
How would I check to see if something is still "on screen" ( in view of the camera ) in a three.js scene?
推荐答案
而不是检查2d画布,你可以检查3d点是否为平截头体。
Instead of check 2d canvas, you can check a 3d point is in frustum or not.
camera.updateMatrix();
camera.updateMatrixWorld();
var frustum = new THREE.Frustum();
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
// Your 3d point to check
var pos = new THREE.Vector3(x, y, z);
if (frustum.containsPoint(pos)) {
// Do something with the position...
}
这篇关于three.js - 检查对象是否仍然在相机视野中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文