Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js set and read camera look vector

Instead of rotating the camera with camera.rotation or with the lookAt() function I'd like to pass a look vector directly to the camera... Is it possible to set a camera look vector directly and is it possible to read the look vector from the camera?

like image 238
Dev Avatar asked Mar 29 '13 03:03

Dev


1 Answers

The camera does not have a "look vector", so you cannot set it.

You can, however, construct a point to look at by adding your look vector to the camera's position, and then calling

camera.lookAt( point );

Here is how to determine the direction in which the camera is looking, assuming the camera either has no parent (other than the scene).

The camera is looking down its internal negative z-axis, so create a vector pointing down the negative z-axis:

var vector = new THREE.Vector3( 0, 0, - 1 );

Now, apply the same rotation to the vector that is applied to the camera:

vector.applyQuaternion( camera.quaternion );

The resulting vector will be pointing in the direction that the camera is looking.

Alternatively, you can use the following method, which works even if the camera is a child of another object:

camera.getWorldDirection( dirVector );

three.js r.73

like image 184
WestLangley Avatar answered Sep 25 '22 06:09

WestLangley