-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransformationMatrices.js
47 lines (47 loc) · 1.79 KB
/
TransformationMatrices.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
export const transformationMatrices = {
translate: (x, y, z) => {
let result = math.identity(4);
result.subset(math.index(0, 3), x);
result.subset(math.index(1, 3), y);
result.subset(math.index(2, 3), z);
return result;
},
rotateOY: (deg) => {
let result = math.zeros(4, 4);
result.subset(math.index(0, 0), math.cos(math.unit(deg, "deg")));
result.subset(math.index(1, 1), 1);
result.subset(math.index(2, 0), -math.sin(math.unit(deg, "deg")));
result.subset(math.index(0, 2), math.sin(math.unit(deg, "deg")));
result.subset(math.index(2, 2), math.cos(math.unit(deg, "deg")));
result.subset(math.index(3, 3), 1);
return result;
},
rotateOX: (deg) => {
let result = math.zeros(4, 4);
result.subset(math.index(0, 0), 1);
result.subset(math.index(1, 1), math.cos(math.unit(deg, "deg")));
result.subset(math.index(1, 2), -math.sin(math.unit(deg, "deg")));
result.subset(math.index(2, 1), math.sin(math.unit(deg, "deg")));
result.subset(math.index(2, 2), math.cos(math.unit(deg, "deg")));
result.subset(math.index(3, 3), 1);
return result;
},
rotateOZ: (deg) => {
let result = math.zeros(4, 4);
result.subset(math.index(0, 0), math.cos(math.unit(deg, "deg")));
result.subset(math.index(1, 1), math.cos(math.unit(deg, "deg")));
result.subset(math.index(0, 1), -math.sin(math.unit(deg, "deg")));
result.subset(math.index(1, 0), math.sin(math.unit(deg, "deg")));
result.subset(math.index(2, 2), 1);
result.subset(math.index(3, 3), 1);
return result;
},
scale: (value) => {
let result = math.zeros(4, 4);
result.subset(math.index(0, 0), value);
result.subset(math.index(1, 1), value);
result.subset(math.index(2, 2), value);
result.subset(math.index(3, 3), 1);
return result;
},
};