0

我在三个 js 中有一个浮动飞机。它是双面的,我的相机围绕场景移动和旋转。我的问题是,考虑到飞机的位置和旋转以及相机的位置和旋转,我怎么知道我在看飞机的哪一侧?

我的旧解决方案是这个(检查相机到飞机前后的距离)但显然这不是最好的解决方案。

this.back.matrixWorldNeedsUpdate = true;
this.front.matrixWorldNeedsUpdate = true;

this.d1 = (new THREE.Vector3()).getPositionFromMatrix( this.back.matrixWorld ).distanceTo(cameraSystem.camera.position);
this.d2 = (new THREE.Vector3()).getPositionFromMatrix( this.front.matrixWorld ).distanceTo(cameraSystem.camera.position);

if((this.d1 - this.d2) < 0)'Facing the back Side'
else 'Facing the front Side'

谢谢!

4

1 回答 1

2

太好了,感谢 George 和three.js 设置并读取相机外观矢量,此代码有效

var planeVector = (new THREE.Vector3( 0, 0, 1 )).applyQuaternion(planeMesh.quaternion);
var cameraVector = (new THREE.Vector3( 0, 0, -1 )).applyQuaternion(camera.quaternion );

if(planeVector.angleTo(cameraVector)>Math.PI/2) 'facing front'
else 'facing back'
于 2013-08-05T14:09:34.070 回答