【问题标题】:How can i make my camera rotation y in threejs equal to 360?如何使我的相机在threejs中的旋转y等于360?
【发布时间】:2020-07-05 01:23:03
【问题描述】:

我想对某个产品进行 360 度查看,所以我有一个 3d 对象,我想在适当的方向上以每次点击 45 度的方式围绕对象旋转我的相机,但我遇到了麻烦。

相机:

this.camera.rotation.y = 15 / 180 * Math.PI;
this.camera.position.x = 0;
this.camera.position.y = 500;
this.camera.position.z = 1200;
this.camera.lookAt(0, 0, 0);

按钮点击方法:

onRightClicked() {
    const newCamPosition = (this.camera.position.x + degToRad(45)) * 10;
    this.camera.position.x = newCamPosition;
    this.camera.position.y = 500;
    this.camera.position.z = 1200;
  }

  onLeftClicked() {
    const newCamPosition = (this.camera.position.x - 150);
    this.camera.position.x = newCamPosition;
    this.camera.position.y = 500;
    this.camera.position.z = 1200;
  }

一切正常,但我的摄像头每次点击时无法进入 45 度。我认为问题出在 camera.rotation.y 但我是threejs的初学者,我不知道发生了什么。

【问题讨论】:

  • 为什么你认为给空间单位增加度数会起作用?
  • 我是一个菜鸟,这是我第一次使用 webgl 的东西,对不起老兄。我只是想弄清楚如何实现这一目标,因为我尝试过的一切都失败了。

标签: javascript angular typescript three.js gltf


【解决方案1】:

.applyAxisAngle() 可能是这样的:

var axis = new THREE.Vector3(0, 1, 0);
var step = Math.PI * 0.25;

onRightClicked() {
  this.camera.position.applyAxisAngle(axis, step);
}

onLeftClicked() {
  this.camera.position.applyAxisAngle(axis, -step);
}

【讨论】:

  • @KeanuJooste 不客气。我很高兴,它有帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-29
  • 1970-01-01
  • 2019-06-29
  • 2018-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多