我有三架j的浮动飞机。它是双面的,我的相机在场景中移动和旋转。我的问题是,考虑到飞机的位置和旋转以及摄像机的位置和旋转,我怎么能分辨出我正在看飞机的哪一侧?
我的旧解决方案就是这个(检查相机到飞机前后的距离),但显然这不是最佳解决方案。
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'
谢谢!
答案 0 :(得分:1)
太棒了,感谢George和three.js set and read camera look vector,这段代码可以运行
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'