-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisteners.js
69 lines (68 loc) · 2.39 KB
/
listeners.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
62
63
64
65
66
67
68
69
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
document.addEventListener( 'mouseup', onDocumentMouseUp, false );
var blopAudio = new Audio('Blop.mp3');
var waterAudio = new Audio('Water.mp3');
function onDocumentMouseMove( event ) {
// waterAudio.play();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
mouse.z = 0.5;
mouse_.x = mouse.x;
mouse_.y = mouse.y;
mouse.unproject( camera );
var dir = mouse.sub( camera.position ).normalize();
var distance = - camera.position.z / dir.z;
pos = camera.position.clone().add( dir.multiplyScalar( distance ) );
pos.z = 0.5;
}
function onDocumentMouseDown( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
mouse.z = 0.5;
mouse_.x = mouse.x;
mouse_.y = mouse.y;
mouse.unproject( camera );
var dir = mouse.sub( camera.position ).normalize();
var distance = - camera.position.z / dir.z;
pos = camera.position.clone().add( dir.multiplyScalar( distance ) );
pos.z = 0.5;
mouseDown = true;
}
function onDocumentMouseUp( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
mouse.z = 0.5;
mouse_.x = mouse.x;
mouse_.y = mouse.y;
mouse.unproject( camera );
var dir = mouse.sub( camera.position ).normalize();
var distance = - camera.position.z / dir.z;
pos = camera.position.clone().add( dir.multiplyScalar( distance ) );
pos.z = 0.5;
mouseDown = false;
}
document.addEventListener('keydown', function(event) {
keyCode = event.keyCode;
if(keyCode == 39 ) {
rotateY = -1;
} else if (keyCode == 37 ) {
rotateY = 1;
} else if (keyCode == 38 ) {
move = 1;
} else if (keyCode == 40 ) {
move = -1;
}
});
document.addEventListener('keyup', function(event) {
keyCode = event.keyCode;
if(keyCode == 39 ) {
rotateY = 0;
} else if (keyCode == 37 ) {
rotateY = 0;
} else if (keyCode == 38 ) {
move = 0;
} else if (keyCode == 40 ) {
move = 0;
}
});