当使用 Babylonjs 时浏​​览器的屏幕尺寸发生变化时,如何使 canvas 保持在相机的焦点(中心)?

How can I keep the canvas in focus (center) of the camera when the screen size of the browser changes while using Babylonjs?

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

  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;
            }
        });
    }