浏览代码

Added onWindowResize callback

WestLangley 5 年之前
父节点
当前提交
74790fb58e
共有 2 个文件被更改,包括 35 次插入1 次删除
  1. 21 1
      examples/css3d_orthographic.html
  2. 14 0
      examples/css3d_sandbox.html

+ 21 - 1
examples/css3d_orthographic.html

@@ -31,12 +31,13 @@
 
 
 			var scene2, renderer2;
 			var scene2, renderer2;
 
 
+			var frustumSize = 500;
+
 			init();
 			init();
 			animate();
 			animate();
 
 
 			function init() {
 			function init() {
 
 
-				var frustumSize = 500;
 				var aspect = window.innerWidth / window.innerHeight;
 				var aspect = window.innerWidth / window.innerHeight;
 				camera = new THREE.OrthographicCamera( frustumSize * aspect / - 2, frustumSize * aspect / 2, frustumSize / 2, frustumSize / - 2, 1, 1000 );
 				camera = new THREE.OrthographicCamera( frustumSize * aspect / - 2, frustumSize * aspect / 2, frustumSize / 2, frustumSize / - 2, 1, 1000 );
 
 
@@ -116,6 +117,25 @@
 
 
 				}
 				}
 
 
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				var aspect = window.innerWidth / window.innerHeight;
+
+				camera.left = - frustumSize * aspect / 2;
+				camera.right = frustumSize * aspect / 2;
+				camera.top = frustumSize / 2;
+				camera.bottom = - frustumSize / 2;
+
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				renderer2.setSize( window.innerWidth, window.innerHeight );
+
 			}
 			}
 
 
 			function animate() {
 			function animate() {

+ 14 - 0
examples/css3d_sandbox.html

@@ -89,6 +89,20 @@
 
 
 				controls = new TrackballControls( camera, renderer2.domElement );
 				controls = new TrackballControls( camera, renderer2.domElement );
 
 
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+				renderer2.setSize( window.innerWidth, window.innerHeight );
+
 			}
 			}
 
 
 			function animate() {
 			function animate() {