How to tell if the camera is looking at the face o

2019-08-29 04:12发布

I have a floating plane in three js. It's double sided and my camera moves and rotates about the scene. My question is, given the position and rotation of the plane and position and rotation of the camera, how can I tell which side of the plane I am looking at?

My old solution is this (check the distance from camera to front and back of the plane) but obviously this isn't the best solution.

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'

Thanks!

标签: 3d three.js
1条回答
孤傲高冷的网名
2楼-- · 2019-08-29 04:37

Great, Thanks to George and three.js set and read camera look vector, this code works

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'
查看更多
登录 后发表回答