当我使用Perspective相机检查点是否在平截头体内时,它可以正常工作。但是,当我使用正交相机检查时,截头框看起来不准确。飞机设置正确。如果使用正交相机,还有其他我忽视的东西吗?
以下是我如何设置飞机..
if((this.mouse.screenx>mouse.screen.x && this.mouse.screeny<mouse.screen.y)||
(this.mouse.screenx<mouse.screen.x && this.mouse.screeny>mouse.screen.y)){
topPlane.setFromCoplanarPoints(camera.position, topRight, topLeft );
rightPlane.setFromCoplanarPoints(camera.position, bottomRight, topRight );
bottomPlane.setFromCoplanarPoints(camera.position, bottomLeft,bottomRight );
leftPlane.setFromCoplanarPoints(camera.position, topLeft, bottomLeft );
}else{
topPlane.setFromCoplanarPoints(camera.position, topLeft , topRight );
rightPlane.setFromCoplanarPoints(camera.position, topRight , bottomRight );
bottomPlane.setFromCoplanarPoints(camera.position,bottomRight , bottomLeft );
leftPlane.setFromCoplanarPoints(camera.position, bottomLeft , topLeft );
}
nearPlane.setFromNormalAndCoplanarPoint(vector,camera.position);
vector.set( 0, 0, 1 );
vector.applyQuaternion( camera.quaternion );
var vector2 = new THREE.Vector3( 0, 0, -config.camera.far );
vector2.applyQuaternion( camera.quaternion );
vector2.add(camera.position);
farPlane.setFromNormalAndCoplanarPoint(vector,vector2);
答案 0 :(得分:0)
好的,我想出了问题。 我正在创建我的飞机,以便它们从相机的位置延伸,然而,这会产生锥形的锥形。 在正交模式下,没有逐渐变细 - 一切都是直的,因此平截头体平面不应该从相机延伸。
我所做的是获得相机的方向:
var vector = new THREE.Vector3( 0, 0, -1 );
vector.applyQuaternion( camera.quaternion );
然后我用它来创建每个平面 - 例如:
var top = topRight.clone(), right = bottomRight.clone(), bottom = bottomLeft.clone(), left = topLeft.clone();
top.add(vector), right.add(vector), bottom.add(vector), left.add(vector);
topPlane.setFromCoplanarPoints(top, topLeft , topRight );
rightPlane.setFromCoplanarPoints(right, topRight , bottomRight );
bottomPlane.setFromCoplanarPoints(bottom,bottomRight , bottomLeft );
leftPlane.setFromCoplanarPoints(left, bottomLeft , topLeft );
我有它,所以平截头体可以倒置 - 所以一定要检查飞机是否朝向正确的方向。