From 6f9358ae957ea9a0b0b94d8468dae2a58c8d12c8 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Sat, 26 Aug 2017 10:01:11 -0400 Subject: [PATCH] Three.js: fix rotate and pan on HiDPI devices. --- res/threejs/SolveSpaceControls.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/res/threejs/SolveSpaceControls.js b/res/threejs/SolveSpaceControls.js index cde7eb24..fbee7da2 100644 --- a/res/threejs/SolveSpaceControls.js +++ b/res/threejs/SolveSpaceControls.js @@ -155,8 +155,8 @@ SolvespaceControls = function(object, domElement) { switch (event.button) { case 0: - _rotateCur.set(event.screenX / window.devicePixelRatio, - event.screenY / window.devicePixelRatio); + _rotateCur.set(event.screenX, + event.screenY); _rotatePrev.copy(_rotateCur); document.addEventListener('mousemove', mousemove_rotate, false); document.addEventListener('mouseup', mouseup, false); @@ -184,8 +184,8 @@ SolvespaceControls = function(object, domElement) { } function mousemove_rotate(event) { - _rotateCur.set(event.screenX / window.devicePixelRatio, - event.screenY / window.devicePixelRatio); + _rotateCur.set(event.screenX, + event.screenY); var diff = new THREE.Vector2().subVectors(_rotateCur, _rotatePrev) .multiplyScalar(1 / object.zoomScale); object.rotate(-0.3 * Math.PI / 180 * diff.x * object.zoomScale, @@ -199,7 +199,7 @@ SolvespaceControls = function(object, domElement) { _offsetCur.set(event.screenX / window.devicePixelRatio, event.screenY / window.devicePixelRatio); var diff = new THREE.Vector2().subVectors(_offsetCur, _offsetPrev) - .multiplyScalar(1 / object.zoomScale); + .multiplyScalar(window.devicePixelRatio / object.zoomScale); object.offsetProj(diff.x, -diff.y); _changed = true; _offsetPrev.copy(_offsetCur); @@ -507,3 +507,4 @@ solvespace = function(obj, params) { return new THREE.LineSegments(geometry, material); } }; +