【问题标题】:Rotate camera around the scene围绕场景旋转相机
【发布时间】:2014-11-01 14:47:33
【问题描述】:

我想将我的相机围绕场景旋转 90 度。我尝试过使用

cosole.log(camera.position);

并将相机设置到我在日志中看到的所需位置,但这根本行不通。

这是相机的初始化方式(对于第一张图像):

var width  = window.innerWidth,
    height = window.innerHeight;
var camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.set(0, -22, 22);

这就是我所拥有的:

这就是我想要的(相机逆时针旋转 90 度):

编辑

我注意到我可以旋转对象本身(:这样做:

plane.rotation.z = 90 * Math.PI / 180;

但我还是很好奇如何通过旋转相机达到同样的效果。

【问题讨论】:

    标签: javascript camera three.js


    【解决方案1】:

    你必须将相机位置移动一圈,lookAt位置应该是物体或场景:

    var rotSpeed = .02 
    camera.position.x = x * Math.cos(rotSpeed) - z * Math.sin(rotSpeed);
    camera.position.z = z * Math.cos(rotSpeed) + x * Math.sin(rotSpeed);
    camera.lookAt(scene.position);
    

    顺时针方向,正负互换。

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 2016-11-23
      • 2016-09-22
      相关资源
      最近更新 更多