2015-04-20 36 views
2

與2D畫布工作時,如果要檢查,如果事情不再是「上屏」你只需做這樣的事情:three.js所 - 檢查對象仍處於攝像機視

if(pos.x > window.innerWidth || pos.x < 0 || 
    pos.y > window.innerHeight || pos.y < 0) { 
    // has left the screen 
} 

如何檢查three.js場景中是否有「屏幕上」(在相機的視野中)?

+0

你可以只是否定條件,如果語句 - 'onScreen =!offScreen' – Conduit

+0

你不必做任何事情。 three.js爲你做。 – gaitat

回答

1

而不是檢查2d畫布,你可以檢查一個3d點是否是平截體。

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... 
}