在使用 2d Canvas 时,如果您想检查某些内容是否不再“显示在屏幕上”,您只需执行以下操作:
if( pos.x > window.innerWidth || pos.x < 0 ||
pos.y > window.innerHeight || pos.y < 0 ) {
// has left the screen
}
我如何检查在 three.js 场景中是否仍有东西“在屏幕上”(在相机的视野中)?
最佳答案
您可以检查 3d 点是否在截锥体中,而不是检查 2d Canvas 。
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...
}
关于javascript - three.js - 检查对象是否仍在相机视野内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29758233/