@math.gl/core 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/base/math-array.d.ts +1 -2
- package/dist/classes/base/math-array.js +220 -266
- package/dist/classes/base/matrix.d.ts +1 -2
- package/dist/classes/base/matrix.js +52 -53
- package/dist/classes/base/vector.d.ts +1 -2
- package/dist/classes/base/vector.js +121 -135
- package/dist/classes/euler.d.ts +2 -3
- package/dist/classes/euler.js +462 -533
- package/dist/classes/matrix3.d.ts +2 -3
- package/dist/classes/matrix3.js +185 -190
- package/dist/classes/matrix4.d.ts +1 -2
- package/dist/classes/matrix4.js +516 -452
- package/dist/classes/pose.d.ts +4 -5
- package/dist/classes/pose.js +104 -119
- package/dist/classes/quaternion.d.ts +1 -2
- package/dist/classes/quaternion.js +257 -233
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.js +138 -147
- package/dist/classes/vector2.d.ts +1 -2
- package/dist/classes/vector2.js +101 -85
- package/dist/classes/vector3.d.ts +1 -2
- package/dist/classes/vector3.js +125 -136
- package/dist/classes/vector4.d.ts +2 -3
- package/dist/classes/vector4.js +106 -114
- package/dist/gl-matrix/common.d.ts +0 -1
- package/dist/gl-matrix/common.js +38 -6
- package/dist/gl-matrix/mat3.d.ts +0 -1
- package/dist/gl-matrix/mat3.js +699 -425
- package/dist/gl-matrix/mat4.d.ts +0 -1
- package/dist/gl-matrix/mat4.js +1879 -1339
- package/dist/gl-matrix/quat.d.ts +0 -1
- package/dist/gl-matrix/quat.js +655 -257
- package/dist/gl-matrix/vec2.d.ts +0 -1
- package/dist/gl-matrix/vec2.js +529 -212
- package/dist/gl-matrix/vec3.d.ts +0 -1
- package/dist/gl-matrix/vec3.js +703 -335
- package/dist/gl-matrix/vec4.d.ts +0 -1
- package/dist/gl-matrix/vec4.js +579 -293
- package/dist/gl-matrix/wip/index.d.ts +3 -4
- package/dist/gl-matrix/wip/index.js +2 -1
- package/dist/gl-matrix/wip/mat2.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2.js +333 -157
- package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2d.js +377 -202
- package/dist/gl-matrix/wip/quat2.d.ts +0 -1
- package/dist/gl-matrix/wip/quat2.js +647 -409
- package/dist/index.cjs +60 -100
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +21 -22
- package/dist/index.js +23 -16
- package/dist/lib/assert.d.ts +0 -1
- package/dist/lib/assert.js +3 -4
- package/dist/lib/common.d.ts +2 -3
- package/dist/lib/common.js +163 -134
- package/dist/lib/gl-matrix-extras.d.ts +0 -1
- package/dist/lib/gl-matrix-extras.js +39 -36
- package/dist/lib/math-utils.d.ts +0 -1
- package/dist/lib/math-utils.js +2 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.js +22 -25
- package/package.json +5 -6
- package/src/classes/matrix3.ts +1 -1
- package/dist/classes/base/math-array.d.ts.map +0 -1
- package/dist/classes/base/math-array.js.map +0 -1
- package/dist/classes/base/matrix.d.ts.map +0 -1
- package/dist/classes/base/matrix.js.map +0 -1
- package/dist/classes/base/vector.d.ts.map +0 -1
- package/dist/classes/base/vector.js.map +0 -1
- package/dist/classes/euler.d.ts.map +0 -1
- package/dist/classes/euler.js.map +0 -1
- package/dist/classes/matrix3.d.ts.map +0 -1
- package/dist/classes/matrix3.js.map +0 -1
- package/dist/classes/matrix4.d.ts.map +0 -1
- package/dist/classes/matrix4.js.map +0 -1
- package/dist/classes/pose.d.ts.map +0 -1
- package/dist/classes/pose.js.map +0 -1
- package/dist/classes/quaternion.d.ts.map +0 -1
- package/dist/classes/quaternion.js.map +0 -1
- package/dist/classes/spherical-coordinates.d.ts.map +0 -1
- package/dist/classes/spherical-coordinates.js.map +0 -1
- package/dist/classes/vector2.d.ts.map +0 -1
- package/dist/classes/vector2.js.map +0 -1
- package/dist/classes/vector3.d.ts.map +0 -1
- package/dist/classes/vector3.js.map +0 -1
- package/dist/classes/vector4.d.ts.map +0 -1
- package/dist/classes/vector4.js.map +0 -1
- package/dist/gl-matrix/common.d.ts.map +0 -1
- package/dist/gl-matrix/common.js.map +0 -1
- package/dist/gl-matrix/mat3.d.ts.map +0 -1
- package/dist/gl-matrix/mat3.js.map +0 -1
- package/dist/gl-matrix/mat4.d.ts.map +0 -1
- package/dist/gl-matrix/mat4.js.map +0 -1
- package/dist/gl-matrix/quat.d.ts.map +0 -1
- package/dist/gl-matrix/quat.js.map +0 -1
- package/dist/gl-matrix/vec2.d.ts.map +0 -1
- package/dist/gl-matrix/vec2.js.map +0 -1
- package/dist/gl-matrix/vec3.d.ts.map +0 -1
- package/dist/gl-matrix/vec3.js.map +0 -1
- package/dist/gl-matrix/vec4.d.ts.map +0 -1
- package/dist/gl-matrix/vec4.js.map +0 -1
- package/dist/gl-matrix/wip/index.d.ts.map +0 -1
- package/dist/gl-matrix/wip/index.js.map +0 -1
- package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2.js.map +0 -1
- package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2d.js.map +0 -1
- package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/quat2.js.map +0 -1
- package/dist/gl-matrix/wip/types.d.js +0 -2
- package/dist/gl-matrix/wip/types.d.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/assert.d.ts.map +0 -1
- package/dist/lib/assert.js.map +0 -1
- package/dist/lib/common.d.ts.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
- package/dist/lib/gl-matrix-extras.js.map +0 -1
- package/dist/lib/gl-matrix.d.js +0 -2
- package/dist/lib/gl-matrix.d.js.map +0 -1
- package/dist/lib/math-utils.d.ts.map +0 -1
- package/dist/lib/math-utils.js.map +0 -1
- package/dist/lib/validators.d.ts.map +0 -1
- package/dist/lib/validators.js.map +0 -1
package/dist/gl-matrix/mat3.js
CHANGED
|
@@ -1,489 +1,763 @@
|
|
|
1
1
|
import * as glMatrix from './common.js';
|
|
2
|
+
/**
|
|
3
|
+
* 3x3 Matrix
|
|
4
|
+
* @module mat3
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new identity mat3
|
|
8
|
+
*
|
|
9
|
+
* @returns {mat3} a new 3x3 matrix
|
|
10
|
+
*/
|
|
2
11
|
export function create() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
out[8] = 1;
|
|
17
|
-
return out;
|
|
12
|
+
const out = new glMatrix.ARRAY_TYPE(9);
|
|
13
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
14
|
+
out[1] = 0;
|
|
15
|
+
out[2] = 0;
|
|
16
|
+
out[3] = 0;
|
|
17
|
+
out[5] = 0;
|
|
18
|
+
out[6] = 0;
|
|
19
|
+
out[7] = 0;
|
|
20
|
+
}
|
|
21
|
+
out[0] = 1;
|
|
22
|
+
out[4] = 1;
|
|
23
|
+
out[8] = 1;
|
|
24
|
+
return out;
|
|
18
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Copies the upper-left 3x3 values into the given mat3.
|
|
28
|
+
*
|
|
29
|
+
* @param {mat3} out the receiving 3x3 matrix
|
|
30
|
+
* @param {ReadonlyMat4} a the source 4x4 matrix
|
|
31
|
+
* @returns {mat3} out
|
|
32
|
+
*/
|
|
19
33
|
export function fromMat4(out, a) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
out[0] = a[0];
|
|
35
|
+
out[1] = a[1];
|
|
36
|
+
out[2] = a[2];
|
|
37
|
+
out[3] = a[4];
|
|
38
|
+
out[4] = a[5];
|
|
39
|
+
out[5] = a[6];
|
|
40
|
+
out[6] = a[8];
|
|
41
|
+
out[7] = a[9];
|
|
42
|
+
out[8] = a[10];
|
|
43
|
+
return out;
|
|
30
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new mat3 initialized with values from an existing matrix
|
|
47
|
+
*
|
|
48
|
+
* @param {ReadonlyMat3} a matrix to clone
|
|
49
|
+
* @returns {mat3} a new 3x3 matrix
|
|
50
|
+
*/
|
|
31
51
|
export function clone(a) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
const out = new glMatrix.ARRAY_TYPE(9);
|
|
53
|
+
out[0] = a[0];
|
|
54
|
+
out[1] = a[1];
|
|
55
|
+
out[2] = a[2];
|
|
56
|
+
out[3] = a[3];
|
|
57
|
+
out[4] = a[4];
|
|
58
|
+
out[5] = a[5];
|
|
59
|
+
out[6] = a[6];
|
|
60
|
+
out[7] = a[7];
|
|
61
|
+
out[8] = a[8];
|
|
62
|
+
return out;
|
|
43
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Copy the values from one mat3 to another
|
|
66
|
+
*
|
|
67
|
+
* @param {mat3} out the receiving matrix
|
|
68
|
+
* @param {ReadonlyMat3} a the source matrix
|
|
69
|
+
* @returns {mat3} out
|
|
70
|
+
*/
|
|
44
71
|
export function copy(out, a) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
out[0] = a[0];
|
|
73
|
+
out[1] = a[1];
|
|
74
|
+
out[2] = a[2];
|
|
75
|
+
out[3] = a[3];
|
|
76
|
+
out[4] = a[4];
|
|
77
|
+
out[5] = a[5];
|
|
78
|
+
out[6] = a[6];
|
|
79
|
+
out[7] = a[7];
|
|
80
|
+
out[8] = a[8];
|
|
81
|
+
return out;
|
|
55
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a new mat3 with the given values
|
|
85
|
+
*
|
|
86
|
+
* @param {Number} m00 Component in column 0, row 0 position (index 0)
|
|
87
|
+
* @param {Number} m01 Component in column 0, row 1 position (index 1)
|
|
88
|
+
* @param {Number} m02 Component in column 0, row 2 position (index 2)
|
|
89
|
+
* @param {Number} m10 Component in column 1, row 0 position (index 3)
|
|
90
|
+
* @param {Number} m11 Component in column 1, row 1 position (index 4)
|
|
91
|
+
* @param {Number} m12 Component in column 1, row 2 position (index 5)
|
|
92
|
+
* @param {Number} m20 Component in column 2, row 0 position (index 6)
|
|
93
|
+
* @param {Number} m21 Component in column 2, row 1 position (index 7)
|
|
94
|
+
* @param {Number} m22 Component in column 2, row 2 position (index 8)
|
|
95
|
+
* @returns {mat3} A new mat3
|
|
96
|
+
*/
|
|
56
97
|
export function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
98
|
+
const out = new glMatrix.ARRAY_TYPE(9);
|
|
99
|
+
out[0] = m00;
|
|
100
|
+
out[1] = m01;
|
|
101
|
+
out[2] = m02;
|
|
102
|
+
out[3] = m10;
|
|
103
|
+
out[4] = m11;
|
|
104
|
+
out[5] = m12;
|
|
105
|
+
out[6] = m20;
|
|
106
|
+
out[7] = m21;
|
|
107
|
+
out[8] = m22;
|
|
108
|
+
return out;
|
|
68
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the components of a mat3 to the given values
|
|
112
|
+
*
|
|
113
|
+
* @param {mat3} out the receiving matrix
|
|
114
|
+
* @param {Number} m00 Component in column 0, row 0 position (index 0)
|
|
115
|
+
* @param {Number} m01 Component in column 0, row 1 position (index 1)
|
|
116
|
+
* @param {Number} m02 Component in column 0, row 2 position (index 2)
|
|
117
|
+
* @param {Number} m10 Component in column 1, row 0 position (index 3)
|
|
118
|
+
* @param {Number} m11 Component in column 1, row 1 position (index 4)
|
|
119
|
+
* @param {Number} m12 Component in column 1, row 2 position (index 5)
|
|
120
|
+
* @param {Number} m20 Component in column 2, row 0 position (index 6)
|
|
121
|
+
* @param {Number} m21 Component in column 2, row 1 position (index 7)
|
|
122
|
+
* @param {Number} m22 Component in column 2, row 2 position (index 8)
|
|
123
|
+
* @returns {mat3} out
|
|
124
|
+
*/
|
|
69
125
|
export function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
126
|
+
out[0] = m00;
|
|
127
|
+
out[1] = m01;
|
|
128
|
+
out[2] = m02;
|
|
129
|
+
out[3] = m10;
|
|
130
|
+
out[4] = m11;
|
|
131
|
+
out[5] = m12;
|
|
132
|
+
out[6] = m20;
|
|
133
|
+
out[7] = m21;
|
|
134
|
+
out[8] = m22;
|
|
135
|
+
return out;
|
|
80
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Set a mat3 to the identity matrix
|
|
139
|
+
*
|
|
140
|
+
* @param {mat3} out the receiving matrix
|
|
141
|
+
* @returns {mat3} out
|
|
142
|
+
*/
|
|
81
143
|
export function identity(out) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
144
|
+
out[0] = 1;
|
|
145
|
+
out[1] = 0;
|
|
146
|
+
out[2] = 0;
|
|
147
|
+
out[3] = 0;
|
|
148
|
+
out[4] = 1;
|
|
149
|
+
out[5] = 0;
|
|
150
|
+
out[6] = 0;
|
|
151
|
+
out[7] = 0;
|
|
152
|
+
out[8] = 1;
|
|
153
|
+
return out;
|
|
92
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Transpose the values of a mat3
|
|
157
|
+
*
|
|
158
|
+
* @param {mat3} out the receiving matrix
|
|
159
|
+
* @param {ReadonlyMat3} a the source matrix
|
|
160
|
+
* @returns {mat3} out
|
|
161
|
+
*/
|
|
93
162
|
export function transpose(out, a) {
|
|
94
|
-
|
|
163
|
+
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
|
164
|
+
if (out === a) {
|
|
165
|
+
const a01 = a[1];
|
|
166
|
+
const a02 = a[2];
|
|
167
|
+
const a12 = a[5];
|
|
168
|
+
out[1] = a[3];
|
|
169
|
+
out[2] = a[6];
|
|
170
|
+
out[3] = a01;
|
|
171
|
+
out[5] = a[7];
|
|
172
|
+
out[6] = a02;
|
|
173
|
+
out[7] = a12;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
out[0] = a[0];
|
|
177
|
+
out[1] = a[3];
|
|
178
|
+
out[2] = a[6];
|
|
179
|
+
out[3] = a[1];
|
|
180
|
+
out[4] = a[4];
|
|
181
|
+
out[5] = a[7];
|
|
182
|
+
out[6] = a[2];
|
|
183
|
+
out[7] = a[5];
|
|
184
|
+
out[8] = a[8];
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Inverts a mat3
|
|
190
|
+
*
|
|
191
|
+
* @param {mat3} out the receiving matrix
|
|
192
|
+
* @param {ReadonlyMat3} a the source matrix
|
|
193
|
+
* @returns {mat3} out
|
|
194
|
+
*/
|
|
195
|
+
export function invert(out, a) {
|
|
196
|
+
const a00 = a[0];
|
|
95
197
|
const a01 = a[1];
|
|
96
198
|
const a02 = a[2];
|
|
199
|
+
const a10 = a[3];
|
|
200
|
+
const a11 = a[4];
|
|
97
201
|
const a12 = a[5];
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
out[
|
|
111
|
-
out[
|
|
112
|
-
out[
|
|
113
|
-
out[
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const a01 = a[1];
|
|
121
|
-
const a02 = a[2];
|
|
122
|
-
const a10 = a[3];
|
|
123
|
-
const a11 = a[4];
|
|
124
|
-
const a12 = a[5];
|
|
125
|
-
const a20 = a[6];
|
|
126
|
-
const a21 = a[7];
|
|
127
|
-
const a22 = a[8];
|
|
128
|
-
const b01 = a22 * a11 - a12 * a21;
|
|
129
|
-
const b11 = -a22 * a10 + a12 * a20;
|
|
130
|
-
const b21 = a21 * a10 - a11 * a20;
|
|
131
|
-
let det = a00 * b01 + a01 * b11 + a02 * b21;
|
|
132
|
-
|
|
133
|
-
if (!det) {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
det = 1.0 / det;
|
|
138
|
-
out[0] = b01 * det;
|
|
139
|
-
out[1] = (-a22 * a01 + a02 * a21) * det;
|
|
140
|
-
out[2] = (a12 * a01 - a02 * a11) * det;
|
|
141
|
-
out[3] = b11 * det;
|
|
142
|
-
out[4] = (a22 * a00 - a02 * a20) * det;
|
|
143
|
-
out[5] = (-a12 * a00 + a02 * a10) * det;
|
|
144
|
-
out[6] = b21 * det;
|
|
145
|
-
out[7] = (-a21 * a00 + a01 * a20) * det;
|
|
146
|
-
out[8] = (a11 * a00 - a01 * a10) * det;
|
|
147
|
-
return out;
|
|
202
|
+
const a20 = a[6];
|
|
203
|
+
const a21 = a[7];
|
|
204
|
+
const a22 = a[8];
|
|
205
|
+
const b01 = a22 * a11 - a12 * a21;
|
|
206
|
+
const b11 = -a22 * a10 + a12 * a20;
|
|
207
|
+
const b21 = a21 * a10 - a11 * a20;
|
|
208
|
+
// Calculate the determinant
|
|
209
|
+
let det = a00 * b01 + a01 * b11 + a02 * b21;
|
|
210
|
+
if (!det) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
det = 1.0 / det;
|
|
214
|
+
out[0] = b01 * det;
|
|
215
|
+
out[1] = (-a22 * a01 + a02 * a21) * det;
|
|
216
|
+
out[2] = (a12 * a01 - a02 * a11) * det;
|
|
217
|
+
out[3] = b11 * det;
|
|
218
|
+
out[4] = (a22 * a00 - a02 * a20) * det;
|
|
219
|
+
out[5] = (-a12 * a00 + a02 * a10) * det;
|
|
220
|
+
out[6] = b21 * det;
|
|
221
|
+
out[7] = (-a21 * a00 + a01 * a20) * det;
|
|
222
|
+
out[8] = (a11 * a00 - a01 * a10) * det;
|
|
223
|
+
return out;
|
|
148
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Calculates the adjugate of a mat3
|
|
227
|
+
*
|
|
228
|
+
* @param {mat3} out the receiving matrix
|
|
229
|
+
* @param {ReadonlyMat3} a the source matrix
|
|
230
|
+
* @returns {mat3} out
|
|
231
|
+
*/
|
|
149
232
|
export function adjoint(out, a) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
233
|
+
const a00 = a[0];
|
|
234
|
+
const a01 = a[1];
|
|
235
|
+
const a02 = a[2];
|
|
236
|
+
const a10 = a[3];
|
|
237
|
+
const a11 = a[4];
|
|
238
|
+
const a12 = a[5];
|
|
239
|
+
const a20 = a[6];
|
|
240
|
+
const a21 = a[7];
|
|
241
|
+
const a22 = a[8];
|
|
242
|
+
out[0] = a11 * a22 - a12 * a21;
|
|
243
|
+
out[1] = a02 * a21 - a01 * a22;
|
|
244
|
+
out[2] = a01 * a12 - a02 * a11;
|
|
245
|
+
out[3] = a12 * a20 - a10 * a22;
|
|
246
|
+
out[4] = a00 * a22 - a02 * a20;
|
|
247
|
+
out[5] = a02 * a10 - a00 * a12;
|
|
248
|
+
out[6] = a10 * a21 - a11 * a20;
|
|
249
|
+
out[7] = a01 * a20 - a00 * a21;
|
|
250
|
+
out[8] = a00 * a11 - a01 * a10;
|
|
251
|
+
return out;
|
|
169
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Calculates the determinant of a mat3
|
|
255
|
+
*
|
|
256
|
+
* @param {ReadonlyMat3} a the source matrix
|
|
257
|
+
* @returns {Number} determinant of a
|
|
258
|
+
*/
|
|
170
259
|
export function determinant(a) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
260
|
+
const a00 = a[0];
|
|
261
|
+
const a01 = a[1];
|
|
262
|
+
const a02 = a[2];
|
|
263
|
+
const a10 = a[3];
|
|
264
|
+
const a11 = a[4];
|
|
265
|
+
const a12 = a[5];
|
|
266
|
+
const a20 = a[6];
|
|
267
|
+
const a21 = a[7];
|
|
268
|
+
const a22 = a[8];
|
|
269
|
+
return (a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20));
|
|
181
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Multiplies two mat3's
|
|
273
|
+
*
|
|
274
|
+
* @param {mat3} out the receiving matrix
|
|
275
|
+
* @param {ReadonlyMat3} a the first operand
|
|
276
|
+
* @param {ReadonlyMat3} b the second operand
|
|
277
|
+
* @returns {mat3} out
|
|
278
|
+
*/
|
|
182
279
|
export function multiply(out, a, b) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
280
|
+
const a00 = a[0];
|
|
281
|
+
const a01 = a[1];
|
|
282
|
+
const a02 = a[2];
|
|
283
|
+
const a10 = a[3];
|
|
284
|
+
const a11 = a[4];
|
|
285
|
+
const a12 = a[5];
|
|
286
|
+
const a20 = a[6];
|
|
287
|
+
const a21 = a[7];
|
|
288
|
+
const a22 = a[8];
|
|
289
|
+
const b00 = b[0];
|
|
290
|
+
const b01 = b[1];
|
|
291
|
+
const b02 = b[2];
|
|
292
|
+
const b10 = b[3];
|
|
293
|
+
const b11 = b[4];
|
|
294
|
+
const b12 = b[5];
|
|
295
|
+
const b20 = b[6];
|
|
296
|
+
const b21 = b[7];
|
|
297
|
+
const b22 = b[8];
|
|
298
|
+
out[0] = b00 * a00 + b01 * a10 + b02 * a20;
|
|
299
|
+
out[1] = b00 * a01 + b01 * a11 + b02 * a21;
|
|
300
|
+
out[2] = b00 * a02 + b01 * a12 + b02 * a22;
|
|
301
|
+
out[3] = b10 * a00 + b11 * a10 + b12 * a20;
|
|
302
|
+
out[4] = b10 * a01 + b11 * a11 + b12 * a21;
|
|
303
|
+
out[5] = b10 * a02 + b11 * a12 + b12 * a22;
|
|
304
|
+
out[6] = b20 * a00 + b21 * a10 + b22 * a20;
|
|
305
|
+
out[7] = b20 * a01 + b21 * a11 + b22 * a21;
|
|
306
|
+
out[8] = b20 * a02 + b21 * a12 + b22 * a22;
|
|
307
|
+
return out;
|
|
211
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Translate a mat3 by the given vector
|
|
311
|
+
*
|
|
312
|
+
* @param {mat3} out the receiving matrix
|
|
313
|
+
* @param {ReadonlyMat3} a the matrix to translate
|
|
314
|
+
* @param {ReadonlyVec2} v vector to translate by
|
|
315
|
+
* @returns {mat3} out
|
|
316
|
+
*/
|
|
212
317
|
export function translate(out, a, v) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
318
|
+
const a00 = a[0];
|
|
319
|
+
const a01 = a[1];
|
|
320
|
+
const a02 = a[2];
|
|
321
|
+
const a10 = a[3];
|
|
322
|
+
const a11 = a[4];
|
|
323
|
+
const a12 = a[5];
|
|
324
|
+
const a20 = a[6];
|
|
325
|
+
const a21 = a[7];
|
|
326
|
+
const a22 = a[8];
|
|
327
|
+
const x = v[0];
|
|
328
|
+
const y = v[1];
|
|
329
|
+
out[0] = a00;
|
|
330
|
+
out[1] = a01;
|
|
331
|
+
out[2] = a02;
|
|
332
|
+
out[3] = a10;
|
|
333
|
+
out[4] = a11;
|
|
334
|
+
out[5] = a12;
|
|
335
|
+
out[6] = x * a00 + y * a10 + a20;
|
|
336
|
+
out[7] = x * a01 + y * a11 + a21;
|
|
337
|
+
out[8] = x * a02 + y * a12 + a22;
|
|
338
|
+
return out;
|
|
234
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Rotates a mat3 by the given angle
|
|
342
|
+
*
|
|
343
|
+
* @param {mat3} out the receiving matrix
|
|
344
|
+
* @param {ReadonlyMat3} a the matrix to rotate
|
|
345
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
346
|
+
* @returns {mat3} out
|
|
347
|
+
*/
|
|
235
348
|
export function rotate(out, a, rad) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
349
|
+
const a00 = a[0];
|
|
350
|
+
const a01 = a[1];
|
|
351
|
+
const a02 = a[2];
|
|
352
|
+
const a10 = a[3];
|
|
353
|
+
const a11 = a[4];
|
|
354
|
+
const a12 = a[5];
|
|
355
|
+
const a20 = a[6];
|
|
356
|
+
const a21 = a[7];
|
|
357
|
+
const a22 = a[8];
|
|
358
|
+
const s = Math.sin(rad);
|
|
359
|
+
const c = Math.cos(rad);
|
|
360
|
+
out[0] = c * a00 + s * a10;
|
|
361
|
+
out[1] = c * a01 + s * a11;
|
|
362
|
+
out[2] = c * a02 + s * a12;
|
|
363
|
+
out[3] = c * a10 - s * a00;
|
|
364
|
+
out[4] = c * a11 - s * a01;
|
|
365
|
+
out[5] = c * a12 - s * a02;
|
|
366
|
+
out[6] = a20;
|
|
367
|
+
out[7] = a21;
|
|
368
|
+
out[8] = a22;
|
|
369
|
+
return out;
|
|
257
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Scales the mat3 by the dimensions in the given vec2
|
|
373
|
+
*
|
|
374
|
+
* @param {mat3} out the receiving matrix
|
|
375
|
+
* @param {ReadonlyMat3} a the matrix to scale
|
|
376
|
+
* @param {ReadonlyVec2} v the vec2 to scale the matrix by
|
|
377
|
+
* @returns {mat3} out
|
|
378
|
+
**/
|
|
258
379
|
export function scale(out, a, v) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
380
|
+
const x = v[0];
|
|
381
|
+
const y = v[1];
|
|
382
|
+
out[0] = x * a[0];
|
|
383
|
+
out[1] = x * a[1];
|
|
384
|
+
out[2] = x * a[2];
|
|
385
|
+
out[3] = y * a[3];
|
|
386
|
+
out[4] = y * a[4];
|
|
387
|
+
out[5] = y * a[5];
|
|
388
|
+
out[6] = a[6];
|
|
389
|
+
out[7] = a[7];
|
|
390
|
+
out[8] = a[8];
|
|
391
|
+
return out;
|
|
271
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Creates a matrix from a vector translation
|
|
395
|
+
* This is equivalent to (but much faster than):
|
|
396
|
+
*
|
|
397
|
+
* mat3.identity(dest);
|
|
398
|
+
* mat3.translate(dest, dest, vec);
|
|
399
|
+
*
|
|
400
|
+
* @param {mat3} out mat3 receiving operation result
|
|
401
|
+
* @param {ReadonlyVec2} v Translation vector
|
|
402
|
+
* @returns {mat3} out
|
|
403
|
+
*/
|
|
272
404
|
export function fromTranslation(out, v) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
405
|
+
out[0] = 1;
|
|
406
|
+
out[1] = 0;
|
|
407
|
+
out[2] = 0;
|
|
408
|
+
out[3] = 0;
|
|
409
|
+
out[4] = 1;
|
|
410
|
+
out[5] = 0;
|
|
411
|
+
out[6] = v[0];
|
|
412
|
+
out[7] = v[1];
|
|
413
|
+
out[8] = 1;
|
|
414
|
+
return out;
|
|
283
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Creates a matrix from a given angle
|
|
418
|
+
* This is equivalent to (but much faster than):
|
|
419
|
+
*
|
|
420
|
+
* mat3.identity(dest);
|
|
421
|
+
* mat3.rotate(dest, dest, rad);
|
|
422
|
+
*
|
|
423
|
+
* @param {mat3} out mat3 receiving operation result
|
|
424
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
425
|
+
* @returns {mat3} out
|
|
426
|
+
*/
|
|
284
427
|
export function fromRotation(out, rad) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
428
|
+
const s = Math.sin(rad);
|
|
429
|
+
const c = Math.cos(rad);
|
|
430
|
+
out[0] = c;
|
|
431
|
+
out[1] = s;
|
|
432
|
+
out[2] = 0;
|
|
433
|
+
out[3] = -s;
|
|
434
|
+
out[4] = c;
|
|
435
|
+
out[5] = 0;
|
|
436
|
+
out[6] = 0;
|
|
437
|
+
out[7] = 0;
|
|
438
|
+
out[8] = 1;
|
|
439
|
+
return out;
|
|
297
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Creates a matrix from a vector scaling
|
|
443
|
+
* This is equivalent to (but much faster than):
|
|
444
|
+
*
|
|
445
|
+
* mat3.identity(dest);
|
|
446
|
+
* mat3.scale(dest, dest, vec);
|
|
447
|
+
*
|
|
448
|
+
* @param {mat3} out mat3 receiving operation result
|
|
449
|
+
* @param {ReadonlyVec2} v Scaling vector
|
|
450
|
+
* @returns {mat3} out
|
|
451
|
+
*/
|
|
298
452
|
export function fromScaling(out, v) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
453
|
+
out[0] = v[0];
|
|
454
|
+
out[1] = 0;
|
|
455
|
+
out[2] = 0;
|
|
456
|
+
out[3] = 0;
|
|
457
|
+
out[4] = v[1];
|
|
458
|
+
out[5] = 0;
|
|
459
|
+
out[6] = 0;
|
|
460
|
+
out[7] = 0;
|
|
461
|
+
out[8] = 1;
|
|
462
|
+
return out;
|
|
309
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* Copies the values from a mat2d into a mat3
|
|
466
|
+
*
|
|
467
|
+
* @param {mat3} out the receiving matrix
|
|
468
|
+
* @param {ReadonlyMat2d} a the matrix to copy
|
|
469
|
+
* @returns {mat3} out
|
|
470
|
+
**/
|
|
310
471
|
export function fromMat2d(out, a) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
472
|
+
out[0] = a[0];
|
|
473
|
+
out[1] = a[1];
|
|
474
|
+
out[2] = 0;
|
|
475
|
+
out[3] = a[2];
|
|
476
|
+
out[4] = a[3];
|
|
477
|
+
out[5] = 0;
|
|
478
|
+
out[6] = a[4];
|
|
479
|
+
out[7] = a[5];
|
|
480
|
+
out[8] = 1;
|
|
481
|
+
return out;
|
|
321
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* Calculates a 3x3 matrix from the given quaternion
|
|
485
|
+
*
|
|
486
|
+
* @param {mat3} out mat3 receiving operation result
|
|
487
|
+
* @param {ReadonlyQuat} q Quaternion to create matrix from
|
|
488
|
+
*
|
|
489
|
+
* @returns {mat3} out
|
|
490
|
+
*/
|
|
322
491
|
export function fromQuat(out, q) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
492
|
+
const x = q[0];
|
|
493
|
+
const y = q[1];
|
|
494
|
+
const z = q[2];
|
|
495
|
+
const w = q[3];
|
|
496
|
+
const x2 = x + x;
|
|
497
|
+
const y2 = y + y;
|
|
498
|
+
const z2 = z + z;
|
|
499
|
+
const xx = x * x2;
|
|
500
|
+
const yx = y * x2;
|
|
501
|
+
const yy = y * y2;
|
|
502
|
+
const zx = z * x2;
|
|
503
|
+
const zy = z * y2;
|
|
504
|
+
const zz = z * z2;
|
|
505
|
+
const wx = w * x2;
|
|
506
|
+
const wy = w * y2;
|
|
507
|
+
const wz = w * z2;
|
|
508
|
+
out[0] = 1 - yy - zz;
|
|
509
|
+
out[3] = yx - wz;
|
|
510
|
+
out[6] = zx + wy;
|
|
511
|
+
out[1] = yx + wz;
|
|
512
|
+
out[4] = 1 - xx - zz;
|
|
513
|
+
out[7] = zy - wx;
|
|
514
|
+
out[2] = zx - wy;
|
|
515
|
+
out[5] = zy + wx;
|
|
516
|
+
out[8] = 1 - xx - yy;
|
|
517
|
+
return out;
|
|
349
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
|
|
521
|
+
*
|
|
522
|
+
* @param {mat3} out mat3 receiving operation result
|
|
523
|
+
* @param {ReadonlyMat4} a Mat4 to derive the normal matrix from
|
|
524
|
+
*
|
|
525
|
+
* @returns {mat3} out
|
|
526
|
+
*/
|
|
350
527
|
export function normalFromMat4(out, a) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return out;
|
|
528
|
+
const a00 = a[0];
|
|
529
|
+
const a01 = a[1];
|
|
530
|
+
const a02 = a[2];
|
|
531
|
+
const a03 = a[3];
|
|
532
|
+
const a10 = a[4];
|
|
533
|
+
const a11 = a[5];
|
|
534
|
+
const a12 = a[6];
|
|
535
|
+
const a13 = a[7];
|
|
536
|
+
const a20 = a[8];
|
|
537
|
+
const a21 = a[9];
|
|
538
|
+
const a22 = a[10];
|
|
539
|
+
const a23 = a[11];
|
|
540
|
+
const a30 = a[12];
|
|
541
|
+
const a31 = a[13];
|
|
542
|
+
const a32 = a[14];
|
|
543
|
+
const a33 = a[15];
|
|
544
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
545
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
546
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
547
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
548
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
549
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
550
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
551
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
552
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
553
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
554
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
555
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
556
|
+
// Calculate the determinant
|
|
557
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
558
|
+
if (!det) {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
det = 1.0 / det;
|
|
562
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
563
|
+
out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
564
|
+
out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
565
|
+
out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
566
|
+
out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
567
|
+
out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
568
|
+
out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
569
|
+
out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
570
|
+
out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
571
|
+
return out;
|
|
396
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* Generates a 2D projection matrix with the given bounds
|
|
575
|
+
*
|
|
576
|
+
* @param {mat3} out mat3 frustum matrix will be written into
|
|
577
|
+
* @param {number} width Width of your gl context
|
|
578
|
+
* @param {number} height Height of gl context
|
|
579
|
+
* @returns {mat3} out
|
|
580
|
+
*/
|
|
397
581
|
export function projection(out, width, height) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
582
|
+
out[0] = 2 / width;
|
|
583
|
+
out[1] = 0;
|
|
584
|
+
out[2] = 0;
|
|
585
|
+
out[3] = 0;
|
|
586
|
+
out[4] = -2 / height;
|
|
587
|
+
out[5] = 0;
|
|
588
|
+
out[6] = -1;
|
|
589
|
+
out[7] = 1;
|
|
590
|
+
out[8] = 1;
|
|
591
|
+
return out;
|
|
408
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* Returns a string representation of a mat3
|
|
595
|
+
*
|
|
596
|
+
* @param {ReadonlyMat3} a matrix to represent as a string
|
|
597
|
+
* @returns {String} string representation of the matrix
|
|
598
|
+
*/
|
|
409
599
|
export function str(a) {
|
|
410
|
-
|
|
600
|
+
return `mat3(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]}, ${a[4]}, ${a[5]}, ${a[6]}, ${a[7]}, ${a[8]})`;
|
|
411
601
|
}
|
|
602
|
+
/**
|
|
603
|
+
* Returns Frobenius norm of a mat3
|
|
604
|
+
*
|
|
605
|
+
* @param {ReadonlyMat3} a the matrix to calculate Frobenius norm of
|
|
606
|
+
* @returns {Number} Frobenius norm
|
|
607
|
+
*/
|
|
412
608
|
export function frob(a) {
|
|
413
|
-
|
|
609
|
+
return Math.sqrt(a[0] * a[0] +
|
|
610
|
+
a[1] * a[1] +
|
|
611
|
+
a[2] * a[2] +
|
|
612
|
+
a[3] * a[3] +
|
|
613
|
+
a[4] * a[4] +
|
|
614
|
+
a[5] * a[5] +
|
|
615
|
+
a[6] * a[6] +
|
|
616
|
+
a[7] * a[7] +
|
|
617
|
+
a[8] * a[8]);
|
|
414
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Adds two mat3's
|
|
621
|
+
*
|
|
622
|
+
* @param {mat3} out the receiving matrix
|
|
623
|
+
* @param {ReadonlyMat3} a the first operand
|
|
624
|
+
* @param {ReadonlyMat3} b the second operand
|
|
625
|
+
* @returns {mat3} out
|
|
626
|
+
*/
|
|
415
627
|
export function add(out, a, b) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
628
|
+
out[0] = a[0] + b[0];
|
|
629
|
+
out[1] = a[1] + b[1];
|
|
630
|
+
out[2] = a[2] + b[2];
|
|
631
|
+
out[3] = a[3] + b[3];
|
|
632
|
+
out[4] = a[4] + b[4];
|
|
633
|
+
out[5] = a[5] + b[5];
|
|
634
|
+
out[6] = a[6] + b[6];
|
|
635
|
+
out[7] = a[7] + b[7];
|
|
636
|
+
out[8] = a[8] + b[8];
|
|
637
|
+
return out;
|
|
426
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* Subtracts matrix b from matrix a
|
|
641
|
+
*
|
|
642
|
+
* @param {mat3} out the receiving matrix
|
|
643
|
+
* @param {ReadonlyMat3} a the first operand
|
|
644
|
+
* @param {ReadonlyMat3} b the second operand
|
|
645
|
+
* @returns {mat3} out
|
|
646
|
+
*/
|
|
427
647
|
export function subtract(out, a, b) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
648
|
+
out[0] = a[0] - b[0];
|
|
649
|
+
out[1] = a[1] - b[1];
|
|
650
|
+
out[2] = a[2] - b[2];
|
|
651
|
+
out[3] = a[3] - b[3];
|
|
652
|
+
out[4] = a[4] - b[4];
|
|
653
|
+
out[5] = a[5] - b[5];
|
|
654
|
+
out[6] = a[6] - b[6];
|
|
655
|
+
out[7] = a[7] - b[7];
|
|
656
|
+
out[8] = a[8] - b[8];
|
|
657
|
+
return out;
|
|
438
658
|
}
|
|
659
|
+
/**
|
|
660
|
+
* Multiply each element of the matrix by a scalar.
|
|
661
|
+
*
|
|
662
|
+
* @param {mat3} out the receiving matrix
|
|
663
|
+
* @param {ReadonlyMat3} a the matrix to scale
|
|
664
|
+
* @param {Number} b amount to scale the matrix's elements by
|
|
665
|
+
* @returns {mat3} out
|
|
666
|
+
*/
|
|
439
667
|
export function multiplyScalar(out, a, b) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
668
|
+
out[0] = a[0] * b;
|
|
669
|
+
out[1] = a[1] * b;
|
|
670
|
+
out[2] = a[2] * b;
|
|
671
|
+
out[3] = a[3] * b;
|
|
672
|
+
out[4] = a[4] * b;
|
|
673
|
+
out[5] = a[5] * b;
|
|
674
|
+
out[6] = a[6] * b;
|
|
675
|
+
out[7] = a[7] * b;
|
|
676
|
+
out[8] = a[8] * b;
|
|
677
|
+
return out;
|
|
450
678
|
}
|
|
679
|
+
/**
|
|
680
|
+
* Adds two mat3's after multiplying each element of the second operand by a scalar value.
|
|
681
|
+
*
|
|
682
|
+
* @param {mat3} out the receiving vector
|
|
683
|
+
* @param {ReadonlyMat3} a the first operand
|
|
684
|
+
* @param {ReadonlyMat3} b the second operand
|
|
685
|
+
* @param {Number} scale the amount to scale b's elements by before adding
|
|
686
|
+
* @returns {mat3} out
|
|
687
|
+
*/
|
|
451
688
|
export function multiplyScalarAndAdd(out, a, b, scale) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
689
|
+
out[0] = a[0] + b[0] * scale;
|
|
690
|
+
out[1] = a[1] + b[1] * scale;
|
|
691
|
+
out[2] = a[2] + b[2] * scale;
|
|
692
|
+
out[3] = a[3] + b[3] * scale;
|
|
693
|
+
out[4] = a[4] + b[4] * scale;
|
|
694
|
+
out[5] = a[5] + b[5] * scale;
|
|
695
|
+
out[6] = a[6] + b[6] * scale;
|
|
696
|
+
out[7] = a[7] + b[7] * scale;
|
|
697
|
+
out[8] = a[8] + b[8] * scale;
|
|
698
|
+
return out;
|
|
462
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
702
|
+
*
|
|
703
|
+
* @param {ReadonlyMat3} a The first matrix.
|
|
704
|
+
* @param {ReadonlyMat3} b The second matrix.
|
|
705
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
706
|
+
*/
|
|
463
707
|
export function exactEquals(a, b) {
|
|
464
|
-
|
|
708
|
+
return (a[0] === b[0] &&
|
|
709
|
+
a[1] === b[1] &&
|
|
710
|
+
a[2] === b[2] &&
|
|
711
|
+
a[3] === b[3] &&
|
|
712
|
+
a[4] === b[4] &&
|
|
713
|
+
a[5] === b[5] &&
|
|
714
|
+
a[6] === b[6] &&
|
|
715
|
+
a[7] === b[7] &&
|
|
716
|
+
a[8] === b[8]);
|
|
465
717
|
}
|
|
718
|
+
/**
|
|
719
|
+
* Returns whether or not the matrices have approximately the same elements in the same position.
|
|
720
|
+
*
|
|
721
|
+
* @param {ReadonlyMat3} a The first matrix.
|
|
722
|
+
* @param {ReadonlyMat3} b The second matrix.
|
|
723
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
724
|
+
*/
|
|
466
725
|
export function equals(a, b) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
726
|
+
const a0 = a[0];
|
|
727
|
+
const a1 = a[1];
|
|
728
|
+
const a2 = a[2];
|
|
729
|
+
const a3 = a[3];
|
|
730
|
+
const a4 = a[4];
|
|
731
|
+
const a5 = a[5];
|
|
732
|
+
const a6 = a[6];
|
|
733
|
+
const a7 = a[7];
|
|
734
|
+
const a8 = a[8];
|
|
735
|
+
const b0 = b[0];
|
|
736
|
+
const b1 = b[1];
|
|
737
|
+
const b2 = b[2];
|
|
738
|
+
const b3 = b[3];
|
|
739
|
+
const b4 = b[4];
|
|
740
|
+
const b5 = b[5];
|
|
741
|
+
const b6 = b[6];
|
|
742
|
+
const b7 = b[7];
|
|
743
|
+
const b8 = b[8];
|
|
744
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
745
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
|
|
746
|
+
Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
|
|
747
|
+
Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
|
|
748
|
+
Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
|
|
749
|
+
Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
|
|
750
|
+
Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
|
|
751
|
+
Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
|
|
752
|
+
Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)));
|
|
486
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* Alias for {@link mat3.multiply}
|
|
756
|
+
* @function
|
|
757
|
+
*/
|
|
487
758
|
export const mul = multiply;
|
|
759
|
+
/**
|
|
760
|
+
* Alias for {@link mat3.subtract}
|
|
761
|
+
* @function
|
|
762
|
+
*/
|
|
488
763
|
export const sub = subtract;
|
|
489
|
-
//# sourceMappingURL=mat3.js.map
|