-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrix.js
128 lines (101 loc) · 2.79 KB
/
matrix.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function matrix3Multiply(a, b) {
var a00 = a[0*3+0];
var a01 = a[0*3+1];
var a02 = a[0*3+2];
var a10 = a[1*3+0];
var a11 = a[1*3+1];
var a12 = a[1*3+2];
var a20 = a[2*3+0];
var a21 = a[2*3+1];
var a22 = a[2*3+2];
var b00 = b[0*3+0];
var b01 = b[0*3+1];
var b02 = b[0*3+2];
var b10 = b[1*3+0];
var b11 = b[1*3+1];
var b12 = b[1*3+2];
var b20 = b[2*3+0];
var b21 = b[2*3+1];
var b22 = b[2*3+2];
return [a00 * b00 + a01 * b10 + a02 * b20,
a00 * b01 + a01 * b11 + a02 * b21,
a00 * b02 + a01 * b12 + a02 * b22,
a10 * b00 + a11 * b10 + a12 * b20,
a10 * b01 + a11 * b11 + a12 * b21,
a10 * b02 + a11 * b12 + a12 * b22,
a20 * b00 + a21 * b10 + a22 * b20,
a20 * b01 + a21 * b11 + a22 * b21,
a20 * b02 + a21 * b12 + a22 * b22];
}
function matrix4Multiply(a, b) {
var a00 = a[0*4+0];
var a01 = a[0*4+1];
var a02 = a[0*4+2];
var a03 = a[0*4+3];
var a10 = a[1*4+0];
var a11 = a[1*4+1];
var a12 = a[1*4+2];
var a13 = a[1*4+3];
var a20 = a[2*4+0];
var a21 = a[2*4+1];
var a22 = a[2*4+2];
var a23 = a[2*4+3];
var a30 = a[3*4+0];
var a31 = a[3*4+1];
var a32 = a[3*4+2];
var a33 = a[3*4+3];
var b00 = b[0*4+0];
var b01 = b[0*4+1];
var b02 = b[0*4+2];
var b03 = b[0*4+3];
var b10 = b[1*4+0];
var b11 = b[1*4+1];
var b12 = b[1*4+2];
var b13 = b[1*4+3];
var b20 = b[2*4+0];
var b21 = b[2*4+1];
var b22 = b[2*4+2];
var b23 = b[2*4+3];
var b30 = b[3*4+0];
var b31 = b[3*4+1];
var b32 = b[3*4+2];
var b33 = b[3*4+3];
return [a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30,
a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31,
a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32,
a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33,
a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30,
a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31,
a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32,
a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33,
a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30,
a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31,
a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32,
a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33,
a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30,
a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31,
a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32,
a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33];
}
function makeTranslationMatrix(vector){
var x = vector[0];
var y = vector[1];
var z = vector[2];
return [
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
x, y, z, 1
];
}
function makeScaleMatrix(vector){
var x = vector[0];
var y = vector[1];
var z = vector[2];
return [
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1
];
}