假设我在以下位置放置了一个摄像头:
{
x: 10,
y: 30,
z: 20
}
它的旋转是:
{
x: 0.1,
y: 0.2,
z: 0.3
}
我想将相机从其当前位置朝它所面对的方向移动 1 个单位。
如何计算相机的新位置?
我正在使用 ThreeJS。
最佳答案
THREE.Camera
类扩展了 THREE.Object3D
类。
您可以使用 the getWorldDirection
method from the base class 获取相机方向:
It returns a vector representing the direction in which the camera is looking, in world space.
当您有了这个direction
向量时,您可以使用它来将相机移动到所需的方向:
var direction = new THREE.Vector3();
camera.getWorldDirection( direction );
要在那个方向只移动 1,你可以简单地做:
camera.position.add( direction );
如果你想移动更多,你可以使用例如 the multiplyScalar
method from the THREE.Vector3
class并乘以所需的距离。
distance = 10;
camera.position.add( direction.multiplyScalar(distance) );
关于javascript - 使用 ThreeJS 将相机朝它所面对的方向移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38052621/