Three.js: fix mousemove event listener.
The mousemove event does not return button press information; refactor into two handlers based on button press.pull/409/head
parent
52a481cd1e
commit
26c8cdcb37
|
@ -158,14 +158,14 @@ SolvespaceControls = function(object, domElement) {
|
||||||
_rotateCur.set(event.screenX / window.devicePixelRatio,
|
_rotateCur.set(event.screenX / window.devicePixelRatio,
|
||||||
event.screenY / window.devicePixelRatio);
|
event.screenY / window.devicePixelRatio);
|
||||||
_rotatePrev.copy(_rotateCur);
|
_rotatePrev.copy(_rotateCur);
|
||||||
document.addEventListener('mousemove', mousemove, false);
|
document.addEventListener('mousemove', mousemove_rotate, false);
|
||||||
document.addEventListener('mouseup', mouseup, false);
|
document.addEventListener('mouseup', mouseup, false);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
||||||
event.screenY / window.devicePixelRatio);
|
event.screenY / window.devicePixelRatio);
|
||||||
_offsetPrev.copy(_offsetCur);
|
_offsetPrev.copy(_offsetCur);
|
||||||
document.addEventListener('mousemove', mousemove, false);
|
document.addEventListener('mousemove', mousemove_pan, false);
|
||||||
document.addEventListener('mouseup', mouseup, false);
|
document.addEventListener('mouseup', mouseup, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -183,9 +183,7 @@ SolvespaceControls = function(object, domElement) {
|
||||||
_changed = true;
|
_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousemove(event) {
|
function mousemove_rotate(event) {
|
||||||
switch (event.button) {
|
|
||||||
case 0:
|
|
||||||
_rotateCur.set(event.screenX / window.devicePixelRatio,
|
_rotateCur.set(event.screenX / window.devicePixelRatio,
|
||||||
event.screenY / window.devicePixelRatio);
|
event.screenY / window.devicePixelRatio);
|
||||||
var diff = new THREE.Vector2().subVectors(_rotateCur, _rotatePrev)
|
var diff = new THREE.Vector2().subVectors(_rotateCur, _rotatePrev)
|
||||||
|
@ -194,8 +192,9 @@ SolvespaceControls = function(object, domElement) {
|
||||||
-0.3 * Math.PI / 180 * diff.y * object.zoomScale);
|
-0.3 * Math.PI / 180 * diff.y * object.zoomScale);
|
||||||
_changed = true;
|
_changed = true;
|
||||||
_rotatePrev.copy(_rotateCur);
|
_rotatePrev.copy(_rotateCur);
|
||||||
break;
|
}
|
||||||
case 2:
|
|
||||||
|
function mousemove_pan(event) {
|
||||||
_mouseMoved = true;
|
_mouseMoved = true;
|
||||||
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
||||||
event.screenY / window.devicePixelRatio);
|
event.screenY / window.devicePixelRatio);
|
||||||
|
@ -203,11 +202,8 @@ SolvespaceControls = function(object, domElement) {
|
||||||
.multiplyScalar(1 / object.zoomScale);
|
.multiplyScalar(1 / object.zoomScale);
|
||||||
object.offsetProj(diff.x, -diff.y);
|
object.offsetProj(diff.x, -diff.y);
|
||||||
_changed = true;
|
_changed = true;
|
||||||
_offsetPrev.copy(_offsetCur)
|
_offsetPrev.copy(_offsetCur);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function mouseup(event) {
|
function mouseup(event) {
|
||||||
/* TODO: Opera mouse gestures will intercept this event, making it
|
/* TODO: Opera mouse gestures will intercept this event, making it
|
||||||
|
@ -217,8 +213,16 @@ SolvespaceControls = function(object, domElement) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
document.removeEventListener('mousemove', mousemove);
|
switch (event.button) {
|
||||||
|
case 0:
|
||||||
|
document.removeEventListener('mousemove', mousemove_rotate);
|
||||||
document.removeEventListener('mouseup', mouseup);
|
document.removeEventListener('mouseup', mouseup);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
document.removeEventListener('mousemove', mousemove_pan);
|
||||||
|
document.removeEventListener('mouseup', mouseup);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
_this.dispatchEvent(endEvent);
|
_this.dispatchEvent(endEvent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue