three.js 设置和读取相机外观矢量 [英] three.js set and read camera look vector
问题描述
而不是使用 camera.rotation 或使用 lookAt() 函数旋转相机我想直接给相机传一个look vector... 是否可以直接设置camera look vector,是否可以从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?
推荐答案
相机没有look vector",所以无法设置.
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).
相机正在向下看它的内部负 z 轴,所以创建一个指向负 z 轴的向量:
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
three.js r.73
这篇关于three.js 设置和读取相机外观矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!