如何在 ThreeJS 中横向移动相机

How can I move my camera sideways in ThreeJS

我想使用箭头键将相机横向移动。为此,我可以使用类似这样的东西来前进:

const facingDir = this.camera.getWorldDirection(new THREE.Vector3())

this.camera.position.addScaledVector(facingDir, 1)

如何计算横向移动的矢量?

我是这样工作的:

import * as THREE from 'three'

export default function calcOrthogonalVector(object: THREE.Object3D): THREE.Vector3 {
  // create default plane using normal vector
  const normalVector = new THREE.Vector3(0, 1, 0)
  const normalPlane = new THREE.Plane(normalVector, 0)

  // copy rotation of camera to plane
  normalPlane.normal.set(0, 1, 0).applyQuaternion(object.quaternion.clone())

  // get new normal vector
  const newNormalVector = normalPlane.normal

  // create new vector from cross product
  const crossVector = new THREE.Vector3()
  crossVector.crossVectors(newNormalVector, object.getWorldDirection(new THREE.Vector3()))

  return crossVector
}