From 864168e9d2ade8bcff27f36120516fe070ab6a37 Mon Sep 17 00:00:00 2001 From: bwlewis Date: Wed, 31 Jan 2018 02:31:43 -0500 Subject: [PATCH] Improved fix for issue #72, better but still skewing perspective on resize Zoom should work OK now however --- inst/htmlwidgets/globe.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/inst/htmlwidgets/globe.js b/inst/htmlwidgets/globe.js index 7a04c1e..462585b 100644 --- a/inst/htmlwidgets/globe.js +++ b/inst/htmlwidgets/globe.js @@ -30,7 +30,11 @@ HTMLWidgets.widget( stuff.renderer.setSize( width, height ); stuff.width = width; stuff.height = height; -// stuff.camera.projectionMatrix = new THREE.Matrix4().makePerspective(stuff.camera.fov, stuff.renderer.domElement.width/stuff.renderer.domElement.height, stuff.camera.near, stuff.camera.far); // XXX FIX ME + var ymax = stuff.camera.near * Math.tan((Math.PI / 180) * stuff.camera.fov * 0.5); + var ymin = - ymax; + var xmin = ymin * stuff.camera.aspect; + var xmax = ymax * stuff.camera.aspect; + stuff.camera.projectionMatrix = new THREE.Matrix4().makePerspective(xmin, xmax, ymax, ymin, stuff.camera.near, stuff.camera.far); stuff.camera.lookAt(stuff.scene.position); stuff.renderer.render( stuff.scene, stuff.camera ); }, @@ -273,7 +277,11 @@ HTMLWidgets.widget( if(GL) stuff.camera.fov -= event.wheelDeltaY * 0.02; else stuff.camera.fov -= event.wheelDeltaY * 0.0075; stuff.camera.fov = Math.max( Math.min( stuff.camera.fov, fovMAX ), fovMIN ); -// stuff.camera.projectionMatrix = new THREE.Matrix4().makePerspective(stuff.camera.fov, stuff.renderer.domElement.width/stuff.renderer.domElement.height, stuff.camera.near, stuff.camera.far); // XXX FIX ME + var ymax = stuff.camera.near * Math.tan((Math.PI / 180) * stuff.camera.fov * 0.5); + var ymin = - ymax; + var xmin = ymin * stuff.camera.aspect; + var xmax = ymax * stuff.camera.aspect; + stuff.camera.projectionMatrix = new THREE.Matrix4().makePerspective(xmin, xmax, ymax, ymin, stuff.camera.near, stuff.camera.far); render(); } el.onmousewheel = function(ev) {ev.preventDefault();};