@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/mat4.js
CHANGED
|
@@ -1,370 +1,595 @@
|
|
|
1
|
+
// @eslint-disable
|
|
2
|
+
// @ts-nocheck
|
|
1
3
|
import * as glMatrix from './common.js';
|
|
4
|
+
/**
|
|
5
|
+
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
6
|
+
* @module mat4
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new identity mat4
|
|
10
|
+
*
|
|
11
|
+
* @returns a new 4x4 matrix
|
|
12
|
+
*/
|
|
2
13
|
export function create() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
const out = new glMatrix.ARRAY_TYPE(16);
|
|
15
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
16
|
+
out[1] = 0;
|
|
17
|
+
out[2] = 0;
|
|
18
|
+
out[3] = 0;
|
|
19
|
+
out[4] = 0;
|
|
20
|
+
out[6] = 0;
|
|
21
|
+
out[7] = 0;
|
|
22
|
+
out[8] = 0;
|
|
23
|
+
out[9] = 0;
|
|
24
|
+
out[11] = 0;
|
|
25
|
+
out[12] = 0;
|
|
26
|
+
out[13] = 0;
|
|
27
|
+
out[14] = 0;
|
|
28
|
+
}
|
|
29
|
+
out[0] = 1;
|
|
30
|
+
out[5] = 1;
|
|
31
|
+
out[10] = 1;
|
|
32
|
+
out[15] = 1;
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new mat4 initialized with values from an existing matrix
|
|
37
|
+
*
|
|
38
|
+
* @param {ReadonlyMat4} a matrix to clone
|
|
39
|
+
* @returns {mat4} a new 4x4 matrix
|
|
40
|
+
*/
|
|
41
|
+
export function clone(a) {
|
|
42
|
+
const out = new glMatrix.ARRAY_TYPE(16);
|
|
43
|
+
out[0] = a[0];
|
|
44
|
+
out[1] = a[1];
|
|
45
|
+
out[2] = a[2];
|
|
46
|
+
out[3] = a[3];
|
|
47
|
+
out[4] = a[4];
|
|
48
|
+
out[5] = a[5];
|
|
49
|
+
out[6] = a[6];
|
|
50
|
+
out[7] = a[7];
|
|
51
|
+
out[8] = a[8];
|
|
52
|
+
out[9] = a[9];
|
|
53
|
+
out[10] = a[10];
|
|
54
|
+
out[11] = a[11];
|
|
55
|
+
out[12] = a[12];
|
|
56
|
+
out[13] = a[13];
|
|
57
|
+
out[14] = a[14];
|
|
58
|
+
out[15] = a[15];
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Copy the values from one mat4 to another
|
|
63
|
+
*
|
|
64
|
+
* @param {mat4} out the receiving matrix
|
|
65
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
66
|
+
* @returns {mat4} out
|
|
67
|
+
*/
|
|
68
|
+
export function copy(out, a) {
|
|
69
|
+
out[0] = a[0];
|
|
70
|
+
out[1] = a[1];
|
|
71
|
+
out[2] = a[2];
|
|
72
|
+
out[3] = a[3];
|
|
73
|
+
out[4] = a[4];
|
|
74
|
+
out[5] = a[5];
|
|
75
|
+
out[6] = a[6];
|
|
76
|
+
out[7] = a[7];
|
|
77
|
+
out[8] = a[8];
|
|
78
|
+
out[9] = a[9];
|
|
79
|
+
out[10] = a[10];
|
|
80
|
+
out[11] = a[11];
|
|
81
|
+
out[12] = a[12];
|
|
82
|
+
out[13] = a[13];
|
|
83
|
+
out[14] = a[14];
|
|
84
|
+
out[15] = a[15];
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a new mat4 with the given values
|
|
89
|
+
*
|
|
90
|
+
* @param {Number} m00 Component in column 0, row 0 position (index 0)
|
|
91
|
+
* @param {Number} m01 Component in column 0, row 1 position (index 1)
|
|
92
|
+
* @param {Number} m02 Component in column 0, row 2 position (index 2)
|
|
93
|
+
* @param {Number} m03 Component in column 0, row 3 position (index 3)
|
|
94
|
+
* @param {Number} m10 Component in column 1, row 0 position (index 4)
|
|
95
|
+
* @param {Number} m11 Component in column 1, row 1 position (index 5)
|
|
96
|
+
* @param {Number} m12 Component in column 1, row 2 position (index 6)
|
|
97
|
+
* @param {Number} m13 Component in column 1, row 3 position (index 7)
|
|
98
|
+
* @param {Number} m20 Component in column 2, row 0 position (index 8)
|
|
99
|
+
* @param {Number} m21 Component in column 2, row 1 position (index 9)
|
|
100
|
+
* @param {Number} m22 Component in column 2, row 2 position (index 10)
|
|
101
|
+
* @param {Number} m23 Component in column 2, row 3 position (index 11)
|
|
102
|
+
* @param {Number} m30 Component in column 3, row 0 position (index 12)
|
|
103
|
+
* @param {Number} m31 Component in column 3, row 1 position (index 13)
|
|
104
|
+
* @param {Number} m32 Component in column 3, row 2 position (index 14)
|
|
105
|
+
* @param {Number} m33 Component in column 3, row 3 position (index 15)
|
|
106
|
+
* @returns {mat4} A new mat4
|
|
107
|
+
*/
|
|
108
|
+
export function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
109
|
+
const out = new glMatrix.ARRAY_TYPE(16);
|
|
110
|
+
out[0] = m00;
|
|
111
|
+
out[1] = m01;
|
|
112
|
+
out[2] = m02;
|
|
113
|
+
out[3] = m03;
|
|
114
|
+
out[4] = m10;
|
|
115
|
+
out[5] = m11;
|
|
116
|
+
out[6] = m12;
|
|
117
|
+
out[7] = m13;
|
|
118
|
+
out[8] = m20;
|
|
119
|
+
out[9] = m21;
|
|
120
|
+
out[10] = m22;
|
|
121
|
+
out[11] = m23;
|
|
122
|
+
out[12] = m30;
|
|
123
|
+
out[13] = m31;
|
|
124
|
+
out[14] = m32;
|
|
125
|
+
out[15] = m33;
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Set the components of a mat4 to the given values
|
|
130
|
+
*
|
|
131
|
+
* @param {mat4} out the receiving matrix
|
|
132
|
+
* @param {Number} m00 Component in column 0, row 0 position (index 0)
|
|
133
|
+
* @param {Number} m01 Component in column 0, row 1 position (index 1)
|
|
134
|
+
* @param {Number} m02 Component in column 0, row 2 position (index 2)
|
|
135
|
+
* @param {Number} m03 Component in column 0, row 3 position (index 3)
|
|
136
|
+
* @param {Number} m10 Component in column 1, row 0 position (index 4)
|
|
137
|
+
* @param {Number} m11 Component in column 1, row 1 position (index 5)
|
|
138
|
+
* @param {Number} m12 Component in column 1, row 2 position (index 6)
|
|
139
|
+
* @param {Number} m13 Component in column 1, row 3 position (index 7)
|
|
140
|
+
* @param {Number} m20 Component in column 2, row 0 position (index 8)
|
|
141
|
+
* @param {Number} m21 Component in column 2, row 1 position (index 9)
|
|
142
|
+
* @param {Number} m22 Component in column 2, row 2 position (index 10)
|
|
143
|
+
* @param {Number} m23 Component in column 2, row 3 position (index 11)
|
|
144
|
+
* @param {Number} m30 Component in column 3, row 0 position (index 12)
|
|
145
|
+
* @param {Number} m31 Component in column 3, row 1 position (index 13)
|
|
146
|
+
* @param {Number} m32 Component in column 3, row 2 position (index 14)
|
|
147
|
+
* @param {Number} m33 Component in column 3, row 3 position (index 15)
|
|
148
|
+
* @returns {mat4} out
|
|
149
|
+
*/
|
|
150
|
+
export function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
151
|
+
out[0] = m00;
|
|
152
|
+
out[1] = m01;
|
|
153
|
+
out[2] = m02;
|
|
154
|
+
out[3] = m03;
|
|
155
|
+
out[4] = m10;
|
|
156
|
+
out[5] = m11;
|
|
157
|
+
out[6] = m12;
|
|
158
|
+
out[7] = m13;
|
|
159
|
+
out[8] = m20;
|
|
160
|
+
out[9] = m21;
|
|
161
|
+
out[10] = m22;
|
|
162
|
+
out[11] = m23;
|
|
163
|
+
out[12] = m30;
|
|
164
|
+
out[13] = m31;
|
|
165
|
+
out[14] = m32;
|
|
166
|
+
out[15] = m33;
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Set a mat4 to the identity matrix
|
|
171
|
+
*
|
|
172
|
+
* @param {mat4} out the receiving matrix
|
|
173
|
+
* @returns {mat4} out
|
|
174
|
+
*/
|
|
175
|
+
export function identity(out) {
|
|
176
|
+
out[0] = 1;
|
|
6
177
|
out[1] = 0;
|
|
7
178
|
out[2] = 0;
|
|
8
179
|
out[3] = 0;
|
|
9
180
|
out[4] = 0;
|
|
181
|
+
out[5] = 1;
|
|
10
182
|
out[6] = 0;
|
|
11
183
|
out[7] = 0;
|
|
12
184
|
out[8] = 0;
|
|
13
185
|
out[9] = 0;
|
|
186
|
+
out[10] = 1;
|
|
14
187
|
out[11] = 0;
|
|
15
188
|
out[12] = 0;
|
|
16
189
|
out[13] = 0;
|
|
17
190
|
out[14] = 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
out[0] = 1;
|
|
21
|
-
out[5] = 1;
|
|
22
|
-
out[10] = 1;
|
|
23
|
-
out[15] = 1;
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
26
|
-
export function clone(a) {
|
|
27
|
-
const out = new glMatrix.ARRAY_TYPE(16);
|
|
28
|
-
out[0] = a[0];
|
|
29
|
-
out[1] = a[1];
|
|
30
|
-
out[2] = a[2];
|
|
31
|
-
out[3] = a[3];
|
|
32
|
-
out[4] = a[4];
|
|
33
|
-
out[5] = a[5];
|
|
34
|
-
out[6] = a[6];
|
|
35
|
-
out[7] = a[7];
|
|
36
|
-
out[8] = a[8];
|
|
37
|
-
out[9] = a[9];
|
|
38
|
-
out[10] = a[10];
|
|
39
|
-
out[11] = a[11];
|
|
40
|
-
out[12] = a[12];
|
|
41
|
-
out[13] = a[13];
|
|
42
|
-
out[14] = a[14];
|
|
43
|
-
out[15] = a[15];
|
|
44
|
-
return out;
|
|
45
|
-
}
|
|
46
|
-
export function copy(out, a) {
|
|
47
|
-
out[0] = a[0];
|
|
48
|
-
out[1] = a[1];
|
|
49
|
-
out[2] = a[2];
|
|
50
|
-
out[3] = a[3];
|
|
51
|
-
out[4] = a[4];
|
|
52
|
-
out[5] = a[5];
|
|
53
|
-
out[6] = a[6];
|
|
54
|
-
out[7] = a[7];
|
|
55
|
-
out[8] = a[8];
|
|
56
|
-
out[9] = a[9];
|
|
57
|
-
out[10] = a[10];
|
|
58
|
-
out[11] = a[11];
|
|
59
|
-
out[12] = a[12];
|
|
60
|
-
out[13] = a[13];
|
|
61
|
-
out[14] = a[14];
|
|
62
|
-
out[15] = a[15];
|
|
63
|
-
return out;
|
|
64
|
-
}
|
|
65
|
-
export function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
66
|
-
const out = new glMatrix.ARRAY_TYPE(16);
|
|
67
|
-
out[0] = m00;
|
|
68
|
-
out[1] = m01;
|
|
69
|
-
out[2] = m02;
|
|
70
|
-
out[3] = m03;
|
|
71
|
-
out[4] = m10;
|
|
72
|
-
out[5] = m11;
|
|
73
|
-
out[6] = m12;
|
|
74
|
-
out[7] = m13;
|
|
75
|
-
out[8] = m20;
|
|
76
|
-
out[9] = m21;
|
|
77
|
-
out[10] = m22;
|
|
78
|
-
out[11] = m23;
|
|
79
|
-
out[12] = m30;
|
|
80
|
-
out[13] = m31;
|
|
81
|
-
out[14] = m32;
|
|
82
|
-
out[15] = m33;
|
|
83
|
-
return out;
|
|
84
|
-
}
|
|
85
|
-
export function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
86
|
-
out[0] = m00;
|
|
87
|
-
out[1] = m01;
|
|
88
|
-
out[2] = m02;
|
|
89
|
-
out[3] = m03;
|
|
90
|
-
out[4] = m10;
|
|
91
|
-
out[5] = m11;
|
|
92
|
-
out[6] = m12;
|
|
93
|
-
out[7] = m13;
|
|
94
|
-
out[8] = m20;
|
|
95
|
-
out[9] = m21;
|
|
96
|
-
out[10] = m22;
|
|
97
|
-
out[11] = m23;
|
|
98
|
-
out[12] = m30;
|
|
99
|
-
out[13] = m31;
|
|
100
|
-
out[14] = m32;
|
|
101
|
-
out[15] = m33;
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
|
-
export function identity(out) {
|
|
105
|
-
out[0] = 1;
|
|
106
|
-
out[1] = 0;
|
|
107
|
-
out[2] = 0;
|
|
108
|
-
out[3] = 0;
|
|
109
|
-
out[4] = 0;
|
|
110
|
-
out[5] = 1;
|
|
111
|
-
out[6] = 0;
|
|
112
|
-
out[7] = 0;
|
|
113
|
-
out[8] = 0;
|
|
114
|
-
out[9] = 0;
|
|
115
|
-
out[10] = 1;
|
|
116
|
-
out[11] = 0;
|
|
117
|
-
out[12] = 0;
|
|
118
|
-
out[13] = 0;
|
|
119
|
-
out[14] = 0;
|
|
120
|
-
out[15] = 1;
|
|
121
|
-
return out;
|
|
191
|
+
out[15] = 1;
|
|
192
|
+
return out;
|
|
122
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Transpose the values of a mat4
|
|
196
|
+
*
|
|
197
|
+
* @param {mat4} out the receiving matrix
|
|
198
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
199
|
+
* @returns {mat4} out
|
|
200
|
+
*/
|
|
123
201
|
export function transpose(out, a) {
|
|
124
|
-
|
|
202
|
+
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
|
203
|
+
if (out === a) {
|
|
204
|
+
const a01 = a[1];
|
|
205
|
+
const a02 = a[2];
|
|
206
|
+
const a03 = a[3];
|
|
207
|
+
const a12 = a[6];
|
|
208
|
+
const a13 = a[7];
|
|
209
|
+
const a23 = a[11];
|
|
210
|
+
out[1] = a[4];
|
|
211
|
+
out[2] = a[8];
|
|
212
|
+
out[3] = a[12];
|
|
213
|
+
out[4] = a01;
|
|
214
|
+
out[6] = a[9];
|
|
215
|
+
out[7] = a[13];
|
|
216
|
+
out[8] = a02;
|
|
217
|
+
out[9] = a12;
|
|
218
|
+
out[11] = a[14];
|
|
219
|
+
out[12] = a03;
|
|
220
|
+
out[13] = a13;
|
|
221
|
+
out[14] = a23;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
out[0] = a[0];
|
|
225
|
+
out[1] = a[4];
|
|
226
|
+
out[2] = a[8];
|
|
227
|
+
out[3] = a[12];
|
|
228
|
+
out[4] = a[1];
|
|
229
|
+
out[5] = a[5];
|
|
230
|
+
out[6] = a[9];
|
|
231
|
+
out[7] = a[13];
|
|
232
|
+
out[8] = a[2];
|
|
233
|
+
out[9] = a[6];
|
|
234
|
+
out[10] = a[10];
|
|
235
|
+
out[11] = a[14];
|
|
236
|
+
out[12] = a[3];
|
|
237
|
+
out[13] = a[7];
|
|
238
|
+
out[14] = a[11];
|
|
239
|
+
out[15] = a[15];
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Inverts a mat4
|
|
245
|
+
*
|
|
246
|
+
* @param {mat4} out the receiving matrix
|
|
247
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
248
|
+
* @returns {mat4} out
|
|
249
|
+
*/
|
|
250
|
+
export function invert(out, a) {
|
|
251
|
+
const a00 = a[0];
|
|
125
252
|
const a01 = a[1];
|
|
126
253
|
const a02 = a[2];
|
|
127
254
|
const a03 = a[3];
|
|
255
|
+
const a10 = a[4];
|
|
256
|
+
const a11 = a[5];
|
|
128
257
|
const a12 = a[6];
|
|
129
258
|
const a13 = a[7];
|
|
259
|
+
const a20 = a[8];
|
|
260
|
+
const a21 = a[9];
|
|
261
|
+
const a22 = a[10];
|
|
130
262
|
const a23 = a[11];
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
out[
|
|
154
|
-
out[
|
|
155
|
-
out[
|
|
156
|
-
out[
|
|
157
|
-
out[
|
|
158
|
-
out[
|
|
159
|
-
out[
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const a11 = a[5];
|
|
171
|
-
const a12 = a[6];
|
|
172
|
-
const a13 = a[7];
|
|
173
|
-
const a20 = a[8];
|
|
174
|
-
const a21 = a[9];
|
|
175
|
-
const a22 = a[10];
|
|
176
|
-
const a23 = a[11];
|
|
177
|
-
const a30 = a[12];
|
|
178
|
-
const a31 = a[13];
|
|
179
|
-
const a32 = a[14];
|
|
180
|
-
const a33 = a[15];
|
|
181
|
-
const b00 = a00 * a11 - a01 * a10;
|
|
182
|
-
const b01 = a00 * a12 - a02 * a10;
|
|
183
|
-
const b02 = a00 * a13 - a03 * a10;
|
|
184
|
-
const b03 = a01 * a12 - a02 * a11;
|
|
185
|
-
const b04 = a01 * a13 - a03 * a11;
|
|
186
|
-
const b05 = a02 * a13 - a03 * a12;
|
|
187
|
-
const b06 = a20 * a31 - a21 * a30;
|
|
188
|
-
const b07 = a20 * a32 - a22 * a30;
|
|
189
|
-
const b08 = a20 * a33 - a23 * a30;
|
|
190
|
-
const b09 = a21 * a32 - a22 * a31;
|
|
191
|
-
const b10 = a21 * a33 - a23 * a31;
|
|
192
|
-
const b11 = a22 * a33 - a23 * a32;
|
|
193
|
-
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
194
|
-
|
|
195
|
-
if (!det) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
det = 1.0 / det;
|
|
200
|
-
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
201
|
-
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
202
|
-
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
203
|
-
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
204
|
-
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
205
|
-
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
206
|
-
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
207
|
-
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
208
|
-
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
209
|
-
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
210
|
-
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
211
|
-
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
212
|
-
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
213
|
-
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
214
|
-
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
215
|
-
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
216
|
-
return out;
|
|
263
|
+
const a30 = a[12];
|
|
264
|
+
const a31 = a[13];
|
|
265
|
+
const a32 = a[14];
|
|
266
|
+
const a33 = a[15];
|
|
267
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
268
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
269
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
270
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
271
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
272
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
273
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
274
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
275
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
276
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
277
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
278
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
279
|
+
// Calculate the determinant
|
|
280
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
281
|
+
if (!det) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
det = 1.0 / det;
|
|
285
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
286
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
287
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
288
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
289
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
290
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
291
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
292
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
293
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
294
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
295
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
296
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
297
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
298
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
299
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
300
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
301
|
+
return out;
|
|
217
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Calculates the adjugate of a mat4
|
|
305
|
+
*
|
|
306
|
+
* @param {mat4} out the receiving matrix
|
|
307
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
308
|
+
* @returns {mat4} out
|
|
309
|
+
*/
|
|
218
310
|
export function adjoint(out, a) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
311
|
+
const a00 = a[0];
|
|
312
|
+
const a01 = a[1];
|
|
313
|
+
const a02 = a[2];
|
|
314
|
+
const a03 = a[3];
|
|
315
|
+
const a10 = a[4];
|
|
316
|
+
const a11 = a[5];
|
|
317
|
+
const a12 = a[6];
|
|
318
|
+
const a13 = a[7];
|
|
319
|
+
const a20 = a[8];
|
|
320
|
+
const a21 = a[9];
|
|
321
|
+
const a22 = a[10];
|
|
322
|
+
const a23 = a[11];
|
|
323
|
+
const a30 = a[12];
|
|
324
|
+
const a31 = a[13];
|
|
325
|
+
const a32 = a[14];
|
|
326
|
+
const a33 = a[15];
|
|
327
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
328
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
329
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
330
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
331
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
332
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
333
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
334
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
335
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
336
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
337
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
338
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
339
|
+
out[0] = a11 * b11 - a12 * b10 + a13 * b09;
|
|
340
|
+
out[1] = a02 * b10 - a01 * b11 - a03 * b09;
|
|
341
|
+
out[2] = a31 * b05 - a32 * b04 + a33 * b03;
|
|
342
|
+
out[3] = a22 * b04 - a21 * b05 - a23 * b03;
|
|
343
|
+
out[4] = a12 * b08 - a10 * b11 - a13 * b07;
|
|
344
|
+
out[5] = a00 * b11 - a02 * b08 + a03 * b07;
|
|
345
|
+
out[6] = a32 * b02 - a30 * b05 - a33 * b01;
|
|
346
|
+
out[7] = a20 * b05 - a22 * b02 + a23 * b01;
|
|
347
|
+
out[8] = a10 * b10 - a11 * b08 + a13 * b06;
|
|
348
|
+
out[9] = a01 * b08 - a00 * b10 - a03 * b06;
|
|
349
|
+
out[10] = a30 * b04 - a31 * b02 + a33 * b00;
|
|
350
|
+
out[11] = a21 * b02 - a20 * b04 - a23 * b00;
|
|
351
|
+
out[12] = a11 * b07 - a10 * b09 - a12 * b06;
|
|
352
|
+
out[13] = a00 * b09 - a01 * b07 + a02 * b06;
|
|
353
|
+
out[14] = a31 * b01 - a30 * b03 - a32 * b00;
|
|
354
|
+
out[15] = a20 * b03 - a21 * b01 + a22 * b00;
|
|
355
|
+
return out;
|
|
264
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Calculates the determinant of a mat4
|
|
359
|
+
*
|
|
360
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
361
|
+
* @returns {Number} determinant of a
|
|
362
|
+
*/
|
|
265
363
|
export function determinant(a) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
364
|
+
const a00 = a[0];
|
|
365
|
+
const a01 = a[1];
|
|
366
|
+
const a02 = a[2];
|
|
367
|
+
const a03 = a[3];
|
|
368
|
+
const a10 = a[4];
|
|
369
|
+
const a11 = a[5];
|
|
370
|
+
const a12 = a[6];
|
|
371
|
+
const a13 = a[7];
|
|
372
|
+
const a20 = a[8];
|
|
373
|
+
const a21 = a[9];
|
|
374
|
+
const a22 = a[10];
|
|
375
|
+
const a23 = a[11];
|
|
376
|
+
const a30 = a[12];
|
|
377
|
+
const a31 = a[13];
|
|
378
|
+
const a32 = a[14];
|
|
379
|
+
const a33 = a[15];
|
|
380
|
+
const b0 = a00 * a11 - a01 * a10;
|
|
381
|
+
const b1 = a00 * a12 - a02 * a10;
|
|
382
|
+
const b2 = a01 * a12 - a02 * a11;
|
|
383
|
+
const b3 = a20 * a31 - a21 * a30;
|
|
384
|
+
const b4 = a20 * a32 - a22 * a30;
|
|
385
|
+
const b5 = a21 * a32 - a22 * a31;
|
|
386
|
+
const b6 = a00 * b5 - a01 * b4 + a02 * b3;
|
|
387
|
+
const b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
388
|
+
const b8 = a20 * b2 - a21 * b1 + a22 * b0;
|
|
389
|
+
const b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
390
|
+
// Calculate the determinant
|
|
391
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
293
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Multiplies two mat4s
|
|
395
|
+
*
|
|
396
|
+
* @param {mat4} out the receiving matrix
|
|
397
|
+
* @param {ReadonlyMat4} a the first operand
|
|
398
|
+
* @param {ReadonlyMat4} b the second operand
|
|
399
|
+
* @returns {mat4} out
|
|
400
|
+
*/
|
|
294
401
|
export function multiply(out, a, b) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
402
|
+
const a00 = a[0];
|
|
403
|
+
const a01 = a[1];
|
|
404
|
+
const a02 = a[2];
|
|
405
|
+
const a03 = a[3];
|
|
406
|
+
const a10 = a[4];
|
|
407
|
+
const a11 = a[5];
|
|
408
|
+
const a12 = a[6];
|
|
409
|
+
const a13 = a[7];
|
|
410
|
+
const a20 = a[8];
|
|
411
|
+
const a21 = a[9];
|
|
412
|
+
const a22 = a[10];
|
|
413
|
+
const a23 = a[11];
|
|
414
|
+
const a30 = a[12];
|
|
415
|
+
const a31 = a[13];
|
|
416
|
+
const a32 = a[14];
|
|
417
|
+
const a33 = a[15];
|
|
418
|
+
// Cache only the current line of the second matrix
|
|
419
|
+
let b0 = b[0];
|
|
420
|
+
let b1 = b[1];
|
|
421
|
+
let b2 = b[2];
|
|
422
|
+
let b3 = b[3];
|
|
423
|
+
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
424
|
+
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
425
|
+
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
426
|
+
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
427
|
+
b0 = b[4];
|
|
428
|
+
b1 = b[5];
|
|
429
|
+
b2 = b[6];
|
|
430
|
+
b3 = b[7];
|
|
431
|
+
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
432
|
+
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
433
|
+
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
434
|
+
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
435
|
+
b0 = b[8];
|
|
436
|
+
b1 = b[9];
|
|
437
|
+
b2 = b[10];
|
|
438
|
+
b3 = b[11];
|
|
439
|
+
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
440
|
+
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
441
|
+
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
442
|
+
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
443
|
+
b0 = b[12];
|
|
444
|
+
b1 = b[13];
|
|
445
|
+
b2 = b[14];
|
|
446
|
+
b3 = b[15];
|
|
447
|
+
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
448
|
+
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
449
|
+
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
450
|
+
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
451
|
+
return out;
|
|
344
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* Translate a mat4 by the given vector
|
|
455
|
+
*
|
|
456
|
+
* @param {mat4} out the receiving matrix
|
|
457
|
+
* @param {ReadonlyMat4} a the matrix to translate
|
|
458
|
+
* @param {ReadonlyVec3} v vector to translate by
|
|
459
|
+
* @returns {mat4} out
|
|
460
|
+
*/
|
|
345
461
|
export function translate(out, a, v) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
462
|
+
const x = v[0];
|
|
463
|
+
const y = v[1];
|
|
464
|
+
const z = v[2];
|
|
465
|
+
let a00;
|
|
466
|
+
let a01;
|
|
467
|
+
let a02;
|
|
468
|
+
let a03;
|
|
469
|
+
let a10;
|
|
470
|
+
let a11;
|
|
471
|
+
let a12;
|
|
472
|
+
let a13;
|
|
473
|
+
let a20;
|
|
474
|
+
let a21;
|
|
475
|
+
let a22;
|
|
476
|
+
let a23;
|
|
477
|
+
if (a === out) {
|
|
478
|
+
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
|
479
|
+
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
|
480
|
+
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
|
481
|
+
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
a00 = a[0];
|
|
485
|
+
a01 = a[1];
|
|
486
|
+
a02 = a[2];
|
|
487
|
+
a03 = a[3];
|
|
488
|
+
a10 = a[4];
|
|
489
|
+
a11 = a[5];
|
|
490
|
+
a12 = a[6];
|
|
491
|
+
a13 = a[7];
|
|
492
|
+
a20 = a[8];
|
|
493
|
+
a21 = a[9];
|
|
494
|
+
a22 = a[10];
|
|
495
|
+
a23 = a[11];
|
|
496
|
+
out[0] = a00;
|
|
497
|
+
out[1] = a01;
|
|
498
|
+
out[2] = a02;
|
|
499
|
+
out[3] = a03;
|
|
500
|
+
out[4] = a10;
|
|
501
|
+
out[5] = a11;
|
|
502
|
+
out[6] = a12;
|
|
503
|
+
out[7] = a13;
|
|
504
|
+
out[8] = a20;
|
|
505
|
+
out[9] = a21;
|
|
506
|
+
out[10] = a22;
|
|
507
|
+
out[11] = a23;
|
|
508
|
+
out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
|
509
|
+
out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
|
510
|
+
out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
|
511
|
+
out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
|
512
|
+
}
|
|
513
|
+
return out;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Scales the mat4 by the dimensions in the given vec3 not using vectorization
|
|
517
|
+
*
|
|
518
|
+
* @param {mat4} out the receiving matrix
|
|
519
|
+
* @param {ReadonlyMat4} a the matrix to scale
|
|
520
|
+
* @param {ReadonlyVec3} v the vec3 to scale the matrix by
|
|
521
|
+
* @returns {mat4} out
|
|
522
|
+
**/
|
|
523
|
+
export function scale(out, a, v) {
|
|
524
|
+
const x = v[0];
|
|
525
|
+
const y = v[1];
|
|
526
|
+
const z = v[2];
|
|
527
|
+
out[0] = a[0] * x;
|
|
528
|
+
out[1] = a[1] * x;
|
|
529
|
+
out[2] = a[2] * x;
|
|
530
|
+
out[3] = a[3] * x;
|
|
531
|
+
out[4] = a[4] * y;
|
|
532
|
+
out[5] = a[5] * y;
|
|
533
|
+
out[6] = a[6] * y;
|
|
534
|
+
out[7] = a[7] * y;
|
|
535
|
+
out[8] = a[8] * z;
|
|
536
|
+
out[9] = a[9] * z;
|
|
537
|
+
out[10] = a[10] * z;
|
|
538
|
+
out[11] = a[11] * z;
|
|
539
|
+
out[12] = a[12];
|
|
540
|
+
out[13] = a[13];
|
|
541
|
+
out[14] = a[14];
|
|
542
|
+
out[15] = a[15];
|
|
543
|
+
return out;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Rotates a mat4 by the given angle around the given axis
|
|
547
|
+
*
|
|
548
|
+
* @param {mat4} out the receiving matrix
|
|
549
|
+
* @param {ReadonlyMat4} a the matrix to rotate
|
|
550
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
551
|
+
* @param {ReadonlyVec3} axis the axis to rotate around
|
|
552
|
+
* @returns {mat4} out
|
|
553
|
+
*/
|
|
554
|
+
export function rotate(out, a, rad, axis) {
|
|
555
|
+
let x = axis[0];
|
|
556
|
+
let y = axis[1];
|
|
557
|
+
let z = axis[2];
|
|
558
|
+
let len = Math.sqrt(x * x + y * y + z * z);
|
|
559
|
+
let c;
|
|
560
|
+
let s;
|
|
561
|
+
let t;
|
|
562
|
+
let a00;
|
|
563
|
+
let a01;
|
|
564
|
+
let a02;
|
|
565
|
+
let a03;
|
|
566
|
+
let a10;
|
|
567
|
+
let a11;
|
|
568
|
+
let a12;
|
|
569
|
+
let a13;
|
|
570
|
+
let a20;
|
|
571
|
+
let a21;
|
|
572
|
+
let a22;
|
|
573
|
+
let a23;
|
|
574
|
+
let b00;
|
|
575
|
+
let b01;
|
|
576
|
+
let b02;
|
|
577
|
+
let b10;
|
|
578
|
+
let b11;
|
|
579
|
+
let b12;
|
|
580
|
+
let b20;
|
|
581
|
+
let b21;
|
|
582
|
+
let b22;
|
|
583
|
+
if (len < glMatrix.EPSILON) {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
len = 1 / len;
|
|
587
|
+
x *= len;
|
|
588
|
+
y *= len;
|
|
589
|
+
z *= len;
|
|
590
|
+
s = Math.sin(rad);
|
|
591
|
+
c = Math.cos(rad);
|
|
592
|
+
t = 1 - c;
|
|
368
593
|
a00 = a[0];
|
|
369
594
|
a01 = a[1];
|
|
370
595
|
a02 = a[2];
|
|
@@ -377,1079 +602,1394 @@ export function translate(out, a, v) {
|
|
|
377
602
|
a21 = a[9];
|
|
378
603
|
a22 = a[10];
|
|
379
604
|
a23 = a[11];
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
out[
|
|
392
|
-
out[
|
|
393
|
-
out[
|
|
394
|
-
out[
|
|
395
|
-
out[
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
out[7] = a[7] * y;
|
|
412
|
-
out[8] = a[8] * z;
|
|
413
|
-
out[9] = a[9] * z;
|
|
414
|
-
out[10] = a[10] * z;
|
|
415
|
-
out[11] = a[11] * z;
|
|
416
|
-
out[12] = a[12];
|
|
417
|
-
out[13] = a[13];
|
|
418
|
-
out[14] = a[14];
|
|
419
|
-
out[15] = a[15];
|
|
420
|
-
return out;
|
|
421
|
-
}
|
|
422
|
-
export function rotate(out, a, rad, axis) {
|
|
423
|
-
let x = axis[0];
|
|
424
|
-
let y = axis[1];
|
|
425
|
-
let z = axis[2];
|
|
426
|
-
let len = Math.sqrt(x * x + y * y + z * z);
|
|
427
|
-
let c;
|
|
428
|
-
let s;
|
|
429
|
-
let t;
|
|
430
|
-
let a00;
|
|
431
|
-
let a01;
|
|
432
|
-
let a02;
|
|
433
|
-
let a03;
|
|
434
|
-
let a10;
|
|
435
|
-
let a11;
|
|
436
|
-
let a12;
|
|
437
|
-
let a13;
|
|
438
|
-
let a20;
|
|
439
|
-
let a21;
|
|
440
|
-
let a22;
|
|
441
|
-
let a23;
|
|
442
|
-
let b00;
|
|
443
|
-
let b01;
|
|
444
|
-
let b02;
|
|
445
|
-
let b10;
|
|
446
|
-
let b11;
|
|
447
|
-
let b12;
|
|
448
|
-
let b20;
|
|
449
|
-
let b21;
|
|
450
|
-
let b22;
|
|
451
|
-
|
|
452
|
-
if (len < glMatrix.EPSILON) {
|
|
453
|
-
return null;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
len = 1 / len;
|
|
457
|
-
x *= len;
|
|
458
|
-
y *= len;
|
|
459
|
-
z *= len;
|
|
460
|
-
s = Math.sin(rad);
|
|
461
|
-
c = Math.cos(rad);
|
|
462
|
-
t = 1 - c;
|
|
463
|
-
a00 = a[0];
|
|
464
|
-
a01 = a[1];
|
|
465
|
-
a02 = a[2];
|
|
466
|
-
a03 = a[3];
|
|
467
|
-
a10 = a[4];
|
|
468
|
-
a11 = a[5];
|
|
469
|
-
a12 = a[6];
|
|
470
|
-
a13 = a[7];
|
|
471
|
-
a20 = a[8];
|
|
472
|
-
a21 = a[9];
|
|
473
|
-
a22 = a[10];
|
|
474
|
-
a23 = a[11];
|
|
475
|
-
b00 = x * x * t + c;
|
|
476
|
-
b01 = y * x * t + z * s;
|
|
477
|
-
b02 = z * x * t - y * s;
|
|
478
|
-
b10 = x * y * t - z * s;
|
|
479
|
-
b11 = y * y * t + c;
|
|
480
|
-
b12 = z * y * t + x * s;
|
|
481
|
-
b20 = x * z * t + y * s;
|
|
482
|
-
b21 = y * z * t - x * s;
|
|
483
|
-
b22 = z * z * t + c;
|
|
484
|
-
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
485
|
-
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
486
|
-
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
487
|
-
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
488
|
-
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
489
|
-
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
490
|
-
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
491
|
-
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
492
|
-
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
493
|
-
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
494
|
-
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
495
|
-
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
496
|
-
|
|
497
|
-
if (a !== out) {
|
|
498
|
-
out[12] = a[12];
|
|
499
|
-
out[13] = a[13];
|
|
500
|
-
out[14] = a[14];
|
|
501
|
-
out[15] = a[15];
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
return out;
|
|
605
|
+
// Construct the elements of the rotation matrix
|
|
606
|
+
b00 = x * x * t + c;
|
|
607
|
+
b01 = y * x * t + z * s;
|
|
608
|
+
b02 = z * x * t - y * s;
|
|
609
|
+
b10 = x * y * t - z * s;
|
|
610
|
+
b11 = y * y * t + c;
|
|
611
|
+
b12 = z * y * t + x * s;
|
|
612
|
+
b20 = x * z * t + y * s;
|
|
613
|
+
b21 = y * z * t - x * s;
|
|
614
|
+
b22 = z * z * t + c;
|
|
615
|
+
// Perform rotation-specific matrix multiplication
|
|
616
|
+
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
617
|
+
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
618
|
+
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
619
|
+
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
620
|
+
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
621
|
+
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
622
|
+
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
623
|
+
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
624
|
+
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
625
|
+
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
626
|
+
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
627
|
+
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
628
|
+
if (a !== out) {
|
|
629
|
+
// If the source and destination differ, copy the unchanged last row
|
|
630
|
+
out[12] = a[12];
|
|
631
|
+
out[13] = a[13];
|
|
632
|
+
out[14] = a[14];
|
|
633
|
+
out[15] = a[15];
|
|
634
|
+
}
|
|
635
|
+
return out;
|
|
505
636
|
}
|
|
637
|
+
/**
|
|
638
|
+
* Rotates a matrix by the given angle around the X axis
|
|
639
|
+
*
|
|
640
|
+
* @param {mat4} out the receiving matrix
|
|
641
|
+
* @param {ReadonlyMat4} a the matrix to rotate
|
|
642
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
643
|
+
* @returns {mat4} out
|
|
644
|
+
*/
|
|
506
645
|
export function rotateX(out, a, rad) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
646
|
+
const s = Math.sin(rad);
|
|
647
|
+
const c = Math.cos(rad);
|
|
648
|
+
const a10 = a[4];
|
|
649
|
+
const a11 = a[5];
|
|
650
|
+
const a12 = a[6];
|
|
651
|
+
const a13 = a[7];
|
|
652
|
+
const a20 = a[8];
|
|
653
|
+
const a21 = a[9];
|
|
654
|
+
const a22 = a[10];
|
|
655
|
+
const a23 = a[11];
|
|
656
|
+
if (a !== out) {
|
|
657
|
+
// If the source and destination differ, copy the unchanged rows
|
|
658
|
+
out[0] = a[0];
|
|
659
|
+
out[1] = a[1];
|
|
660
|
+
out[2] = a[2];
|
|
661
|
+
out[3] = a[3];
|
|
662
|
+
out[12] = a[12];
|
|
663
|
+
out[13] = a[13];
|
|
664
|
+
out[14] = a[14];
|
|
665
|
+
out[15] = a[15];
|
|
666
|
+
}
|
|
667
|
+
// Perform axis-specific matrix multiplication
|
|
668
|
+
out[4] = a10 * c + a20 * s;
|
|
669
|
+
out[5] = a11 * c + a21 * s;
|
|
670
|
+
out[6] = a12 * c + a22 * s;
|
|
671
|
+
out[7] = a13 * c + a23 * s;
|
|
672
|
+
out[8] = a20 * c - a10 * s;
|
|
673
|
+
out[9] = a21 * c - a11 * s;
|
|
674
|
+
out[10] = a22 * c - a12 * s;
|
|
675
|
+
out[11] = a23 * c - a13 * s;
|
|
676
|
+
return out;
|
|
538
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* Rotates a matrix by the given angle around the Y axis
|
|
680
|
+
*
|
|
681
|
+
* @param {mat4} out the receiving matrix
|
|
682
|
+
* @param {ReadonlyMat4} a the matrix to rotate
|
|
683
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
684
|
+
* @returns {mat4} out
|
|
685
|
+
*/
|
|
539
686
|
export function rotateY(out, a, rad) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
687
|
+
const s = Math.sin(rad);
|
|
688
|
+
const c = Math.cos(rad);
|
|
689
|
+
const a00 = a[0];
|
|
690
|
+
const a01 = a[1];
|
|
691
|
+
const a02 = a[2];
|
|
692
|
+
const a03 = a[3];
|
|
693
|
+
const a20 = a[8];
|
|
694
|
+
const a21 = a[9];
|
|
695
|
+
const a22 = a[10];
|
|
696
|
+
const a23 = a[11];
|
|
697
|
+
if (a !== out) {
|
|
698
|
+
// If the source and destination differ, copy the unchanged rows
|
|
699
|
+
out[4] = a[4];
|
|
700
|
+
out[5] = a[5];
|
|
701
|
+
out[6] = a[6];
|
|
702
|
+
out[7] = a[7];
|
|
703
|
+
out[12] = a[12];
|
|
704
|
+
out[13] = a[13];
|
|
705
|
+
out[14] = a[14];
|
|
706
|
+
out[15] = a[15];
|
|
707
|
+
}
|
|
708
|
+
// Perform axis-specific matrix multiplication
|
|
709
|
+
out[0] = a00 * c - a20 * s;
|
|
710
|
+
out[1] = a01 * c - a21 * s;
|
|
711
|
+
out[2] = a02 * c - a22 * s;
|
|
712
|
+
out[3] = a03 * c - a23 * s;
|
|
713
|
+
out[8] = a00 * s + a20 * c;
|
|
714
|
+
out[9] = a01 * s + a21 * c;
|
|
715
|
+
out[10] = a02 * s + a22 * c;
|
|
716
|
+
out[11] = a03 * s + a23 * c;
|
|
717
|
+
return out;
|
|
571
718
|
}
|
|
719
|
+
/**
|
|
720
|
+
* Rotates a matrix by the given angle around the Z axis
|
|
721
|
+
*
|
|
722
|
+
* @param {mat4} out the receiving matrix
|
|
723
|
+
* @param {ReadonlyMat4} a the matrix to rotate
|
|
724
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
725
|
+
* @returns {mat4} out
|
|
726
|
+
*/
|
|
572
727
|
export function rotateZ(out, a, rad) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
728
|
+
const s = Math.sin(rad);
|
|
729
|
+
const c = Math.cos(rad);
|
|
730
|
+
const a00 = a[0];
|
|
731
|
+
const a01 = a[1];
|
|
732
|
+
const a02 = a[2];
|
|
733
|
+
const a03 = a[3];
|
|
734
|
+
const a10 = a[4];
|
|
735
|
+
const a11 = a[5];
|
|
736
|
+
const a12 = a[6];
|
|
737
|
+
const a13 = a[7];
|
|
738
|
+
if (a !== out) {
|
|
739
|
+
// If the source and destination differ, copy the unchanged last row
|
|
740
|
+
out[8] = a[8];
|
|
741
|
+
out[9] = a[9];
|
|
742
|
+
out[10] = a[10];
|
|
743
|
+
out[11] = a[11];
|
|
744
|
+
out[12] = a[12];
|
|
745
|
+
out[13] = a[13];
|
|
746
|
+
out[14] = a[14];
|
|
747
|
+
out[15] = a[15];
|
|
748
|
+
}
|
|
749
|
+
// Perform axis-specific matrix multiplication
|
|
750
|
+
out[0] = a00 * c + a10 * s;
|
|
751
|
+
out[1] = a01 * c + a11 * s;
|
|
752
|
+
out[2] = a02 * c + a12 * s;
|
|
753
|
+
out[3] = a03 * c + a13 * s;
|
|
754
|
+
out[4] = a10 * c - a00 * s;
|
|
755
|
+
out[5] = a11 * c - a01 * s;
|
|
756
|
+
out[6] = a12 * c - a02 * s;
|
|
757
|
+
out[7] = a13 * c - a03 * s;
|
|
758
|
+
return out;
|
|
604
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Creates a matrix from a vector translation
|
|
762
|
+
* This is equivalent to (but much faster than):
|
|
763
|
+
*
|
|
764
|
+
* mat4.identity(dest);
|
|
765
|
+
* mat4.translate(dest, dest, vec);
|
|
766
|
+
*
|
|
767
|
+
* @param {mat4} out mat4 receiving operation result
|
|
768
|
+
* @param {ReadonlyVec3} v Translation vector
|
|
769
|
+
* @returns {mat4} out
|
|
770
|
+
*/
|
|
605
771
|
export function fromTranslation(out, v) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
772
|
+
out[0] = 1;
|
|
773
|
+
out[1] = 0;
|
|
774
|
+
out[2] = 0;
|
|
775
|
+
out[3] = 0;
|
|
776
|
+
out[4] = 0;
|
|
777
|
+
out[5] = 1;
|
|
778
|
+
out[6] = 0;
|
|
779
|
+
out[7] = 0;
|
|
780
|
+
out[8] = 0;
|
|
781
|
+
out[9] = 0;
|
|
782
|
+
out[10] = 1;
|
|
783
|
+
out[11] = 0;
|
|
784
|
+
out[12] = v[0];
|
|
785
|
+
out[13] = v[1];
|
|
786
|
+
out[14] = v[2];
|
|
787
|
+
out[15] = 1;
|
|
788
|
+
return out;
|
|
623
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* Creates a matrix from a vector scaling
|
|
792
|
+
* This is equivalent to (but much faster than):
|
|
793
|
+
*
|
|
794
|
+
* mat4.identity(dest);
|
|
795
|
+
* mat4.scale(dest, dest, vec);
|
|
796
|
+
*
|
|
797
|
+
* @param {mat4} out mat4 receiving operation result
|
|
798
|
+
* @param {ReadonlyVec3} v Scaling vector
|
|
799
|
+
* @returns {mat4} out
|
|
800
|
+
*/
|
|
624
801
|
export function fromScaling(out, v) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
802
|
+
out[0] = v[0];
|
|
803
|
+
out[1] = 0;
|
|
804
|
+
out[2] = 0;
|
|
805
|
+
out[3] = 0;
|
|
806
|
+
out[4] = 0;
|
|
807
|
+
out[5] = v[1];
|
|
808
|
+
out[6] = 0;
|
|
809
|
+
out[7] = 0;
|
|
810
|
+
out[8] = 0;
|
|
811
|
+
out[9] = 0;
|
|
812
|
+
out[10] = v[2];
|
|
813
|
+
out[11] = 0;
|
|
814
|
+
out[12] = 0;
|
|
815
|
+
out[13] = 0;
|
|
816
|
+
out[14] = 0;
|
|
817
|
+
out[15] = 1;
|
|
818
|
+
return out;
|
|
642
819
|
}
|
|
820
|
+
/**
|
|
821
|
+
* Creates a matrix from a given angle around a given axis
|
|
822
|
+
* This is equivalent to (but much faster than):
|
|
823
|
+
*
|
|
824
|
+
* mat4.identity(dest);
|
|
825
|
+
* mat4.rotate(dest, dest, rad, axis);
|
|
826
|
+
*
|
|
827
|
+
* @param {mat4} out mat4 receiving operation result
|
|
828
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
829
|
+
* @param {ReadonlyVec3} axis the axis to rotate around
|
|
830
|
+
* @returns {mat4} out
|
|
831
|
+
*/
|
|
643
832
|
export function fromRotation(out, rad, axis) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return out;
|
|
833
|
+
let x = axis[0];
|
|
834
|
+
let y = axis[1];
|
|
835
|
+
let z = axis[2];
|
|
836
|
+
let len = Math.sqrt(x * x + y * y + z * z);
|
|
837
|
+
let c;
|
|
838
|
+
let s;
|
|
839
|
+
let t;
|
|
840
|
+
if (len < glMatrix.EPSILON) {
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
len = 1 / len;
|
|
844
|
+
x *= len;
|
|
845
|
+
y *= len;
|
|
846
|
+
z *= len;
|
|
847
|
+
s = Math.sin(rad);
|
|
848
|
+
c = Math.cos(rad);
|
|
849
|
+
t = 1 - c;
|
|
850
|
+
// Perform rotation-specific matrix multiplication
|
|
851
|
+
out[0] = x * x * t + c;
|
|
852
|
+
out[1] = y * x * t + z * s;
|
|
853
|
+
out[2] = z * x * t - y * s;
|
|
854
|
+
out[3] = 0;
|
|
855
|
+
out[4] = x * y * t - z * s;
|
|
856
|
+
out[5] = y * y * t + c;
|
|
857
|
+
out[6] = z * y * t + x * s;
|
|
858
|
+
out[7] = 0;
|
|
859
|
+
out[8] = x * z * t + y * s;
|
|
860
|
+
out[9] = y * z * t - x * s;
|
|
861
|
+
out[10] = z * z * t + c;
|
|
862
|
+
out[11] = 0;
|
|
863
|
+
out[12] = 0;
|
|
864
|
+
out[13] = 0;
|
|
865
|
+
out[14] = 0;
|
|
866
|
+
out[15] = 1;
|
|
867
|
+
return out;
|
|
680
868
|
}
|
|
869
|
+
/**
|
|
870
|
+
* Creates a matrix from the given angle around the X axis
|
|
871
|
+
* This is equivalent to (but much faster than):
|
|
872
|
+
*
|
|
873
|
+
* mat4.identity(dest);
|
|
874
|
+
* mat4.rotateX(dest, dest, rad);
|
|
875
|
+
*
|
|
876
|
+
* @param {mat4} out mat4 receiving operation result
|
|
877
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
878
|
+
* @returns {mat4} out
|
|
879
|
+
*/
|
|
681
880
|
export function fromXRotation(out, rad) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
881
|
+
const s = Math.sin(rad);
|
|
882
|
+
const c = Math.cos(rad);
|
|
883
|
+
// Perform axis-specific matrix multiplication
|
|
884
|
+
out[0] = 1;
|
|
885
|
+
out[1] = 0;
|
|
886
|
+
out[2] = 0;
|
|
887
|
+
out[3] = 0;
|
|
888
|
+
out[4] = 0;
|
|
889
|
+
out[5] = c;
|
|
890
|
+
out[6] = s;
|
|
891
|
+
out[7] = 0;
|
|
892
|
+
out[8] = 0;
|
|
893
|
+
out[9] = -s;
|
|
894
|
+
out[10] = c;
|
|
895
|
+
out[11] = 0;
|
|
896
|
+
out[12] = 0;
|
|
897
|
+
out[13] = 0;
|
|
898
|
+
out[14] = 0;
|
|
899
|
+
out[15] = 1;
|
|
900
|
+
return out;
|
|
701
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Creates a matrix from the given angle around the Y axis
|
|
904
|
+
* This is equivalent to (but much faster than):
|
|
905
|
+
*
|
|
906
|
+
* mat4.identity(dest);
|
|
907
|
+
* mat4.rotateY(dest, dest, rad);
|
|
908
|
+
*
|
|
909
|
+
* @param {mat4} out mat4 receiving operation result
|
|
910
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
911
|
+
* @returns {mat4} out
|
|
912
|
+
*/
|
|
702
913
|
export function fromYRotation(out, rad) {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
914
|
+
const s = Math.sin(rad);
|
|
915
|
+
const c = Math.cos(rad);
|
|
916
|
+
// Perform axis-specific matrix multiplication
|
|
917
|
+
out[0] = c;
|
|
918
|
+
out[1] = 0;
|
|
919
|
+
out[2] = -s;
|
|
920
|
+
out[3] = 0;
|
|
921
|
+
out[4] = 0;
|
|
922
|
+
out[5] = 1;
|
|
923
|
+
out[6] = 0;
|
|
924
|
+
out[7] = 0;
|
|
925
|
+
out[8] = s;
|
|
926
|
+
out[9] = 0;
|
|
927
|
+
out[10] = c;
|
|
928
|
+
out[11] = 0;
|
|
929
|
+
out[12] = 0;
|
|
930
|
+
out[13] = 0;
|
|
931
|
+
out[14] = 0;
|
|
932
|
+
out[15] = 1;
|
|
933
|
+
return out;
|
|
722
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Creates a matrix from the given angle around the Z axis
|
|
937
|
+
* This is equivalent to (but much faster than):
|
|
938
|
+
*
|
|
939
|
+
* mat4.identity(dest);
|
|
940
|
+
* mat4.rotateZ(dest, dest, rad);
|
|
941
|
+
*
|
|
942
|
+
* @param {mat4} out mat4 receiving operation result
|
|
943
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
944
|
+
* @returns {mat4} out
|
|
945
|
+
*/
|
|
723
946
|
export function fromZRotation(out, rad) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
947
|
+
const s = Math.sin(rad);
|
|
948
|
+
const c = Math.cos(rad);
|
|
949
|
+
// Perform axis-specific matrix multiplication
|
|
950
|
+
out[0] = c;
|
|
951
|
+
out[1] = s;
|
|
952
|
+
out[2] = 0;
|
|
953
|
+
out[3] = 0;
|
|
954
|
+
out[4] = -s;
|
|
955
|
+
out[5] = c;
|
|
956
|
+
out[6] = 0;
|
|
957
|
+
out[7] = 0;
|
|
958
|
+
out[8] = 0;
|
|
959
|
+
out[9] = 0;
|
|
960
|
+
out[10] = 1;
|
|
961
|
+
out[11] = 0;
|
|
962
|
+
out[12] = 0;
|
|
963
|
+
out[13] = 0;
|
|
964
|
+
out[14] = 0;
|
|
965
|
+
out[15] = 1;
|
|
966
|
+
return out;
|
|
743
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Creates a matrix from a quaternion rotation and vector translation
|
|
970
|
+
* This is equivalent to (but much faster than):
|
|
971
|
+
*
|
|
972
|
+
* mat4.identity(dest);
|
|
973
|
+
* mat4.translate(dest, vec);
|
|
974
|
+
* let quatMat = mat4.create();
|
|
975
|
+
* quat4.toMat4(quat, quatMat);
|
|
976
|
+
* mat4.multiply(dest, quatMat);
|
|
977
|
+
*
|
|
978
|
+
* @param {mat4} out mat4 receiving operation result
|
|
979
|
+
* @param {quat4} q Rotation quaternion
|
|
980
|
+
* @param {ReadonlyVec3} v Translation vector
|
|
981
|
+
* @returns {mat4} out
|
|
982
|
+
*/
|
|
744
983
|
export function fromRotationTranslation(out, q, v) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
984
|
+
// Quaternion math
|
|
985
|
+
const x = q[0];
|
|
986
|
+
const y = q[1];
|
|
987
|
+
const z = q[2];
|
|
988
|
+
const w = q[3];
|
|
989
|
+
const x2 = x + x;
|
|
990
|
+
const y2 = y + y;
|
|
991
|
+
const z2 = z + z;
|
|
992
|
+
const xx = x * x2;
|
|
993
|
+
const xy = x * y2;
|
|
994
|
+
const xz = x * z2;
|
|
995
|
+
const yy = y * y2;
|
|
996
|
+
const yz = y * z2;
|
|
997
|
+
const zz = z * z2;
|
|
998
|
+
const wx = w * x2;
|
|
999
|
+
const wy = w * y2;
|
|
1000
|
+
const wz = w * z2;
|
|
1001
|
+
out[0] = 1 - (yy + zz);
|
|
1002
|
+
out[1] = xy + wz;
|
|
1003
|
+
out[2] = xz - wy;
|
|
1004
|
+
out[3] = 0;
|
|
1005
|
+
out[4] = xy - wz;
|
|
1006
|
+
out[5] = 1 - (xx + zz);
|
|
1007
|
+
out[6] = yz + wx;
|
|
1008
|
+
out[7] = 0;
|
|
1009
|
+
out[8] = xz + wy;
|
|
1010
|
+
out[9] = yz - wx;
|
|
1011
|
+
out[10] = 1 - (xx + yy);
|
|
1012
|
+
out[11] = 0;
|
|
1013
|
+
out[12] = v[0];
|
|
1014
|
+
out[13] = v[1];
|
|
1015
|
+
out[14] = v[2];
|
|
1016
|
+
out[15] = 1;
|
|
1017
|
+
return out;
|
|
778
1018
|
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Creates a new mat4 from a dual quat.
|
|
1021
|
+
*
|
|
1022
|
+
* @param {mat4} out Matrix
|
|
1023
|
+
* @param {ReadonlyQuat2} a Dual Quaternion
|
|
1024
|
+
* @returns {mat4} mat4 receiving operation result
|
|
1025
|
+
*/
|
|
779
1026
|
export function fromQuat2(out, a) {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1027
|
+
const translation = new glMatrix.ARRAY_TYPE(3);
|
|
1028
|
+
const bx = -a[0];
|
|
1029
|
+
const by = -a[1];
|
|
1030
|
+
const bz = -a[2];
|
|
1031
|
+
const bw = a[3];
|
|
1032
|
+
const ax = a[4];
|
|
1033
|
+
const ay = a[5];
|
|
1034
|
+
const az = a[6];
|
|
1035
|
+
const aw = a[7];
|
|
1036
|
+
const magnitude = bx * bx + by * by + bz * bz + bw * bw;
|
|
1037
|
+
// Only scale if it makes sense
|
|
1038
|
+
if (magnitude > 0) {
|
|
1039
|
+
translation[0] = ((ax * bw + aw * bx + ay * bz - az * by) * 2) / magnitude;
|
|
1040
|
+
translation[1] = ((ay * bw + aw * by + az * bx - ax * bz) * 2) / magnitude;
|
|
1041
|
+
translation[2] = ((az * bw + aw * bz + ax * by - ay * bx) * 2) / magnitude;
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
|
|
1045
|
+
translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
|
|
1046
|
+
translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
|
|
1047
|
+
}
|
|
1048
|
+
fromRotationTranslation(out, a, translation);
|
|
1049
|
+
return out;
|
|
803
1050
|
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Returns the translation vector component of a transformation
|
|
1053
|
+
* matrix. If a matrix is built with fromRotationTranslation,
|
|
1054
|
+
* the returned vector will be the same as the translation vector
|
|
1055
|
+
* originally supplied.
|
|
1056
|
+
* @param {vec3} out Vector to receive translation component
|
|
1057
|
+
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
1058
|
+
* @return {vec3} out
|
|
1059
|
+
*/
|
|
804
1060
|
export function getTranslation(out, mat) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1061
|
+
out[0] = mat[12];
|
|
1062
|
+
out[1] = mat[13];
|
|
1063
|
+
out[2] = mat[14];
|
|
1064
|
+
return out;
|
|
809
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Returns the scaling factor component of a transformation
|
|
1068
|
+
* matrix. If a matrix is built with fromRotationTranslationScale
|
|
1069
|
+
* with a normalized Quaternion paramter, the returned vector will be
|
|
1070
|
+
* the same as the scaling vector
|
|
1071
|
+
* originally supplied.
|
|
1072
|
+
* @param {vec3} out Vector to receive scaling factor component
|
|
1073
|
+
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
1074
|
+
* @return {vec3} out
|
|
1075
|
+
*/
|
|
810
1076
|
export function getScaling(out, mat) {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1077
|
+
const m11 = mat[0];
|
|
1078
|
+
const m12 = mat[1];
|
|
1079
|
+
const m13 = mat[2];
|
|
1080
|
+
const m21 = mat[4];
|
|
1081
|
+
const m22 = mat[5];
|
|
1082
|
+
const m23 = mat[6];
|
|
1083
|
+
const m31 = mat[8];
|
|
1084
|
+
const m32 = mat[9];
|
|
1085
|
+
const m33 = mat[10];
|
|
1086
|
+
out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
|
|
1087
|
+
out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
|
|
1088
|
+
out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
|
|
1089
|
+
return out;
|
|
824
1090
|
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Returns a quaternion representing the rotational component
|
|
1093
|
+
* of a transformation matrix. If a matrix is built with
|
|
1094
|
+
* fromRotationTranslation, the returned quaternion will be the
|
|
1095
|
+
* same as the quaternion originally supplied.
|
|
1096
|
+
* @param {quat} out Quaternion to receive the rotation component
|
|
1097
|
+
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
1098
|
+
* @return {quat} out
|
|
1099
|
+
*/
|
|
825
1100
|
export function getRotation(out, mat) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
1101
|
+
const scaling = new glMatrix.ARRAY_TYPE(3);
|
|
1102
|
+
getScaling(scaling, mat);
|
|
1103
|
+
const is1 = 1 / scaling[0];
|
|
1104
|
+
const is2 = 1 / scaling[1];
|
|
1105
|
+
const is3 = 1 / scaling[2];
|
|
1106
|
+
const sm11 = mat[0] * is1;
|
|
1107
|
+
const sm12 = mat[1] * is2;
|
|
1108
|
+
const sm13 = mat[2] * is3;
|
|
1109
|
+
const sm21 = mat[4] * is1;
|
|
1110
|
+
const sm22 = mat[5] * is2;
|
|
1111
|
+
const sm23 = mat[6] * is3;
|
|
1112
|
+
const sm31 = mat[8] * is1;
|
|
1113
|
+
const sm32 = mat[9] * is2;
|
|
1114
|
+
const sm33 = mat[10] * is3;
|
|
1115
|
+
const trace = sm11 + sm22 + sm33;
|
|
1116
|
+
let S = 0;
|
|
1117
|
+
if (trace > 0) {
|
|
1118
|
+
S = Math.sqrt(trace + 1.0) * 2;
|
|
1119
|
+
out[3] = 0.25 * S;
|
|
1120
|
+
out[0] = (sm23 - sm32) / S;
|
|
1121
|
+
out[1] = (sm31 - sm13) / S;
|
|
1122
|
+
out[2] = (sm12 - sm21) / S;
|
|
1123
|
+
}
|
|
1124
|
+
else if (sm11 > sm22 && sm11 > sm33) {
|
|
1125
|
+
S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
|
|
1126
|
+
out[3] = (sm23 - sm32) / S;
|
|
1127
|
+
out[0] = 0.25 * S;
|
|
1128
|
+
out[1] = (sm12 + sm21) / S;
|
|
1129
|
+
out[2] = (sm31 + sm13) / S;
|
|
1130
|
+
}
|
|
1131
|
+
else if (sm22 > sm33) {
|
|
1132
|
+
S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
|
|
1133
|
+
out[3] = (sm31 - sm13) / S;
|
|
1134
|
+
out[0] = (sm12 + sm21) / S;
|
|
1135
|
+
out[1] = 0.25 * S;
|
|
1136
|
+
out[2] = (sm23 + sm32) / S;
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
|
|
1140
|
+
out[3] = (sm12 - sm21) / S;
|
|
1141
|
+
out[0] = (sm31 + sm13) / S;
|
|
1142
|
+
out[1] = (sm23 + sm32) / S;
|
|
1143
|
+
out[2] = 0.25 * S;
|
|
1144
|
+
}
|
|
1145
|
+
return out;
|
|
870
1146
|
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Decomposes a transformation matrix into its rotation, translation
|
|
1149
|
+
* and scale components. Returns only the rotation component
|
|
1150
|
+
* @param {quat} out_r Quaternion to receive the rotation component
|
|
1151
|
+
* @param {vec3} out_t Vector to receive the translation vector
|
|
1152
|
+
* @param {vec3} out_s Vector to receive the scaling factor
|
|
1153
|
+
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
1154
|
+
* @returns {quat} out_r
|
|
1155
|
+
*/
|
|
871
1156
|
export function decompose(out_r, out_t, out_s, mat) {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1157
|
+
out_t[0] = mat[12];
|
|
1158
|
+
out_t[1] = mat[13];
|
|
1159
|
+
out_t[2] = mat[14];
|
|
1160
|
+
const m11 = mat[0];
|
|
1161
|
+
const m12 = mat[1];
|
|
1162
|
+
const m13 = mat[2];
|
|
1163
|
+
const m21 = mat[4];
|
|
1164
|
+
const m22 = mat[5];
|
|
1165
|
+
const m23 = mat[6];
|
|
1166
|
+
const m31 = mat[8];
|
|
1167
|
+
const m32 = mat[9];
|
|
1168
|
+
const m33 = mat[10];
|
|
1169
|
+
out_s[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
|
|
1170
|
+
out_s[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
|
|
1171
|
+
out_s[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
|
|
1172
|
+
const is1 = 1 / out_s[0];
|
|
1173
|
+
const is2 = 1 / out_s[1];
|
|
1174
|
+
const is3 = 1 / out_s[2];
|
|
1175
|
+
const sm11 = m11 * is1;
|
|
1176
|
+
const sm12 = m12 * is2;
|
|
1177
|
+
const sm13 = m13 * is3;
|
|
1178
|
+
const sm21 = m21 * is1;
|
|
1179
|
+
const sm22 = m22 * is2;
|
|
1180
|
+
const sm23 = m23 * is3;
|
|
1181
|
+
const sm31 = m31 * is1;
|
|
1182
|
+
const sm32 = m32 * is2;
|
|
1183
|
+
const sm33 = m33 * is3;
|
|
1184
|
+
const trace = sm11 + sm22 + sm33;
|
|
1185
|
+
let S = 0;
|
|
1186
|
+
if (trace > 0) {
|
|
1187
|
+
S = Math.sqrt(trace + 1.0) * 2;
|
|
1188
|
+
out_r[3] = 0.25 * S;
|
|
1189
|
+
out_r[0] = (sm23 - sm32) / S;
|
|
1190
|
+
out_r[1] = (sm31 - sm13) / S;
|
|
1191
|
+
out_r[2] = (sm12 - sm21) / S;
|
|
1192
|
+
}
|
|
1193
|
+
else if (sm11 > sm22 && sm11 > sm33) {
|
|
1194
|
+
S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
|
|
1195
|
+
out_r[3] = (sm23 - sm32) / S;
|
|
1196
|
+
out_r[0] = 0.25 * S;
|
|
1197
|
+
out_r[1] = (sm12 + sm21) / S;
|
|
1198
|
+
out_r[2] = (sm31 + sm13) / S;
|
|
1199
|
+
}
|
|
1200
|
+
else if (sm22 > sm33) {
|
|
1201
|
+
S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
|
|
1202
|
+
out_r[3] = (sm31 - sm13) / S;
|
|
1203
|
+
out_r[0] = (sm12 + sm21) / S;
|
|
1204
|
+
out_r[1] = 0.25 * S;
|
|
1205
|
+
out_r[2] = (sm23 + sm32) / S;
|
|
1206
|
+
}
|
|
1207
|
+
else {
|
|
1208
|
+
S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
|
|
1209
|
+
out_r[3] = (sm12 - sm21) / S;
|
|
1210
|
+
out_r[0] = (sm31 + sm13) / S;
|
|
1211
|
+
out_r[1] = (sm23 + sm32) / S;
|
|
1212
|
+
out_r[2] = 0.25 * S;
|
|
1213
|
+
}
|
|
1214
|
+
return out_r;
|
|
929
1215
|
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Creates a matrix from a quaternion rotation, vector translation and vector scale
|
|
1218
|
+
* This is equivalent to (but much faster than):
|
|
1219
|
+
*
|
|
1220
|
+
* mat4.identity(dest);
|
|
1221
|
+
* mat4.translate(dest, vec);
|
|
1222
|
+
* let quatMat = mat4.create();
|
|
1223
|
+
* quat4.toMat4(quat, quatMat);
|
|
1224
|
+
* mat4.multiply(dest, quatMat);
|
|
1225
|
+
* mat4.scale(dest, scale)
|
|
1226
|
+
*
|
|
1227
|
+
* @param {mat4} out mat4 receiving operation result
|
|
1228
|
+
* @param {quat4} q Rotation quaternion
|
|
1229
|
+
* @param {ReadonlyVec3} v Translation vector
|
|
1230
|
+
* @param {ReadonlyVec3} s Scaling vector
|
|
1231
|
+
* @returns {mat4} out
|
|
1232
|
+
*/
|
|
930
1233
|
export function fromRotationTranslationScale(out, q, v, s) {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1234
|
+
// Quaternion math
|
|
1235
|
+
const x = q[0];
|
|
1236
|
+
const y = q[1];
|
|
1237
|
+
const z = q[2];
|
|
1238
|
+
const w = q[3];
|
|
1239
|
+
const x2 = x + x;
|
|
1240
|
+
const y2 = y + y;
|
|
1241
|
+
const z2 = z + z;
|
|
1242
|
+
const xx = x * x2;
|
|
1243
|
+
const xy = x * y2;
|
|
1244
|
+
const xz = x * z2;
|
|
1245
|
+
const yy = y * y2;
|
|
1246
|
+
const yz = y * z2;
|
|
1247
|
+
const zz = z * z2;
|
|
1248
|
+
const wx = w * x2;
|
|
1249
|
+
const wy = w * y2;
|
|
1250
|
+
const wz = w * z2;
|
|
1251
|
+
const sx = s[0];
|
|
1252
|
+
const sy = s[1];
|
|
1253
|
+
const sz = s[2];
|
|
1254
|
+
out[0] = (1 - (yy + zz)) * sx;
|
|
1255
|
+
out[1] = (xy + wz) * sx;
|
|
1256
|
+
out[2] = (xz - wy) * sx;
|
|
1257
|
+
out[3] = 0;
|
|
1258
|
+
out[4] = (xy - wz) * sy;
|
|
1259
|
+
out[5] = (1 - (xx + zz)) * sy;
|
|
1260
|
+
out[6] = (yz + wx) * sy;
|
|
1261
|
+
out[7] = 0;
|
|
1262
|
+
out[8] = (xz + wy) * sz;
|
|
1263
|
+
out[9] = (yz - wx) * sz;
|
|
1264
|
+
out[10] = (1 - (xx + yy)) * sz;
|
|
1265
|
+
out[11] = 0;
|
|
1266
|
+
out[12] = v[0];
|
|
1267
|
+
out[13] = v[1];
|
|
1268
|
+
out[14] = v[2];
|
|
1269
|
+
out[15] = 1;
|
|
1270
|
+
return out;
|
|
967
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
|
|
1274
|
+
* This is equivalent to (but much faster than):
|
|
1275
|
+
*
|
|
1276
|
+
* mat4.identity(dest);
|
|
1277
|
+
* mat4.translate(dest, vec);
|
|
1278
|
+
* mat4.translate(dest, origin);
|
|
1279
|
+
* let quatMat = mat4.create();
|
|
1280
|
+
* quat4.toMat4(quat, quatMat);
|
|
1281
|
+
* mat4.multiply(dest, quatMat);
|
|
1282
|
+
* mat4.scale(dest, scale)
|
|
1283
|
+
* mat4.translate(dest, negativeOrigin);
|
|
1284
|
+
*
|
|
1285
|
+
* @param {mat4} out mat4 receiving operation result
|
|
1286
|
+
* @param {quat4} q Rotation quaternion
|
|
1287
|
+
* @param {ReadonlyVec3} v Translation vector
|
|
1288
|
+
* @param {ReadonlyVec3} s Scaling vector
|
|
1289
|
+
* @param {ReadonlyVec3} o The origin vector around which to scale and rotate
|
|
1290
|
+
* @returns {mat4} out
|
|
1291
|
+
*/
|
|
968
1292
|
export function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1293
|
+
// Quaternion math
|
|
1294
|
+
const x = q[0];
|
|
1295
|
+
const y = q[1];
|
|
1296
|
+
const z = q[2];
|
|
1297
|
+
const w = q[3];
|
|
1298
|
+
const x2 = x + x;
|
|
1299
|
+
const y2 = y + y;
|
|
1300
|
+
const z2 = z + z;
|
|
1301
|
+
const xx = x * x2;
|
|
1302
|
+
const xy = x * y2;
|
|
1303
|
+
const xz = x * z2;
|
|
1304
|
+
const yy = y * y2;
|
|
1305
|
+
const yz = y * z2;
|
|
1306
|
+
const zz = z * z2;
|
|
1307
|
+
const wx = w * x2;
|
|
1308
|
+
const wy = w * y2;
|
|
1309
|
+
const wz = w * z2;
|
|
1310
|
+
const sx = s[0];
|
|
1311
|
+
const sy = s[1];
|
|
1312
|
+
const sz = s[2];
|
|
1313
|
+
const ox = o[0];
|
|
1314
|
+
const oy = o[1];
|
|
1315
|
+
const oz = o[2];
|
|
1316
|
+
const out0 = (1 - (yy + zz)) * sx;
|
|
1317
|
+
const out1 = (xy + wz) * sx;
|
|
1318
|
+
const out2 = (xz - wy) * sx;
|
|
1319
|
+
const out4 = (xy - wz) * sy;
|
|
1320
|
+
const out5 = (1 - (xx + zz)) * sy;
|
|
1321
|
+
const out6 = (yz + wx) * sy;
|
|
1322
|
+
const out8 = (xz + wy) * sz;
|
|
1323
|
+
const out9 = (yz - wx) * sz;
|
|
1324
|
+
const out10 = (1 - (xx + yy)) * sz;
|
|
1325
|
+
out[0] = out0;
|
|
1326
|
+
out[1] = out1;
|
|
1327
|
+
out[2] = out2;
|
|
1328
|
+
out[3] = 0;
|
|
1329
|
+
out[4] = out4;
|
|
1330
|
+
out[5] = out5;
|
|
1331
|
+
out[6] = out6;
|
|
1332
|
+
out[7] = 0;
|
|
1333
|
+
out[8] = out8;
|
|
1334
|
+
out[9] = out9;
|
|
1335
|
+
out[10] = out10;
|
|
1336
|
+
out[11] = 0;
|
|
1337
|
+
out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
|
|
1338
|
+
out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
|
|
1339
|
+
out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
|
|
1340
|
+
out[15] = 1;
|
|
1341
|
+
return out;
|
|
1017
1342
|
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Calculates a 4x4 matrix from the given quaternion
|
|
1345
|
+
*
|
|
1346
|
+
* @param {mat4} out mat4 receiving operation result
|
|
1347
|
+
* @param {ReadonlyQuat} q Quaternion to create matrix from
|
|
1348
|
+
*
|
|
1349
|
+
* @returns {mat4} out
|
|
1350
|
+
*/
|
|
1018
1351
|
export function fromQuat(out, q) {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1352
|
+
const x = q[0];
|
|
1353
|
+
const y = q[1];
|
|
1354
|
+
const z = q[2];
|
|
1355
|
+
const w = q[3];
|
|
1356
|
+
const x2 = x + x;
|
|
1357
|
+
const y2 = y + y;
|
|
1358
|
+
const z2 = z + z;
|
|
1359
|
+
const xx = x * x2;
|
|
1360
|
+
const yx = y * x2;
|
|
1361
|
+
const yy = y * y2;
|
|
1362
|
+
const zx = z * x2;
|
|
1363
|
+
const zy = z * y2;
|
|
1364
|
+
const zz = z * z2;
|
|
1365
|
+
const wx = w * x2;
|
|
1366
|
+
const wy = w * y2;
|
|
1367
|
+
const wz = w * z2;
|
|
1368
|
+
out[0] = 1 - yy - zz;
|
|
1369
|
+
out[1] = yx + wz;
|
|
1370
|
+
out[2] = zx - wy;
|
|
1371
|
+
out[3] = 0;
|
|
1372
|
+
out[4] = yx - wz;
|
|
1373
|
+
out[5] = 1 - xx - zz;
|
|
1374
|
+
out[6] = zy + wx;
|
|
1375
|
+
out[7] = 0;
|
|
1376
|
+
out[8] = zx + wy;
|
|
1377
|
+
out[9] = zy - wx;
|
|
1378
|
+
out[10] = 1 - xx - yy;
|
|
1379
|
+
out[11] = 0;
|
|
1380
|
+
out[12] = 0;
|
|
1381
|
+
out[13] = 0;
|
|
1382
|
+
out[14] = 0;
|
|
1383
|
+
out[15] = 1;
|
|
1384
|
+
return out;
|
|
1052
1385
|
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Generates a frustum matrix with the given bounds
|
|
1388
|
+
*
|
|
1389
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1390
|
+
* @param {Number} left Left bound of the frustum
|
|
1391
|
+
* @param {Number} right Right bound of the frustum
|
|
1392
|
+
* @param {Number} bottom Bottom bound of the frustum
|
|
1393
|
+
* @param {Number} top Top bound of the frustum
|
|
1394
|
+
* @param {Number} near Near bound of the frustum
|
|
1395
|
+
* @param {Number} far Far bound of the frustum
|
|
1396
|
+
* @returns {mat4} out
|
|
1397
|
+
*/
|
|
1053
1398
|
export function frustum(out, left, right, bottom, top, near, far) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
const nf = 1 / (near - far);
|
|
1057
|
-
out[0] = near * 2 * rl;
|
|
1058
|
-
out[1] = 0;
|
|
1059
|
-
out[2] = 0;
|
|
1060
|
-
out[3] = 0;
|
|
1061
|
-
out[4] = 0;
|
|
1062
|
-
out[5] = near * 2 * tb;
|
|
1063
|
-
out[6] = 0;
|
|
1064
|
-
out[7] = 0;
|
|
1065
|
-
out[8] = (right + left) * rl;
|
|
1066
|
-
out[9] = (top + bottom) * tb;
|
|
1067
|
-
out[10] = (far + near) * nf;
|
|
1068
|
-
out[11] = -1;
|
|
1069
|
-
out[12] = 0;
|
|
1070
|
-
out[13] = 0;
|
|
1071
|
-
out[14] = far * near * 2 * nf;
|
|
1072
|
-
out[15] = 0;
|
|
1073
|
-
return out;
|
|
1074
|
-
}
|
|
1075
|
-
export function perspectiveNO(out, fovy, aspect, near, far) {
|
|
1076
|
-
const f = 1.0 / Math.tan(fovy / 2);
|
|
1077
|
-
out[0] = f / aspect;
|
|
1078
|
-
out[1] = 0;
|
|
1079
|
-
out[2] = 0;
|
|
1080
|
-
out[3] = 0;
|
|
1081
|
-
out[4] = 0;
|
|
1082
|
-
out[5] = f;
|
|
1083
|
-
out[6] = 0;
|
|
1084
|
-
out[7] = 0;
|
|
1085
|
-
out[8] = 0;
|
|
1086
|
-
out[9] = 0;
|
|
1087
|
-
out[11] = -1;
|
|
1088
|
-
out[12] = 0;
|
|
1089
|
-
out[13] = 0;
|
|
1090
|
-
out[15] = 0;
|
|
1091
|
-
|
|
1092
|
-
if (far != null && far !== Infinity) {
|
|
1399
|
+
const rl = 1 / (right - left);
|
|
1400
|
+
const tb = 1 / (top - bottom);
|
|
1093
1401
|
const nf = 1 / (near - far);
|
|
1402
|
+
out[0] = near * 2 * rl;
|
|
1403
|
+
out[1] = 0;
|
|
1404
|
+
out[2] = 0;
|
|
1405
|
+
out[3] = 0;
|
|
1406
|
+
out[4] = 0;
|
|
1407
|
+
out[5] = near * 2 * tb;
|
|
1408
|
+
out[6] = 0;
|
|
1409
|
+
out[7] = 0;
|
|
1410
|
+
out[8] = (right + left) * rl;
|
|
1411
|
+
out[9] = (top + bottom) * tb;
|
|
1094
1412
|
out[10] = (far + near) * nf;
|
|
1095
|
-
out[
|
|
1096
|
-
|
|
1097
|
-
out[
|
|
1098
|
-
out[14] =
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1413
|
+
out[11] = -1;
|
|
1414
|
+
out[12] = 0;
|
|
1415
|
+
out[13] = 0;
|
|
1416
|
+
out[14] = far * near * 2 * nf;
|
|
1417
|
+
out[15] = 0;
|
|
1418
|
+
return out;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Generates a perspective projection matrix with the given bounds.
|
|
1422
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
|
|
1423
|
+
* which matches WebGL/OpenGL's clip volume.
|
|
1424
|
+
* Passing null/undefined/no value for far will generate infinite projection matrix.
|
|
1425
|
+
*
|
|
1426
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1427
|
+
* @param {number} fovy Vertical field of view in radians
|
|
1428
|
+
* @param {number} aspect Aspect ratio. typically viewport width/height
|
|
1429
|
+
* @param {number} near Near bound of the frustum
|
|
1430
|
+
* @param {number} far Far bound of the frustum, can be null or Infinity
|
|
1431
|
+
* @returns {mat4} out
|
|
1432
|
+
*/
|
|
1433
|
+
export function perspectiveNO(out, fovy, aspect, near, far) {
|
|
1434
|
+
const f = 1.0 / Math.tan(fovy / 2);
|
|
1435
|
+
out[0] = f / aspect;
|
|
1436
|
+
out[1] = 0;
|
|
1437
|
+
out[2] = 0;
|
|
1438
|
+
out[3] = 0;
|
|
1439
|
+
out[4] = 0;
|
|
1440
|
+
out[5] = f;
|
|
1441
|
+
out[6] = 0;
|
|
1442
|
+
out[7] = 0;
|
|
1443
|
+
out[8] = 0;
|
|
1444
|
+
out[9] = 0;
|
|
1445
|
+
out[11] = -1;
|
|
1446
|
+
out[12] = 0;
|
|
1447
|
+
out[13] = 0;
|
|
1448
|
+
out[15] = 0;
|
|
1449
|
+
if (far != null && far !== Infinity) {
|
|
1450
|
+
const nf = 1 / (near - far);
|
|
1451
|
+
out[10] = (far + near) * nf;
|
|
1452
|
+
out[14] = 2 * far * near * nf;
|
|
1453
|
+
}
|
|
1454
|
+
else {
|
|
1455
|
+
out[10] = -1;
|
|
1456
|
+
out[14] = -2 * near;
|
|
1457
|
+
}
|
|
1458
|
+
return out;
|
|
1102
1459
|
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Alias for {@link mat4.perspectiveNO}
|
|
1462
|
+
* @function
|
|
1463
|
+
*/
|
|
1103
1464
|
export const perspective = perspectiveNO;
|
|
1465
|
+
/**
|
|
1466
|
+
* Generates a perspective projection matrix suitable for WebGPU with the given bounds.
|
|
1467
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
|
|
1468
|
+
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
|
|
1469
|
+
* Passing null/undefined/no value for far will generate infinite projection matrix.
|
|
1470
|
+
*
|
|
1471
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1472
|
+
* @param {number} fovy Vertical field of view in radians
|
|
1473
|
+
* @param {number} aspect Aspect ratio. typically viewport width/height
|
|
1474
|
+
* @param {number} near Near bound of the frustum
|
|
1475
|
+
* @param {number} far Far bound of the frustum, can be null or Infinity
|
|
1476
|
+
* @returns {mat4} out
|
|
1477
|
+
*/
|
|
1104
1478
|
export function perspectiveZO(out, fovy, aspect, near, far) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
return out;
|
|
1479
|
+
const f = 1.0 / Math.tan(fovy / 2);
|
|
1480
|
+
out[0] = f / aspect;
|
|
1481
|
+
out[1] = 0;
|
|
1482
|
+
out[2] = 0;
|
|
1483
|
+
out[3] = 0;
|
|
1484
|
+
out[4] = 0;
|
|
1485
|
+
out[5] = f;
|
|
1486
|
+
out[6] = 0;
|
|
1487
|
+
out[7] = 0;
|
|
1488
|
+
out[8] = 0;
|
|
1489
|
+
out[9] = 0;
|
|
1490
|
+
out[11] = -1;
|
|
1491
|
+
out[12] = 0;
|
|
1492
|
+
out[13] = 0;
|
|
1493
|
+
out[15] = 0;
|
|
1494
|
+
if (far != null && far !== Infinity) {
|
|
1495
|
+
const nf = 1 / (near - far);
|
|
1496
|
+
out[10] = far * nf;
|
|
1497
|
+
out[14] = far * near * nf;
|
|
1498
|
+
}
|
|
1499
|
+
else {
|
|
1500
|
+
out[10] = -1;
|
|
1501
|
+
out[14] = -near;
|
|
1502
|
+
}
|
|
1503
|
+
return out;
|
|
1131
1504
|
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Generates a perspective projection matrix with the given field of view.
|
|
1507
|
+
* This is primarily useful for generating projection matrices to be used
|
|
1508
|
+
* with the still experiemental WebVR API.
|
|
1509
|
+
*
|
|
1510
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1511
|
+
* @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
|
|
1512
|
+
* @param {number} near Near bound of the frustum
|
|
1513
|
+
* @param {number} far Far bound of the frustum
|
|
1514
|
+
* @returns {mat4} out
|
|
1515
|
+
*/
|
|
1132
1516
|
export function perspectiveFromFieldOfView(out, fov, near, far) {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1517
|
+
const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
|
|
1518
|
+
const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
|
|
1519
|
+
const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
|
|
1520
|
+
const rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);
|
|
1521
|
+
const xScale = 2.0 / (leftTan + rightTan);
|
|
1522
|
+
const yScale = 2.0 / (upTan + downTan);
|
|
1523
|
+
out[0] = xScale;
|
|
1524
|
+
out[1] = 0.0;
|
|
1525
|
+
out[2] = 0.0;
|
|
1526
|
+
out[3] = 0.0;
|
|
1527
|
+
out[4] = 0.0;
|
|
1528
|
+
out[5] = yScale;
|
|
1529
|
+
out[6] = 0.0;
|
|
1530
|
+
out[7] = 0.0;
|
|
1531
|
+
out[8] = -((leftTan - rightTan) * xScale * 0.5);
|
|
1532
|
+
out[9] = (upTan - downTan) * yScale * 0.5;
|
|
1533
|
+
out[10] = far / (near - far);
|
|
1534
|
+
out[11] = -1.0;
|
|
1535
|
+
out[12] = 0.0;
|
|
1536
|
+
out[13] = 0.0;
|
|
1537
|
+
out[14] = (far * near) / (near - far);
|
|
1538
|
+
out[15] = 0.0;
|
|
1539
|
+
return out;
|
|
1156
1540
|
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Generates a orthogonal projection matrix with the given bounds.
|
|
1543
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
|
|
1544
|
+
* which matches WebGL/OpenGL's clip volume.
|
|
1545
|
+
*
|
|
1546
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1547
|
+
* @param {number} left Left bound of the frustum
|
|
1548
|
+
* @param {number} right Right bound of the frustum
|
|
1549
|
+
* @param {number} bottom Bottom bound of the frustum
|
|
1550
|
+
* @param {number} top Top bound of the frustum
|
|
1551
|
+
* @param {number} near Near bound of the frustum
|
|
1552
|
+
* @param {number} far Far bound of the frustum
|
|
1553
|
+
* @returns {mat4} out
|
|
1554
|
+
*/
|
|
1157
1555
|
export function orthoNO(out, left, right, bottom, top, near, far) {
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1556
|
+
const lr = 1 / (left - right);
|
|
1557
|
+
const bt = 1 / (bottom - top);
|
|
1558
|
+
const nf = 1 / (near - far);
|
|
1559
|
+
out[0] = -2 * lr;
|
|
1560
|
+
out[1] = 0;
|
|
1561
|
+
out[2] = 0;
|
|
1562
|
+
out[3] = 0;
|
|
1563
|
+
out[4] = 0;
|
|
1564
|
+
out[5] = -2 * bt;
|
|
1565
|
+
out[6] = 0;
|
|
1566
|
+
out[7] = 0;
|
|
1567
|
+
out[8] = 0;
|
|
1568
|
+
out[9] = 0;
|
|
1569
|
+
out[10] = 2 * nf;
|
|
1570
|
+
out[11] = 0;
|
|
1571
|
+
out[12] = (left + right) * lr;
|
|
1572
|
+
out[13] = (top + bottom) * bt;
|
|
1573
|
+
out[14] = (far + near) * nf;
|
|
1574
|
+
out[15] = 1;
|
|
1575
|
+
return out;
|
|
1178
1576
|
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Alias for {@link mat4.orthoNO}
|
|
1579
|
+
* @function
|
|
1580
|
+
*/
|
|
1179
1581
|
export const ortho = orthoNO;
|
|
1582
|
+
/**
|
|
1583
|
+
* Generates a orthogonal projection matrix with the given bounds.
|
|
1584
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
|
|
1585
|
+
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
|
|
1586
|
+
*
|
|
1587
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1588
|
+
* @param {number} left Left bound of the frustum
|
|
1589
|
+
* @param {number} right Right bound of the frustum
|
|
1590
|
+
* @param {number} bottom Bottom bound of the frustum
|
|
1591
|
+
* @param {number} top Top bound of the frustum
|
|
1592
|
+
* @param {number} near Near bound of the frustum
|
|
1593
|
+
* @param {number} far Far bound of the frustum
|
|
1594
|
+
* @returns {mat4} out
|
|
1595
|
+
*/
|
|
1180
1596
|
export function orthoZO(out, left, right, bottom, top, near, far) {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1597
|
+
const lr = 1 / (left - right);
|
|
1598
|
+
const bt = 1 / (bottom - top);
|
|
1599
|
+
const nf = 1 / (near - far);
|
|
1600
|
+
out[0] = -2 * lr;
|
|
1601
|
+
out[1] = 0;
|
|
1602
|
+
out[2] = 0;
|
|
1603
|
+
out[3] = 0;
|
|
1604
|
+
out[4] = 0;
|
|
1605
|
+
out[5] = -2 * bt;
|
|
1606
|
+
out[6] = 0;
|
|
1607
|
+
out[7] = 0;
|
|
1608
|
+
out[8] = 0;
|
|
1609
|
+
out[9] = 0;
|
|
1610
|
+
out[10] = nf;
|
|
1611
|
+
out[11] = 0;
|
|
1612
|
+
out[12] = (left + right) * lr;
|
|
1613
|
+
out[13] = (top + bottom) * bt;
|
|
1614
|
+
out[14] = near * nf;
|
|
1615
|
+
out[15] = 1;
|
|
1616
|
+
return out;
|
|
1201
1617
|
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Generates a look-at matrix with the given eye position, focal point, and up axis.
|
|
1620
|
+
* If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
|
|
1621
|
+
*
|
|
1622
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1623
|
+
* @param {ReadonlyVec3} eye Position of the viewer
|
|
1624
|
+
* @param {ReadonlyVec3} center Point the viewer is looking at
|
|
1625
|
+
* @param {ReadonlyVec3} up vec3 pointing up
|
|
1626
|
+
* @returns {mat4} out
|
|
1627
|
+
*/
|
|
1202
1628
|
export function lookAt(out, eye, center, up) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
z0 *= len;
|
|
1232
|
-
z1 *= len;
|
|
1233
|
-
z2 *= len;
|
|
1234
|
-
x0 = upy * z2 - upz * z1;
|
|
1235
|
-
x1 = upz * z0 - upx * z2;
|
|
1236
|
-
x2 = upx * z1 - upy * z0;
|
|
1237
|
-
len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
|
|
1238
|
-
|
|
1239
|
-
if (!len) {
|
|
1240
|
-
x0 = 0;
|
|
1241
|
-
x1 = 0;
|
|
1242
|
-
x2 = 0;
|
|
1243
|
-
} else {
|
|
1244
|
-
len = 1 / len;
|
|
1245
|
-
x0 *= len;
|
|
1246
|
-
x1 *= len;
|
|
1247
|
-
x2 *= len;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
y0 = z1 * x2 - z2 * x1;
|
|
1251
|
-
y1 = z2 * x0 - z0 * x2;
|
|
1252
|
-
y2 = z0 * x1 - z1 * x0;
|
|
1253
|
-
len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
|
|
1254
|
-
|
|
1255
|
-
if (!len) {
|
|
1256
|
-
y0 = 0;
|
|
1257
|
-
y1 = 0;
|
|
1258
|
-
y2 = 0;
|
|
1259
|
-
} else {
|
|
1260
|
-
len = 1 / len;
|
|
1261
|
-
y0 *= len;
|
|
1262
|
-
y1 *= len;
|
|
1263
|
-
y2 *= len;
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
out[0] = x0;
|
|
1267
|
-
out[1] = y0;
|
|
1268
|
-
out[2] = z0;
|
|
1269
|
-
out[3] = 0;
|
|
1270
|
-
out[4] = x1;
|
|
1271
|
-
out[5] = y1;
|
|
1272
|
-
out[6] = z1;
|
|
1273
|
-
out[7] = 0;
|
|
1274
|
-
out[8] = x2;
|
|
1275
|
-
out[9] = y2;
|
|
1276
|
-
out[10] = z2;
|
|
1277
|
-
out[11] = 0;
|
|
1278
|
-
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
|
|
1279
|
-
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
|
|
1280
|
-
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
|
1281
|
-
out[15] = 1;
|
|
1282
|
-
return out;
|
|
1283
|
-
}
|
|
1284
|
-
export function targetTo(out, eye, target, up) {
|
|
1285
|
-
const eyex = eye[0];
|
|
1286
|
-
const eyey = eye[1];
|
|
1287
|
-
const eyez = eye[2];
|
|
1288
|
-
const upx = up[0];
|
|
1289
|
-
const upy = up[1];
|
|
1290
|
-
const upz = up[2];
|
|
1291
|
-
let z0 = eyex - target[0];
|
|
1292
|
-
let z1 = eyey - target[1];
|
|
1293
|
-
let z2 = eyez - target[2];
|
|
1294
|
-
let len = z0 * z0 + z1 * z1 + z2 * z2;
|
|
1295
|
-
|
|
1296
|
-
if (len > 0) {
|
|
1297
|
-
len = 1 / Math.sqrt(len);
|
|
1629
|
+
let len;
|
|
1630
|
+
let x0;
|
|
1631
|
+
let x1;
|
|
1632
|
+
let x2;
|
|
1633
|
+
let y0;
|
|
1634
|
+
let y1;
|
|
1635
|
+
let y2;
|
|
1636
|
+
let z0;
|
|
1637
|
+
let z1;
|
|
1638
|
+
let z2;
|
|
1639
|
+
const eyex = eye[0];
|
|
1640
|
+
const eyey = eye[1];
|
|
1641
|
+
const eyez = eye[2];
|
|
1642
|
+
const upx = up[0];
|
|
1643
|
+
const upy = up[1];
|
|
1644
|
+
const upz = up[2];
|
|
1645
|
+
const centerx = center[0];
|
|
1646
|
+
const centery = center[1];
|
|
1647
|
+
const centerz = center[2];
|
|
1648
|
+
if (Math.abs(eyex - centerx) < glMatrix.EPSILON &&
|
|
1649
|
+
Math.abs(eyey - centery) < glMatrix.EPSILON &&
|
|
1650
|
+
Math.abs(eyez - centerz) < glMatrix.EPSILON) {
|
|
1651
|
+
return identity(out);
|
|
1652
|
+
}
|
|
1653
|
+
z0 = eyex - centerx;
|
|
1654
|
+
z1 = eyey - centery;
|
|
1655
|
+
z2 = eyez - centerz;
|
|
1656
|
+
len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
|
|
1298
1657
|
z0 *= len;
|
|
1299
1658
|
z1 *= len;
|
|
1300
1659
|
z2 *= len;
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1660
|
+
x0 = upy * z2 - upz * z1;
|
|
1661
|
+
x1 = upz * z0 - upx * z2;
|
|
1662
|
+
x2 = upx * z1 - upy * z0;
|
|
1663
|
+
len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
|
|
1664
|
+
if (!len) {
|
|
1665
|
+
x0 = 0;
|
|
1666
|
+
x1 = 0;
|
|
1667
|
+
x2 = 0;
|
|
1668
|
+
}
|
|
1669
|
+
else {
|
|
1670
|
+
len = 1 / len;
|
|
1671
|
+
x0 *= len;
|
|
1672
|
+
x1 *= len;
|
|
1673
|
+
x2 *= len;
|
|
1674
|
+
}
|
|
1675
|
+
y0 = z1 * x2 - z2 * x1;
|
|
1676
|
+
y1 = z2 * x0 - z0 * x2;
|
|
1677
|
+
y2 = z0 * x1 - z1 * x0;
|
|
1678
|
+
len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
|
|
1679
|
+
if (!len) {
|
|
1680
|
+
y0 = 0;
|
|
1681
|
+
y1 = 0;
|
|
1682
|
+
y2 = 0;
|
|
1683
|
+
}
|
|
1684
|
+
else {
|
|
1685
|
+
len = 1 / len;
|
|
1686
|
+
y0 *= len;
|
|
1687
|
+
y1 *= len;
|
|
1688
|
+
y2 *= len;
|
|
1689
|
+
}
|
|
1690
|
+
out[0] = x0;
|
|
1691
|
+
out[1] = y0;
|
|
1692
|
+
out[2] = z0;
|
|
1693
|
+
out[3] = 0;
|
|
1694
|
+
out[4] = x1;
|
|
1695
|
+
out[5] = y1;
|
|
1696
|
+
out[6] = z1;
|
|
1697
|
+
out[7] = 0;
|
|
1698
|
+
out[8] = x2;
|
|
1699
|
+
out[9] = y2;
|
|
1700
|
+
out[10] = z2;
|
|
1701
|
+
out[11] = 0;
|
|
1702
|
+
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
|
|
1703
|
+
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
|
|
1704
|
+
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
|
1705
|
+
out[15] = 1;
|
|
1706
|
+
return out;
|
|
1707
|
+
}
|
|
1708
|
+
/**
|
|
1709
|
+
* Generates a matrix that makes something look at something else.
|
|
1710
|
+
*
|
|
1711
|
+
* @param {mat4} out mat4 frustum matrix will be written into
|
|
1712
|
+
* @param {ReadonlyVec3} eye Position of the viewer
|
|
1713
|
+
* @param {ReadonlyVec3} center Point the viewer is looking at
|
|
1714
|
+
* @param {ReadonlyVec3} up vec3 pointing up
|
|
1715
|
+
* @returns {mat4} out
|
|
1716
|
+
*/
|
|
1717
|
+
export function targetTo(out, eye, target, up) {
|
|
1718
|
+
const eyex = eye[0];
|
|
1719
|
+
const eyey = eye[1];
|
|
1720
|
+
const eyez = eye[2];
|
|
1721
|
+
const upx = up[0];
|
|
1722
|
+
const upy = up[1];
|
|
1723
|
+
const upz = up[2];
|
|
1724
|
+
let z0 = eyex - target[0];
|
|
1725
|
+
let z1 = eyey - target[1];
|
|
1726
|
+
let z2 = eyez - target[2];
|
|
1727
|
+
let len = z0 * z0 + z1 * z1 + z2 * z2;
|
|
1728
|
+
if (len > 0) {
|
|
1729
|
+
len = 1 / Math.sqrt(len);
|
|
1730
|
+
z0 *= len;
|
|
1731
|
+
z1 *= len;
|
|
1732
|
+
z2 *= len;
|
|
1733
|
+
}
|
|
1734
|
+
let x0 = upy * z2 - upz * z1;
|
|
1735
|
+
let x1 = upz * z0 - upx * z2;
|
|
1736
|
+
let x2 = upx * z1 - upy * z0;
|
|
1737
|
+
len = x0 * x0 + x1 * x1 + x2 * x2;
|
|
1738
|
+
if (len > 0) {
|
|
1739
|
+
len = 1 / Math.sqrt(len);
|
|
1740
|
+
x0 *= len;
|
|
1741
|
+
x1 *= len;
|
|
1742
|
+
x2 *= len;
|
|
1743
|
+
}
|
|
1744
|
+
out[0] = x0;
|
|
1745
|
+
out[1] = x1;
|
|
1746
|
+
out[2] = x2;
|
|
1747
|
+
out[3] = 0;
|
|
1748
|
+
out[4] = z1 * x2 - z2 * x1;
|
|
1749
|
+
out[5] = z2 * x0 - z0 * x2;
|
|
1750
|
+
out[6] = z0 * x1 - z1 * x0;
|
|
1751
|
+
out[7] = 0;
|
|
1752
|
+
out[8] = z0;
|
|
1753
|
+
out[9] = z1;
|
|
1754
|
+
out[10] = z2;
|
|
1755
|
+
out[11] = 0;
|
|
1756
|
+
out[12] = eyex;
|
|
1757
|
+
out[13] = eyey;
|
|
1758
|
+
out[14] = eyez;
|
|
1759
|
+
out[15] = 1;
|
|
1760
|
+
return out;
|
|
1332
1761
|
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Returns a string representation of a mat4
|
|
1764
|
+
*
|
|
1765
|
+
* @param {ReadonlyMat4} a matrix to represent as a string
|
|
1766
|
+
* @returns {String} string representation of the matrix
|
|
1767
|
+
*/
|
|
1333
1768
|
export function str(a) {
|
|
1334
|
-
|
|
1769
|
+
return `mat4(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]}, ${a[4]}, ${a[5]}, ${a[6]}, ${a[7]}, ${a[8]}, ${a[9]}, ${a[10]}, ${a[11]}, ${a[12]}, ${a[13]}, ${a[14]}, ${a[15]})`;
|
|
1335
1770
|
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Returns Frobenius norm of a mat4
|
|
1773
|
+
*
|
|
1774
|
+
* @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of
|
|
1775
|
+
* @returns {Number} Frobenius norm
|
|
1776
|
+
*/
|
|
1336
1777
|
export function frob(a) {
|
|
1337
|
-
|
|
1778
|
+
return Math.sqrt(a[0] * a[0] +
|
|
1779
|
+
a[1] * a[1] +
|
|
1780
|
+
a[2] * a[2] +
|
|
1781
|
+
a[3] * a[3] +
|
|
1782
|
+
a[4] * a[4] +
|
|
1783
|
+
a[5] * a[5] +
|
|
1784
|
+
a[6] * a[6] +
|
|
1785
|
+
a[7] * a[7] +
|
|
1786
|
+
a[8] * a[8] +
|
|
1787
|
+
a[9] * a[9] +
|
|
1788
|
+
a[10] * a[10] +
|
|
1789
|
+
a[11] * a[11] +
|
|
1790
|
+
a[12] * a[12] +
|
|
1791
|
+
a[13] * a[13] +
|
|
1792
|
+
a[14] * a[14] +
|
|
1793
|
+
a[15] * a[15]);
|
|
1338
1794
|
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Adds two mat4's
|
|
1797
|
+
*
|
|
1798
|
+
* @param {mat4} out the receiving matrix
|
|
1799
|
+
* @param {ReadonlyMat4} a the first operand
|
|
1800
|
+
* @param {ReadonlyMat4} b the second operand
|
|
1801
|
+
* @returns {mat4} out
|
|
1802
|
+
*/
|
|
1339
1803
|
export function add(out, a, b) {
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1804
|
+
out[0] = a[0] + b[0];
|
|
1805
|
+
out[1] = a[1] + b[1];
|
|
1806
|
+
out[2] = a[2] + b[2];
|
|
1807
|
+
out[3] = a[3] + b[3];
|
|
1808
|
+
out[4] = a[4] + b[4];
|
|
1809
|
+
out[5] = a[5] + b[5];
|
|
1810
|
+
out[6] = a[6] + b[6];
|
|
1811
|
+
out[7] = a[7] + b[7];
|
|
1812
|
+
out[8] = a[8] + b[8];
|
|
1813
|
+
out[9] = a[9] + b[9];
|
|
1814
|
+
out[10] = a[10] + b[10];
|
|
1815
|
+
out[11] = a[11] + b[11];
|
|
1816
|
+
out[12] = a[12] + b[12];
|
|
1817
|
+
out[13] = a[13] + b[13];
|
|
1818
|
+
out[14] = a[14] + b[14];
|
|
1819
|
+
out[15] = a[15] + b[15];
|
|
1820
|
+
return out;
|
|
1357
1821
|
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Subtracts matrix b from matrix a
|
|
1824
|
+
*
|
|
1825
|
+
* @param {mat4} out the receiving matrix
|
|
1826
|
+
* @param {ReadonlyMat4} a the first operand
|
|
1827
|
+
* @param {ReadonlyMat4} b the second operand
|
|
1828
|
+
* @returns {mat4} out
|
|
1829
|
+
*/
|
|
1358
1830
|
export function subtract(out, a, b) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1831
|
+
out[0] = a[0] - b[0];
|
|
1832
|
+
out[1] = a[1] - b[1];
|
|
1833
|
+
out[2] = a[2] - b[2];
|
|
1834
|
+
out[3] = a[3] - b[3];
|
|
1835
|
+
out[4] = a[4] - b[4];
|
|
1836
|
+
out[5] = a[5] - b[5];
|
|
1837
|
+
out[6] = a[6] - b[6];
|
|
1838
|
+
out[7] = a[7] - b[7];
|
|
1839
|
+
out[8] = a[8] - b[8];
|
|
1840
|
+
out[9] = a[9] - b[9];
|
|
1841
|
+
out[10] = a[10] - b[10];
|
|
1842
|
+
out[11] = a[11] - b[11];
|
|
1843
|
+
out[12] = a[12] - b[12];
|
|
1844
|
+
out[13] = a[13] - b[13];
|
|
1845
|
+
out[14] = a[14] - b[14];
|
|
1846
|
+
out[15] = a[15] - b[15];
|
|
1847
|
+
return out;
|
|
1376
1848
|
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Multiply each element of the matrix by a scalar.
|
|
1851
|
+
*
|
|
1852
|
+
* @param {mat4} out the receiving matrix
|
|
1853
|
+
* @param {ReadonlyMat4} a the matrix to scale
|
|
1854
|
+
* @param {Number} b amount to scale the matrix's elements by
|
|
1855
|
+
* @returns {mat4} out
|
|
1856
|
+
*/
|
|
1377
1857
|
export function multiplyScalar(out, a, b) {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1858
|
+
out[0] = a[0] * b;
|
|
1859
|
+
out[1] = a[1] * b;
|
|
1860
|
+
out[2] = a[2] * b;
|
|
1861
|
+
out[3] = a[3] * b;
|
|
1862
|
+
out[4] = a[4] * b;
|
|
1863
|
+
out[5] = a[5] * b;
|
|
1864
|
+
out[6] = a[6] * b;
|
|
1865
|
+
out[7] = a[7] * b;
|
|
1866
|
+
out[8] = a[8] * b;
|
|
1867
|
+
out[9] = a[9] * b;
|
|
1868
|
+
out[10] = a[10] * b;
|
|
1869
|
+
out[11] = a[11] * b;
|
|
1870
|
+
out[12] = a[12] * b;
|
|
1871
|
+
out[13] = a[13] * b;
|
|
1872
|
+
out[14] = a[14] * b;
|
|
1873
|
+
out[15] = a[15] * b;
|
|
1874
|
+
return out;
|
|
1395
1875
|
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Adds two mat4's after multiplying each element of the second operand by a scalar value.
|
|
1878
|
+
*
|
|
1879
|
+
* @param {mat4} out the receiving vector
|
|
1880
|
+
* @param {ReadonlyMat4} a the first operand
|
|
1881
|
+
* @param {ReadonlyMat4} b the second operand
|
|
1882
|
+
* @param {Number} scale the amount to scale b's elements by before adding
|
|
1883
|
+
* @returns {mat4} out
|
|
1884
|
+
*/
|
|
1396
1885
|
export function multiplyScalarAndAdd(out, a, b, scale) {
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1886
|
+
out[0] = a[0] + b[0] * scale;
|
|
1887
|
+
out[1] = a[1] + b[1] * scale;
|
|
1888
|
+
out[2] = a[2] + b[2] * scale;
|
|
1889
|
+
out[3] = a[3] + b[3] * scale;
|
|
1890
|
+
out[4] = a[4] + b[4] * scale;
|
|
1891
|
+
out[5] = a[5] + b[5] * scale;
|
|
1892
|
+
out[6] = a[6] + b[6] * scale;
|
|
1893
|
+
out[7] = a[7] + b[7] * scale;
|
|
1894
|
+
out[8] = a[8] + b[8] * scale;
|
|
1895
|
+
out[9] = a[9] + b[9] * scale;
|
|
1896
|
+
out[10] = a[10] + b[10] * scale;
|
|
1897
|
+
out[11] = a[11] + b[11] * scale;
|
|
1898
|
+
out[12] = a[12] + b[12] * scale;
|
|
1899
|
+
out[13] = a[13] + b[13] * scale;
|
|
1900
|
+
out[14] = a[14] + b[14] * scale;
|
|
1901
|
+
out[15] = a[15] + b[15] * scale;
|
|
1902
|
+
return out;
|
|
1414
1903
|
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
1906
|
+
*
|
|
1907
|
+
* @param {ReadonlyMat4} a The first matrix.
|
|
1908
|
+
* @param {ReadonlyMat4} b The second matrix.
|
|
1909
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
1910
|
+
*/
|
|
1415
1911
|
export function exactEquals(a, b) {
|
|
1416
|
-
|
|
1912
|
+
return (a[0] === b[0] &&
|
|
1913
|
+
a[1] === b[1] &&
|
|
1914
|
+
a[2] === b[2] &&
|
|
1915
|
+
a[3] === b[3] &&
|
|
1916
|
+
a[4] === b[4] &&
|
|
1917
|
+
a[5] === b[5] &&
|
|
1918
|
+
a[6] === b[6] &&
|
|
1919
|
+
a[7] === b[7] &&
|
|
1920
|
+
a[8] === b[8] &&
|
|
1921
|
+
a[9] === b[9] &&
|
|
1922
|
+
a[10] === b[10] &&
|
|
1923
|
+
a[11] === b[11] &&
|
|
1924
|
+
a[12] === b[12] &&
|
|
1925
|
+
a[13] === b[13] &&
|
|
1926
|
+
a[14] === b[14] &&
|
|
1927
|
+
a[15] === b[15]);
|
|
1417
1928
|
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Returns whether or not the matrices have approximately the same elements in the same position.
|
|
1931
|
+
*
|
|
1932
|
+
* @param {ReadonlyMat4} a The first matrix.
|
|
1933
|
+
* @param {ReadonlyMat4} b The second matrix.
|
|
1934
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
1935
|
+
*/
|
|
1418
1936
|
export function equals(a, b) {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1937
|
+
const a0 = a[0];
|
|
1938
|
+
const a1 = a[1];
|
|
1939
|
+
const a2 = a[2];
|
|
1940
|
+
const a3 = a[3];
|
|
1941
|
+
const a4 = a[4];
|
|
1942
|
+
const a5 = a[5];
|
|
1943
|
+
const a6 = a[6];
|
|
1944
|
+
const a7 = a[7];
|
|
1945
|
+
const a8 = a[8];
|
|
1946
|
+
const a9 = a[9];
|
|
1947
|
+
const a10 = a[10];
|
|
1948
|
+
const a11 = a[11];
|
|
1949
|
+
const a12 = a[12];
|
|
1950
|
+
const a13 = a[13];
|
|
1951
|
+
const a14 = a[14];
|
|
1952
|
+
const a15 = a[15];
|
|
1953
|
+
const b0 = b[0];
|
|
1954
|
+
const b1 = b[1];
|
|
1955
|
+
const b2 = b[2];
|
|
1956
|
+
const b3 = b[3];
|
|
1957
|
+
const b4 = b[4];
|
|
1958
|
+
const b5 = b[5];
|
|
1959
|
+
const b6 = b[6];
|
|
1960
|
+
const b7 = b[7];
|
|
1961
|
+
const b8 = b[8];
|
|
1962
|
+
const b9 = b[9];
|
|
1963
|
+
const b10 = b[10];
|
|
1964
|
+
const b11 = b[11];
|
|
1965
|
+
const b12 = b[12];
|
|
1966
|
+
const b13 = b[13];
|
|
1967
|
+
const b14 = b[14];
|
|
1968
|
+
const b15 = b[15];
|
|
1969
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
1970
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
|
|
1971
|
+
Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
|
|
1972
|
+
Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
|
|
1973
|
+
Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
|
|
1974
|
+
Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
|
|
1975
|
+
Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
|
|
1976
|
+
Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
|
|
1977
|
+
Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&
|
|
1978
|
+
Math.abs(a9 - b9) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&
|
|
1979
|
+
Math.abs(a10 - b10) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&
|
|
1980
|
+
Math.abs(a11 - b11) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&
|
|
1981
|
+
Math.abs(a12 - b12) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&
|
|
1982
|
+
Math.abs(a13 - b13) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&
|
|
1983
|
+
Math.abs(a14 - b14) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&
|
|
1984
|
+
Math.abs(a15 - b15) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15)));
|
|
1452
1985
|
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Alias for {@link mat4.multiply}
|
|
1988
|
+
* @function
|
|
1989
|
+
*/
|
|
1453
1990
|
export const mul = multiply;
|
|
1991
|
+
/**
|
|
1992
|
+
* Alias for {@link mat4.subtract}
|
|
1993
|
+
* @function
|
|
1994
|
+
*/
|
|
1454
1995
|
export const sub = subtract;
|
|
1455
|
-
//# sourceMappingURL=mat4.js.map
|