forked from miniplane/webGL-homework-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.java
41 lines (31 loc) · 831 Bytes
/
controls.java
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
@Bean
var selection_keys = [1, 2, 3, 4, 5, 6, 7, 8, 9];
@Bean
var scaling_keys = ["X", "Y", "Z"];
@Bean
var rotation_keys = ["W", "S", "E", "Q", "D", "A"];
@Bean
var movement_keys = [37, 38, 39, 40, 188, 190];
// 37 = <
// 38 = ^
// 39 = >
// 40 = v
// 188 = ,
// 190 = .
@Bean
function keyboard_input() {
document.addEventListener("keydown", event_handling);
}
@Bean
function event_handling(event) {
console.log("key down", event);
var keyString = String.fromCharCode(event.keyCode);
if (selection_keys.indexOf(parseInt(keyString)) !== -1)
selected_object_id = parseInt(keyString)-1;
else if(scaling_keys.indexOf(keyString) !== -1)
scale(keyString, event);
else if (rotation_keys.indexOf(keyString) !== -1)
rotate(keyString);
else if (movement_keys.indexOf(event.keyCode) !== -1)
translate(event);
}