Three.js Get Camera lookAt Vector

I want to translate the camera along my lookAt vector. As soon as I have this vector, I can perform a scalar translation along it, use this point to move the camera position in global coordinates and re-render. Trick gets arbitrary lookAt vector? I looked at several other issues and solutions, but they don't seem to work for me.

+6
source share
2 answers

You cannot get lookAtVector from the camera itself, however you can create a new vector and apply camera rotation to it.

 var lookAtVector = new THREE.Vector3(0,0, -1); lookAtVector.applyQuaternion(camera.quaternion); 
+6
source

The first choice should be cam.translateZ();

There is also a second option. You can extract the lookAt vector from the matrix property of the camera object. You just need to take the elements corresponding to the local z axis.

 var lookAtVector = new THREE.Vector3(cam.matrix[8], cam.matrix[9], cam.matrix[10]); 
0
source

All Articles