我正在尝试在 THREE.js 中实现类似于 FlyControls 的东西,但我无法终生弄清楚如何正确旋转相机的俯仰角:
http://radiantjs.herokuapp.com/
按 A 或 Z 键“向上看/向下看”。因为该演示中的初始位置已经在偏航轴上旋转,所以俯仰基本上看起来像滚动。
我更新相机位置和旋转的代码如下:
/**
* Updates this View. This is called once per frame.
*
* @param {Number} delta The length of the frame (16 / milliseconds).
*/
update: function(delta) {
if (this.velocity.length() < 0.15) {
this.velocity.clear()
} else {
this.velocity.multiplyScalar(0.85 * delta)
}
if (this.velocity.x || this.velocity.y || this.velocity.z) {
this.camera.position = this.camera.localToWorld(this.velocity.clone())
this.camera.position.clamp(-16384, 16384)
}
if (this.rotation.length() < 0.15) {
this.rotation.clear()
} else {
this.rotation.multiplyScalar(0.85 * delta)
}
if (this.rotation.x || this.rotation.y) {
var rotation = this.rotation.clone().multiplyScalar(Math.PI / 180)
this.camera.rotation.add(rotation)
}
}
完整的代码也可以在这里找到: https ://github.com/jdolan/radiantjs/blob/master/public/scripts/main/view.js#L291
非常感谢任何帮助!