Math 使用四元数的第一人称相机

Math 使用四元数的第一人称相机,math,3d,three.js,quaternions,Math,3d,Three.js,Quaternions,对于我在three.js中的第一人称相机,我需要将音高限制在[-PI/2;PI/2]范围内。 这与使用euler angles的threejs.org中的示例代码配合得很好,我重新编写了该示例代码以满足我的需要: this.pitchObj.rotation.x -= input.check("looky") * settings.mouse.sensitivityY; this.pitchObj.rotation.x = Math.clamp(this.pitchObj.rotation.x,

对于我在three.js中的第一人称相机,我需要将音高限制在[-PI/2;PI/2]范围内。 这与使用euler angles的threejs.org中的示例代码配合得很好,我重新编写了该示例代码以满足我的需要:

this.pitchObj.rotation.x -= input.check("looky") * settings.mouse.sensitivityY;
this.pitchObj.rotation.x = Math.clamp(this.pitchObj.rotation.x, -HALF_PI, HALF_PI);
然而,因为我改变了一些东西,我现在需要使用四元数版本。在这里,旋转就像一个符咒,但音调是不受限制的。那么,如何使用四元数旋转编写上述代码段呢

我的尝试:

this.pitchObj.rotateX(-this.input.check("looky") * settings.mouse.sensitivityY);
this.pitchObj.quaternion.x = Math.clamp(this.pitchObj.quaternion.x, -HALF_PI, HALF_PI);