【问题标题】:How can I move my camera sideways in ThreeJS如何在 ThreeJS 中将相机侧向移动
【发布时间】:2021-12-31 08:33:09
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: blender threejs-editor


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 2017-07-02
      • 2022-01-22
      • 2021-11-10
      • 2017-03-06
      • 2016-10-29
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多