计算目标四元数,而不会使用 lookAt 作弊



如何在不存储当前四元数并使用lookAt的情况下计算相机的目标四元数(稍后用于slerp(?

这给了我想要的结果(即四元数(:

// newTarget is Vector3
let fromQuaternion = (new THREE.Quaternion()).copy(this.camera.quaternion);
this.camera.lookAt(newTarget);
let toQuaternion = (new THREE.Quaternion()).copy(this.camera.quaternion);
this.camera.quaternion.set(fromQuaternion.x, fromQuaternion.y, fromQuaternion.z, fromQuaternion.w);

我试图通过以下方式避免上述情况,但它不起作用(获得更大的四元数(:

// currentTarget, newTarget are Vector3
var _c = (new THREE.Vector3()).copy(this.camera.position);
var _t0 = (new THREE.Vector3()).copy(currentTarget).sub(_c).normalize();
var _t1 = (new THREE.Vector3()).copy(newTarget).sub(_c).normalize();
var toQuaternion = new THREE.Quaternion();
toQuaternion.setFromUnitVectors(_t1, _t0);

反转四元数的方向并将其初始化为当前相机可以:

    var _c = (new THREE.Vector3()).copy(this.camera.position);
    var _t0 = (new THREE.Vector3()).copy(currentTarget).sub(_c).normalize();
    var _t1 = (new THREE.Vector3()).copy(this.orbitControls.target).sub(_c).normalize();
    var toQuaternion = new THREE.Quaternion();
    toQuaternion.setFromUnitVectors(_t0, _t1);
    toQuaternion.multiply(this.camera.quaternion);

最新更新