【问题标题】:Apply camera position and rotation with three.js使用 three.js 应用相机位置和旋转
【发布时间】:2018-09-15 20:24:57
【问题描述】:

在一个场景中,我正在查看一个带有PerspectiveCamera 的对象。 使用OrbitControls,我可以在对象周围移动、旋转、平移等。

我想要做的是将对象以一定角度移动到某个位置,然后获取相机位置和旋转。我稍后会用这些值更新相机。问题是three.js 没有应用其中一些值。这是我正在做的获取相机位置、旋转和lookAt向量的方法

console.log("Position", camera.position)
console.log("Rotation", camera.rotation)
console.log("World Direction", camera.getWorldDirection())

一旦我得到向量,把它们写下来并像这样应用它们:

camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
camera.rotation.set(-3.14, -0.44, -3.14);
camera.position.set(-1067.29, 34.23, 205.82);
camera.lookAt(0.43, -7.10, 0.90)

但问题是,如果我将 pan 与 OrbitControls 一起使用,则旋转和位置会更改为其他值

【问题讨论】:

    标签: javascript three.js camera rotation


    【解决方案1】:

    在 Orbitcontrols 上,您需要在更改相机变换后调用“controls.update()”。

    参见OrbitControlDokumentation上的代码示例

    更新: 注意:orbitcontrols seem to overwrite camera transforms

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2012-06-02
      • 2021-08-23
      • 2013-07-15
      相关资源
      最近更新 更多