THREE.js 检查对象是否为平截头体 [英] THREE.js check if object is in frustum
本文介绍了THREE.js 检查对象是否为平截头体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在修改three.js,我有一个画布,我想用作一种GUI.为此,我必须检查一个物体是否在相机视锥中.
i've been tinkering around with three.js and i have a canvas i'd like to use as kind of a GUI. for that i have to check if an object is in the camera frustum.
我当前的代码:
camera.updateMatrix();
camera.updateMatrixWorld();
var frustum = new THREE.Frustum();
var projScreenMatrix = new THREE.Matrix4();
projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromProjectionMatrix( camera.projectionMatrix );
if(frustum.containsPoint( mesh.position )){
//stuff happens...
};
frustum.containsPoint()
一直返回 false.我在这里做错了什么?
frustum.containsPoint()
keeps returning false. what am i doing wrong here?
推荐答案
您的代码正在使用
frustum.setFromMatrix( camera.projectionMatrix );
但这不是您想要的矩阵.而是使用:
But that isn't the matrix you want. Instead use:
frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ) );
如如何确定飞机在 Three.js 相机 Frustum 中
这篇关于THREE.js 检查对象是否为平截头体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文