浏览代码

fit to canvas

Gregg Tavares 7 年之前
父节点
当前提交
4b19370932
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      threejs/lessons/resources/threejs-primitives.js

+ 8 - 1
threejs/lessons/resources/threejs-primitives.js

@@ -543,7 +543,14 @@ function main() {
       const left   = rect.left * pixelRatio;
       const top    = rect.top * pixelRatio;
 
-      camera.aspect = width / height;
+      const aspect = width / height;
+      const targetFov = THREE.Math.degToRad(60);
+      const fov = aspect >= 1
+        ? targetFov
+        : (2 * Math.atan(Math.tan(targetFov * .5) / aspect));
+
+      camera.fov = THREE.Math.radToDeg(fov);
+      camera.aspect = aspect;
       camera.updateProjectionMatrix();
 
       renderer.setViewport(left, top, width, height);