-
Notifications
You must be signed in to change notification settings - Fork 1
/
transformations.js
62 lines (49 loc) · 2.06 KB
/
transformations.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
function scale(keyString, event) {
var factor = 0.9;
if (event.shiftKey)
factor = 1.1;
switch (keyString) {
case "X": mat4.scale(scene[selected_object_id].sclMatrix, [factor, 1, 1]);
break;
case "Y": mat4.scale(scene[selected_object_id].sclMatrix, [1, factor, 1]);
break;
case "Z": mat4.scale(scene[selected_object_id].sclMatrix, [1, 1, factor]);
break;
}
}
// mat4.rotate(mat, angle, axis)
// mat = mat * rotationmatrix_for(angle, axis)
// mat4.rotate(mat_out, mat_in, angle, axis)
// mat_out = mat_in * rotationmatrix_for(angle, axis)
function rotate(keyString) {
switch (keyString) {
case "W": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(10), [1, 0, 0]); // x clockwise
break;
case "S": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(-10), [1, 0, 0]);
break;
case "E": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(10), [0, 1, 0]); // y clockwise
break;
case "Q": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(-10), [0, 1, 0]);
break;
case "D": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(10), [0, 0, 1]);
break;
case "A": mat4.rotate(scene[selected_object_id].posRotMatrix, degToRad(-10), [0, 0, 1]);
break;
}
}
function translate(event) { // move shape using arrow keys
switch (event.keyCode) {
case 37: mat4.translate(scene[selected_object_id].posRotMatrix, [-0.1, 0, 0]); // left
break;
case 38: mat4.translate(scene[selected_object_id].posRotMatrix, [0, 0.1, 0]); // up
break;
case 39: mat4.translate(scene[selected_object_id].posRotMatrix, [0.1, 0, 0]); // right
break;
case 40: mat4.translate(scene[selected_object_id].posRotMatrix, [0, -0.1, 0]); // down
break;
case 188: mat4.translate(scene[selected_object_id].posRotMatrix, [0, 0, 0.1]); // , forth
break;
case 190: mat4.translate(scene[selected_object_id].posRotMatrix, [0, 0, -0.1]); // . back
break;
};
}