【发布时间】:2021-12-31 08:33:09
【问题描述】:
我想使用箭头键将相机横向移动。为此,我可以使用这样的东西来前进:
const facingDir = this.camera.getWorldDirection(new THREE.Vector3())
this.camera.position.addScaledVector(facingDir, 1)
如何计算横向移动的向量?
【问题讨论】:
我想使用箭头键将相机横向移动。为此,我可以使用这样的东西来前进:
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
}
【讨论】: