-
Notifications
You must be signed in to change notification settings - Fork 2
/
eventHandling.js
61 lines (47 loc) · 1.34 KB
/
eventHandling.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//field of view vertical angle is needed for picking objects with mouse rays
function setUpEventHandling(canvas, fov){
var msm = MouseStateMachine(canvas.width, canvas.height, fov);
$( "#switchTexture" ).click(function() {
switchTexture();
});
draggablePoints.onCPStateChange = function(){
if(!draggablePoints.closestPoint)
$('canvas').css( 'cursor', 'default' );
else if(draggablePoints.closestPoint.state !=0)
$('canvas').css( 'cursor', 'pointer' );
else
$('canvas').css( 'cursor', 'default' );
}
function getCentralizedMousePos(event){
return getCentralizedCoords(getMousePos(canvas, event), canvas.width, canvas.height);
}
canvas.onmouseup = function(event){
msm.mouseup();
}
canvas.onmousedown = function(event){
var pos = getCentralizedMousePos(event);
msm.mousedown(pos);
}
canvas.onmousemove = function(event){
var pos = getCentralizedMousePos(event);
msm.mousemove(pos);
}
canvas.onmousewheel = function (event){
var direction = (event.detail<0 || event.wheelDelta>0) ? 1 : -1;
msm.mousewheel(direction);
//stops event propagation, so it doesnt scroll the page also
return false;
}
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
switch(e.keyCode){
case 83: //s
msm.mousewheel(-1);
break;
case 87: //w
msm.mousewheel(1);
break;
}
}
}