|
|
|
@@ -3,46 +3,64 @@ mouse.wasClick = true; |
|
|
|
|
|
|
|
mouse.raycaster = new THREE.Raycaster(); |
|
|
|
|
|
|
|
mouse.onFreeMove = function(){console.log("Free move");}; |
|
|
|
mouse.onDrag = function(){console.log("Drag");}; |
|
|
|
mouse.onClick = function(){console.log("Click");}; |
|
|
|
mouse.onCtrlClick = function(){console.log("Ctrl-click");}; |
|
|
|
mouse.onShiftClick = function(){console.log("Shift-click");}; |
|
|
|
mouse.onFreeMove = function() { |
|
|
|
console.log("Free move"); |
|
|
|
}; |
|
|
|
mouse.onDrag = function() { |
|
|
|
console.log("Drag"); |
|
|
|
}; |
|
|
|
mouse.onClick = function() { |
|
|
|
console.log("Click"); |
|
|
|
}; |
|
|
|
mouse.onCtrlClick = function() { |
|
|
|
console.log("Ctrl-click"); |
|
|
|
}; |
|
|
|
mouse.onShiftClick = function() { |
|
|
|
console.log("Shift-click"); |
|
|
|
}; |
|
|
|
|
|
|
|
mouse.prepare = function(){ |
|
|
|
mouse.prepare = function() { |
|
|
|
var el = gui.renderer.domElement; |
|
|
|
el.addEventListener("mousedown", mouse.onDown); |
|
|
|
el.addEventListener("mouseup", mouse.onUp); |
|
|
|
el.addEventListener("mousemove", mouse.onMove); |
|
|
|
}; |
|
|
|
|
|
|
|
mouse.onDown = function(event){ |
|
|
|
mouse.onDown = function(event) { |
|
|
|
mouse.wasClick = true; |
|
|
|
mouse.pressed = true; |
|
|
|
}; |
|
|
|
|
|
|
|
mouse.onUp = function(event){ |
|
|
|
if (!mouse.wasClick){return;} |
|
|
|
mouse.onUp = function(event) { |
|
|
|
if (!mouse.wasClick) { |
|
|
|
return; |
|
|
|
} |
|
|
|
mouse.pressed = false; |
|
|
|
if (event.ctrlKey){mouse.onCtrlClick();} |
|
|
|
else if (event.shiftKey){mouse.onShiftClick();} |
|
|
|
else { |
|
|
|
if (event.ctrlKey) { |
|
|
|
mouse.onCtrlClick(); |
|
|
|
} else if (event.shiftKey) { |
|
|
|
mouse.onShiftClick(); |
|
|
|
} else { |
|
|
|
mouse.onClick(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
mouse.onMove = function(event) { |
|
|
|
mouse.wasClick = false; |
|
|
|
mouse.position_absolute = {x: event.clientX, y:event.clientY}; |
|
|
|
mouse.position_relative = {x: (event.clientX / window.innerWidth) * 2 - 1, |
|
|
|
y: -(event.clientY / window.innerHeight) * 2 + 1}; |
|
|
|
mouse.position_absolute = { |
|
|
|
x: event.clientX, |
|
|
|
y: event.clientY |
|
|
|
}; |
|
|
|
mouse.position_relative = { |
|
|
|
x: (event.clientX / window.innerWidth) * 2 - 1, |
|
|
|
y: -(event.clientY / window.innerHeight) * 2 + 1 |
|
|
|
}; |
|
|
|
gui.setInfoPosition(mouse.position_absolute); |
|
|
|
mouse.raycaster.setFromCamera(mouse.position_relative, gui.camera); |
|
|
|
mouse.ray = mouse.raycaster.ray; |
|
|
|
if (mouse.pressed){ |
|
|
|
if (mouse.pressed) { |
|
|
|
mouse.onDrag(); |
|
|
|
} else { |
|
|
|
mouse.onFreeMove(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|