【问题标题】:How to setup a camera that follows a circle path?如何设置遵循圆形路径的相机?
【发布时间】:2017-09-19 10:41:49
【问题描述】:

我正在尝试创建一个摄像头,该摄像头跟随在围绕球体的轨道上旋转的物体。但是每次相机到达轨道的极坐标时,方向都会改变。我只是根据必须跟随的对象设置相机的位置,然后调用lookAt

function render() {
    rotation += 0.002;

    // set the marker position
    pt = path.getPoint( t );

    // set the marker position
    marker.position.set( pt.x, pt.y, pt.z );
    marker.lookAt( new THREE.Vector3(0,0,0) );

    // rotate the mesh that illustrates the orbit
    mesh.rotation.y = rotation

    // set the camera position
    var cameraPt = cameraPath.getPoint( t );
    camera.position.set( cameraPt.x, cameraPt.y, cameraPt.z );
    camera.lookAt( marker.position );

    t = (t >= 1) ? 0 : t += 0.002;

    renderer.render( scene, camera );
}

这是一个完整的小提琴:http://jsfiddle.net/krw8nwLn/69/

我用第二个立方体创建了另一个小提琴,代表所需的相机行为:http://jsfiddle.net/krw8nwLn/70/

【问题讨论】:

  • 你的两个链接指向同一个url
  • 哦,对不起!我已经更新了问题:)

标签: three.js


【解决方案1】:

发生的情况是相机的lookAt 函数将始终尝试将相机与水平面对齐(因此“向上”方向始终为(0,1,0)。当您到达顶部和底部时椭圆路径后,相机将立即旋转 180°,因此向上仍然向上。您还可以在“所需行为”示例中看到这一点,因为相机立方体旋转以便显示另一侧的颜色。

解决方案是在这种情况下不使用lookAt,因为它不支持像这样翻转的相机。而是直接设置相机的rotation 向量。 (这需要一些数学知识,但你看起来像个数学家。)

【讨论】:

  • 那太好了,令人难以置信... :-) 但是感谢您为我指明了正确的方向,我要测试一些东西!
猜你喜欢
  • 1970-01-01
  • 2017-03-12
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
  • 2021-05-27
  • 2019-03-22
相关资源
最近更新 更多