【问题标题】:Camera configuration in ThreeJSThreeJS 中的相机配置
【发布时间】:2014-07-02 15:55:41
【问题描述】:

我是 ThreeJS 的新手,我正在尝试用它构建我的 Web 应用程序。我遇到了摄像头配置问题。

我有一个透视相机,它能够在我的场景的每个点上观察和移动。

问题是我只想让我的相机可以看到每个点(左、右、上和下)。但是,我不希望它可以在每一点移动(我的意思是移动和外观之间的区别,而不是相同的行为)。我希望它可以在 Z 轴(深度)上移动。

这里,我的相机:

this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

【问题讨论】:

    标签: javascript camera three.js


    【解决方案1】:

    我想这就是你需要的答案

    https://stackoverflow.com/a/15661803/507186

    camera.translateZ( - distance );
    

    它会在不改变 LookAt 位置的情况下翻译

    【讨论】:

      【解决方案2】:

      先简单解释一下摄像头的配置

      this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
      

      PerspectiveCamera( fov, aspect, near, far );

      • fov - 相机平截头体垂直视野。
      • aspect - 相机截锥体纵横比。(宽度/高度)
      • near - 平面附近的相机平截头体。
      • far — 相机截头远平面。

      这会配置相机,但不会控制其移动或看到的位置。

      要控制相机的视线,请使用以下代码:

      this.camera.lookAt(new THREE.Vector3(0,0,0)); // x, y, z
      

      但是如果你使用一些库来控制相机(OrbitControls.js),你可能不得不使用:

      this.controls.target.set( 0, 0, 0 ); //x, y, z
      

      如果您不使用任何库来控制相机,那么“lookAt()”应该没有问题。

      为了让摄像头保持在固定位置,请使用以下代码:

      this.camera.position.x      =   0;
      this.camera.position.z      =   0;
      this.camera.position.y      =   0;
      

      Ahora lo que realmente desea es administrar la profundidad de la cámara que tendra que utilizar el siguiente código:

      this.fov = 0;
      this.camera.projectionMatrix.makePerspective(this.fov,  window.innerWidth   /   window.innerHeight, this.near,  this.far));
      

      注意这一点,以免离开由远近所控制的视野。

      欲了解更多信息,请参阅threejs.org

      【讨论】:

        猜你喜欢
        • 2019-06-05
        • 2013-07-31
        • 2013-08-30
        • 1970-01-01
        • 2014-04-08
        • 2020-08-04
        • 2015-09-20
        • 2018-08-30
        • 2017-03-06
        相关资源
        最近更新 更多