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,
|
||||
event.screenY / window.devicePixelRatio);
|
||||
_rotatePrev.copy(_rotateCur);
|
||||
document.addEventListener('mousemove', mousemove, false);
|
||||
document.addEventListener('mousemove', mousemove_rotate, false);
|
||||
document.addEventListener('mouseup', mouseup, false);
|
||||
break;
|
||||
case 2:
|
||||
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
||||
event.screenY / window.devicePixelRatio);
|
||||
_offsetPrev.copy(_offsetCur);
|
||||
document.addEventListener('mousemove', mousemove, false);
|
||||
document.addEventListener('mousemove', mousemove_pan, false);
|
||||
document.addEventListener('mouseup', mouseup, false);
|
||||
break;
|
||||
default:
|
||||
|
@ -183,9 +183,7 @@ SolvespaceControls = function(object, domElement) {
|
|||
_changed = true;
|
||||
}
|
||||
|
||||
function mousemove(event) {
|
||||
switch (event.button) {
|
||||
case 0:
|
||||
function mousemove_rotate(event) {
|
||||
_rotateCur.set(event.screenX / window.devicePixelRatio,
|
||||
event.screenY / window.devicePixelRatio);
|
||||
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);
|
||||
_changed = true;
|
||||
_rotatePrev.copy(_rotateCur);
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
|
||||
function mousemove_pan(event) {
|
||||
_mouseMoved = true;
|
||||
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
||||
event.screenY / window.devicePixelRatio);
|
||||
|
@ -203,11 +202,8 @@ SolvespaceControls = function(object, domElement) {
|
|||
.multiplyScalar(1 / object.zoomScale);
|
||||
object.offsetProj(diff.x, -diff.y);
|
||||
_changed = true;
|
||||
_offsetPrev.copy(_offsetCur)
|
||||
break;
|
||||
_offsetPrev.copy(_offsetCur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function mouseup(event) {
|
||||
/* TODO: Opera mouse gestures will intercept this event, making it
|
||||
|
@ -217,8 +213,16 @@ SolvespaceControls = function(object, domElement) {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
document.removeEventListener('mousemove', mousemove);
|
||||
switch (event.button) {
|
||||
case 0:
|
||||
document.removeEventListener('mousemove', mousemove_rotate);
|
||||
document.removeEventListener('mouseup', mouseup);
|
||||
break;
|
||||
case 2:
|
||||
document.removeEventListener('mousemove', mousemove_pan);
|
||||
document.removeEventListener('mouseup', mouseup);
|
||||
break;
|
||||
}
|
||||
|
||||
_this.dispatchEvent(endEvent);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue