I'm looking to translate the camera along its lookAt vector. Once I have this vector, I can do scalar translation along it, use that point to move the camera position in global coordinates and re-render. The trick is getting the arbitrary lookAt vector? I've looked at several other questions and solutions but they don't seem to work for me.
Asked
Active
Viewed 1.6k times
10
-
1See http://stackoverflow.com/questions/15696963/three-js-set-and-read-camera-look-vector/. Also, is `camera.translateZ( -1 )` what you mean? – WestLangley May 13 '14 at 23:52
2 Answers
11
You can't get the lookAtVector
from the camera itself, you can however create a new vector and apply the camera rotation to that.
var lookAtVector = new THREE.Vector3(0,0, -1);
lookAtVector.applyQuaternion(camera.quaternion);

Kevin Kuyl
- 1,215
- 1
- 17
- 31
-
This answer is not correct. See http://stackoverflow.com/questions/15696963/three-js-set-and-read-camera-look-vector/15697227#15697227 – WestLangley Jul 20 '14 at 17:49
-
7
-
1The difference was the negative lookup vector, the answer has been edited. – Sjeiti Oct 09 '18 at 18:22
1
The first choice should be cam.translateZ();
There is a second option as well. 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]);

Isolin
- 845
- 7
- 20