【问题标题】:How can I keep the canvas in focus (center) of the camera when the screen size of the browser changes while using Babylonjs?当使用 Babylonjs 时浏​​览器的屏幕尺寸发生变化时,如何使画布保持在相机的焦点(中心)?
【发布时间】:2021-02-28 14:09:19
【问题描述】:

用户可以更改屏幕大小,这会扭曲我们创建的画布的大小,从而扭曲相机的图像焦点。为了解决这个问题,我们需要编写聚焦代码。

【问题讨论】:

    标签: javascript reactjs canvas size babylonjs


    【解决方案1】:
      relocateCamera_CanvasSize = () => {
            this.engine = this.scene.getEngine();
            this.engine.onResizeObservable.add(() => {
                if (this.scene.getEngine().getRenderHeight() > this.scene.getEngine().getRenderWidth()) {
                    camera.fovMode = Camera.FOVMODE_HORIZONTAL_FIXED;
                }
                else {
                    camera.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
                }
            });
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2012-01-27
      相关资源
      最近更新 更多