5
These other answers are very insightful, but not completely correct. The code returns a vector that points in the same direction that the camera is pointing at. That's a great start!
这些其他的答案很有见地,但并不完全正确。代码返回一个指向摄像机指向的方向的向量。这是一个好的开始!
But unless the camera is at the origin (0, 0, 0) (or lies exactly on the line segment that connects the origin to the rotated vector point without passing beyond that point so that the point is behind the camera) the camera won't be looking at that point. Clearly -- just common sense -- the position of the camera also influences what points are being looked at. Just think about it!!
但是,除非相机在原点(0,0,0)(或者正好位于将原点与旋转矢量点相连的线段上,而不经过那个点,这样这个点就在相机后面),否则相机不会看到那个点。很明显,仅仅是常识,相机的位置也会影响到所观察到的点。想想吧! !
The camera method lookAt()
looks at a point in 3D space regardless of where the camera is. So to get a point that the camera is looking at you need to adjust for the camera position by calling:
camera方法lookAt()查看3D空间中的一个点,而不管摄像头在哪里。因此,要得到相机正在观察的点,你需要通过调用:
vec.add( camera.position );
矢量。添加(相机。位置);
It is also worth mentioning that the camera is looking not at a single point but is looking down a line of an infinite number of points, each at a different distance from the camera. The code from the other answers returns a vector that is exactly one unit in length because the application of a quaternion to the normalized z-axis vector (0, 0, -1) returns another normalized vector (in a different direction). To calculate the look at point at an arbitrary distance x
from the camera use:
值得一提的是,相机并不是盯着一个点,而是盯着一条无限多的点,每一个点与相机的距离都不同。来自其他答案的代码返回一个长度为一个单位的向量,因为四元数对归一化的z轴向量的应用(0,0,-1)返回另一个归一化的向量(在另一个方向上)。计算从相机使用的任意距离x的角度:
THREE.Vector3( 0, 0, -x ).applyQuaternion( camera.quaternion ).add( camera.position );
三。向量(0,0,-x)applyQuaternion(相机。四元数)。添加(相机。位置);
This takes a point along the z-axis at a distance x
from the origin, rotates it to the direction of the camera and then creates a "world point" by adding the camera's position. We want a "world point" (and not just a "relative to the camera point") since camera.lookAt()
also takes a "world point" as a parameter.
它沿着z轴取一个点,距离原点x,将它旋转到相机的方向,然后通过增加相机的位置来创建一个“世界点”。我们需要一个“world point”(而不仅仅是“相对于camera point”),因为camerat . lookat()也将“world point”作为参数。