为什么我仍然使用以下使用四元数的代码在THREE.js中获得万向节锁定?

时间:2017-05-04 05:41:29

标签: three.js rotation quaternions

我正试图让相机围绕世界空间的任意轴进行轨道运动。我已经花了这么多时间试图解决这个问题而没有运气。我不想添加像THREE.OrbitControls这样的库来拥有这个功能。谁能告诉我在下面的代码中我做错了什么?

Camera.prototype.orbit = function(axis, spd, pt) {
    var axis = axis.normalize(),
        currCamQuaternion = new THREE.Quaternion(this.position.x, this.position.y, this.position.z, 0),
        rotQuaternion = new THREE.Quaternion();

    rotQuaternion.setFromAxisAngle(axis, spd);
    var halfCamQuaternion = rotQuaternion.clone().multiply(currCamQuaternion),
        fullCamQuaternion = halfCamQuaternion.clone().multiply(rotQuaternion.clone().conjugate());

    this.position.copy(new THREE.Vector3(fullCamQuaternion.x, fullCamQuaternion.y, fullCamQuaternion.z));
    this.lookAt(pt);
}

0 个答案:

没有答案