在 Three.js 中沿其 LookAt 轴移动相机? [英] Move the camera along its LookAt axis in Three.js?
问题描述
我是 Three.js 的新手,所以如果这很明显,那么请提前道歉.
I'm new to Three.js, so if this is obvious then apologies upfront.
我使用 LookAt 方法设置了我的相机,并希望在按下键盘上的某个键时沿着该向量移动.
I set my camera using the LookAt method, and would like to move along that vector when pressing a key on the keyboard.
我尝试通过从我通过 subVector
观察的点减去相机矢量来模仿该特征,对结果矢量进行归一化,然后按照以下方式进行操作:
I've tried mimicking the feature by subtracting the camera vector from the point I'm looking at via subVector
, normalized the resulting vector, then did something along the lines of:
camera.position.x += lookAtVector.x
camera.position.y += lookAtVector.y
camera.position.z += lookAtVector.z
...但是当我这样做时,我似乎有点漂移并且没有朝着lookAt点移动.如何在three.js中沿着lookAt向量移动?
...but I appear to be drifting a bit and not moving toward the lookAt point when I do this. How can I move along a lookAt vector in three.js?
推荐答案
相机正俯视它的负 Z 轴,所以你想这样做:
The camera is looking down it's negative-Z axis, so you want to do this:
camera.translateZ( - distance );
three.js r.57
three.js r.57
这篇关于在 Three.js 中沿其 LookAt 轴移动相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!