-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.js
65 lines (50 loc) · 1.6 KB
/
controls.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
var selection_keys = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var scaling_keys = ["X", "Y", "Z"];
var rotation_keys = ["W", "S", "E", "Q", "D", "A"];
var movement_keys = [37, 38, 39, 40, 188, 190];
var lighting_mode_keys = ["u", "U", "I", "O", "P"]; // for some reason, "U" is not recognized in my firefox
//'u' (Gouraud/diffuse), 'i' (Gouraud/specular), 'o' (Phong/diffuse), and 'p' (Phong/specular).
// 37 = <
// 38 = ^
// 39 = >
// 40 = v
// 188 = ,
// 190 = .
function keyboard_input() {
document.addEventListener("keydown", event_handling);
}
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);
else if(scaling_keys.indexOf(keyString) !== -1) {
if (selected_object_id == 0)
scale(keyString, event, scene[0]);
else
scale(keyString, event, scene[0].children[selected_object_id-1]);
}
else if (rotation_keys.indexOf(keyString) !== -1) {
if (selected_object_id == 0)
rotate(keyString, scene[0]);
else
rotate(keyString, scene[0].children[selected_object_id-1]);
}
else if (movement_keys.indexOf(event.keyCode) !== -1) {
if (selected_object_id == 0)
translate(event, scene[0]);
else
translate(event, scene[0].children[selected_object_id-1]);
}
else if (lighting_mode_keys.indexOf(keyString)) {
console.log(keyString);
if (keyString == "U")
lighting_mode = 1;
else if (keyString == "I")
lighting_mode = 2;
else if (keyString == "O")
lighting_mode = 3;
else if (keyString == "P")
lighting_mode = 4;
}
}