From 76b8f635cae8927a68717babf76ab218b46fe610 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Sat, 6 Jan 2018 12:14:46 -0800 Subject: [PATCH] viewport resize for the orthographic camera --- modules/scene/sceneSetup.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/scene/sceneSetup.js b/modules/scene/sceneSetup.js index 07f2284c..204d64f4 100644 --- a/modules/scene/sceneSetup.js +++ b/modules/scene/sceneSetup.js @@ -22,7 +22,11 @@ export default class SceneSetUp { createOrthographicCamera() { let width = this.container.clientWidth; let height = this.container.clientHeight; - this.oCamera = new THREE.OrthographicCamera( width / - 1, width / 1, height / 1, height / - 1, 0.1, 10000); + let factor = ORTHOGRAPHIC_CAMERA_FACTOR; + this.oCamera = new THREE.OrthographicCamera(-width / factor, + width / factor, + height / factor, + -height / factor, 0.1, 10000); this.oCamera.position.z = 1000; this.oCamera.position.x = -1000; this.oCamera.position.y = 300; @@ -52,13 +56,29 @@ export default class SceneSetUp { this.container.appendChild( this.renderer.domElement ); window.addEventListener( 'resize', () => { - this.pCamera.aspect = this.aspect(); - this.pCamera.updateProjectionMatrix(); + this.updatePerspectiveCameraViewport(); + this.updateOrthographicCameraViewport(); this.renderer.setSize( this.container.clientWidth, this.container.clientHeight ); this.render(); }, false ); } + updatePerspectiveCameraViewport() { + this.pCamera.aspect = this.aspect(); + this.pCamera.updateProjectionMatrix(); + } + + updateOrthographicCameraViewport() { + let width = this.container.clientWidth; + let height = this.container.clientHeight; + let factor = ORTHOGRAPHIC_CAMERA_FACTOR; + this.oCamera.left = - width / factor; + this.oCamera.right = width / factor; + this.oCamera.top = height / factor; + this.oCamera.bottom = - height / factor; + this.oCamera.updateProjectionMatrix(); + } + setCamera(camera) { let camPosition = new THREE.Vector3(); let camRotation = new THREE.Euler(); @@ -167,4 +187,6 @@ export default class SceneSetUp { domElement() { return this.renderer.domElement; } -} \ No newline at end of file +} + +const ORTHOGRAPHIC_CAMERA_FACTOR = 1; \ No newline at end of file