Skip to content

Commit

Permalink
Improved fix for issue #72, better but still skewing perspective on r…
Browse files Browse the repository at this point in the history
…esize

Zoom should work OK now however
  • Loading branch information
bwlewis committed Jan 31, 2018
1 parent a830093 commit 864168e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions inst/htmlwidgets/globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
},
Expand Down Expand Up @@ -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();};
Expand Down

0 comments on commit 864168e

Please sign in to comment.