@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/quat.js
CHANGED
|
@@ -1,315 +1,713 @@
|
|
|
1
|
+
// @eslint-disable
|
|
2
|
+
// @ts-nocheck
|
|
1
3
|
import * as glMatrix from './common.js';
|
|
2
4
|
import * as mat3 from './mat3.js';
|
|
3
5
|
import * as vec3 from './vec3.js';
|
|
4
6
|
import * as vec4 from './vec4.js';
|
|
7
|
+
// const glMatrix: {EPSILON = 0.000001};
|
|
8
|
+
/**
|
|
9
|
+
* Quaternion in the format XYZW
|
|
10
|
+
* @module quat
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new identity quat
|
|
14
|
+
*
|
|
15
|
+
* @returns {quat} a new quaternion
|
|
16
|
+
*/
|
|
5
17
|
export function create() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
const out = new glMatrix.ARRAY_TYPE(4);
|
|
19
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
20
|
+
out[0] = 0;
|
|
21
|
+
out[1] = 0;
|
|
22
|
+
out[2] = 0;
|
|
23
|
+
}
|
|
24
|
+
out[3] = 1;
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Set a quat to the identity quaternion
|
|
29
|
+
*
|
|
30
|
+
* @param {quat} out the receiving quaternion
|
|
31
|
+
* @returns {quat} out
|
|
32
|
+
*/
|
|
33
|
+
export function identity(out) {
|
|
9
34
|
out[0] = 0;
|
|
10
35
|
out[1] = 0;
|
|
11
36
|
out[2] = 0;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
out[3] = 1;
|
|
15
|
-
return out;
|
|
16
|
-
}
|
|
17
|
-
export function identity(out) {
|
|
18
|
-
out[0] = 0;
|
|
19
|
-
out[1] = 0;
|
|
20
|
-
out[2] = 0;
|
|
21
|
-
out[3] = 1;
|
|
22
|
-
return out;
|
|
37
|
+
out[3] = 1;
|
|
38
|
+
return out;
|
|
23
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets a quat from the given angle and rotation axis,
|
|
42
|
+
* then returns it.
|
|
43
|
+
*
|
|
44
|
+
* @param {quat} out the receiving quaternion
|
|
45
|
+
* @param {ReadonlyVec3} axis the axis around which to rotate
|
|
46
|
+
* @param {Number} rad the angle in radians
|
|
47
|
+
* @returns {quat} out
|
|
48
|
+
**/
|
|
24
49
|
export function setAxisAngle(out, axis, rad) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
rad = rad * 0.5;
|
|
51
|
+
const s = Math.sin(rad);
|
|
52
|
+
out[0] = s * axis[0];
|
|
53
|
+
out[1] = s * axis[1];
|
|
54
|
+
out[2] = s * axis[2];
|
|
55
|
+
out[3] = Math.cos(rad);
|
|
56
|
+
return out;
|
|
32
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the rotation axis and angle for a given
|
|
60
|
+
* quaternion. If a quaternion is created with
|
|
61
|
+
* setAxisAngle, this method will return the same
|
|
62
|
+
* values as providied in the original parameter list
|
|
63
|
+
* OR functionally equivalent values.
|
|
64
|
+
* Example: The quaternion formed by axis [0, 0, 1] and
|
|
65
|
+
* angle -90 is the same as the quaternion formed by
|
|
66
|
+
* [0, 0, 1] and 270. This method favors the latter.
|
|
67
|
+
* @param {vec3} out_axis Vector receiving the axis of rotation
|
|
68
|
+
* @param {ReadonlyQuat} q Quaternion to be decomposed
|
|
69
|
+
* @return {Number} Angle, in radians, of the rotation
|
|
70
|
+
*/
|
|
33
71
|
export function getAxisAngle(out_axis, q) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
const rad = Math.acos(q[3]) * 2.0;
|
|
73
|
+
const s = Math.sin(rad / 2.0);
|
|
74
|
+
if (s > glMatrix.EPSILON) {
|
|
75
|
+
out_axis[0] = q[0] / s;
|
|
76
|
+
out_axis[1] = q[1] / s;
|
|
77
|
+
out_axis[2] = q[2] / s;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// If s is zero, return any axis (no rotation - axis does not matter)
|
|
81
|
+
out_axis[0] = 1;
|
|
82
|
+
out_axis[1] = 0;
|
|
83
|
+
out_axis[2] = 0;
|
|
84
|
+
}
|
|
85
|
+
return rad;
|
|
48
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Gets the angular distance between two unit quaternions
|
|
89
|
+
*
|
|
90
|
+
* @param {ReadonlyQuat} a Origin unit quaternion
|
|
91
|
+
* @param {ReadonlyQuat} b Destination unit quaternion
|
|
92
|
+
* @return {Number} Angle, in radians, between the two quaternions
|
|
93
|
+
*/
|
|
49
94
|
export function getAngle(a, b) {
|
|
50
|
-
|
|
51
|
-
|
|
95
|
+
const dotproduct = dot(a, b);
|
|
96
|
+
return Math.acos(2 * dotproduct * dotproduct - 1);
|
|
52
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Multiplies two quat's
|
|
100
|
+
*
|
|
101
|
+
* @param {quat} out the receiving quaternion
|
|
102
|
+
* @param {ReadonlyQuat} a the first operand
|
|
103
|
+
* @param {ReadonlyQuat} b the second operand
|
|
104
|
+
* @returns {quat} out
|
|
105
|
+
*/
|
|
53
106
|
export function multiply(out, a, b) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
107
|
+
const ax = a[0];
|
|
108
|
+
const ay = a[1];
|
|
109
|
+
const az = a[2];
|
|
110
|
+
const aw = a[3];
|
|
111
|
+
const bx = b[0];
|
|
112
|
+
const by = b[1];
|
|
113
|
+
const bz = b[2];
|
|
114
|
+
const bw = b[3];
|
|
115
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
116
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
117
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
118
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
119
|
+
return out;
|
|
67
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Rotates a quaternion by the given angle about the X axis
|
|
123
|
+
*
|
|
124
|
+
* @param {quat} out quat receiving operation result
|
|
125
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
126
|
+
* @param {number} rad angle (in radians) to rotate
|
|
127
|
+
* @returns {quat} out
|
|
128
|
+
*/
|
|
68
129
|
export function rotateX(out, a, rad) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
130
|
+
rad *= 0.5;
|
|
131
|
+
const ax = a[0];
|
|
132
|
+
const ay = a[1];
|
|
133
|
+
const az = a[2];
|
|
134
|
+
const aw = a[3];
|
|
135
|
+
const bx = Math.sin(rad);
|
|
136
|
+
const bw = Math.cos(rad);
|
|
137
|
+
out[0] = ax * bw + aw * bx;
|
|
138
|
+
out[1] = ay * bw + az * bx;
|
|
139
|
+
out[2] = az * bw - ay * bx;
|
|
140
|
+
out[3] = aw * bw - ax * bx;
|
|
141
|
+
return out;
|
|
81
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Rotates a quaternion by the given angle about the Y axis
|
|
145
|
+
*
|
|
146
|
+
* @param {quat} out quat receiving operation result
|
|
147
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
148
|
+
* @param {number} rad angle (in radians) to rotate
|
|
149
|
+
* @returns {quat} out
|
|
150
|
+
*/
|
|
82
151
|
export function rotateY(out, a, rad) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
152
|
+
rad *= 0.5;
|
|
153
|
+
const ax = a[0];
|
|
154
|
+
const ay = a[1];
|
|
155
|
+
const az = a[2];
|
|
156
|
+
const aw = a[3];
|
|
157
|
+
const by = Math.sin(rad);
|
|
158
|
+
const bw = Math.cos(rad);
|
|
159
|
+
out[0] = ax * bw - az * by;
|
|
160
|
+
out[1] = ay * bw + aw * by;
|
|
161
|
+
out[2] = az * bw + ax * by;
|
|
162
|
+
out[3] = aw * bw - ay * by;
|
|
163
|
+
return out;
|
|
95
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Rotates a quaternion by the given angle about the Z axis
|
|
167
|
+
*
|
|
168
|
+
* @param {quat} out quat receiving operation result
|
|
169
|
+
* @param {ReadonlyQuat} a quat to rotate
|
|
170
|
+
* @param {number} rad angle (in radians) to rotate
|
|
171
|
+
* @returns {quat} out
|
|
172
|
+
*/
|
|
96
173
|
export function rotateZ(out, a, rad) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
174
|
+
rad *= 0.5;
|
|
175
|
+
const ax = a[0];
|
|
176
|
+
const ay = a[1];
|
|
177
|
+
const az = a[2];
|
|
178
|
+
const aw = a[3];
|
|
179
|
+
const bz = Math.sin(rad);
|
|
180
|
+
const bw = Math.cos(rad);
|
|
181
|
+
out[0] = ax * bw + ay * bz;
|
|
182
|
+
out[1] = ay * bw - ax * bz;
|
|
183
|
+
out[2] = az * bw + aw * bz;
|
|
184
|
+
out[3] = aw * bw - az * bz;
|
|
185
|
+
return out;
|
|
109
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Calculates the W component of a quat from the X, Y, and Z components.
|
|
189
|
+
* Assumes that quaternion is 1 unit in length.
|
|
190
|
+
* Any existing W component will be ignored.
|
|
191
|
+
*
|
|
192
|
+
* @param {quat} out the receiving quaternion
|
|
193
|
+
* @param {ReadonlyQuat} a quat to calculate W component of
|
|
194
|
+
* @returns {quat} out
|
|
195
|
+
*/
|
|
110
196
|
export function calculateW(out, a) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
197
|
+
const x = a[0];
|
|
198
|
+
const y = a[1];
|
|
199
|
+
const z = a[2];
|
|
200
|
+
out[0] = x;
|
|
201
|
+
out[1] = y;
|
|
202
|
+
out[2] = z;
|
|
203
|
+
out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
|
|
204
|
+
return out;
|
|
119
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Calculate the exponential of a unit quaternion.
|
|
208
|
+
*
|
|
209
|
+
* @param {quat} out the receiving quaternion
|
|
210
|
+
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
211
|
+
* @returns {quat} out
|
|
212
|
+
*/
|
|
120
213
|
export function exp(out, a) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
214
|
+
const x = a[0];
|
|
215
|
+
const y = a[1];
|
|
216
|
+
const z = a[2];
|
|
217
|
+
const w = a[3];
|
|
218
|
+
const r = Math.sqrt(x * x + y * y + z * z);
|
|
219
|
+
const et = Math.exp(w);
|
|
220
|
+
const s = r > 0 ? (et * Math.sin(r)) / r : 0;
|
|
221
|
+
out[0] = x * s;
|
|
222
|
+
out[1] = y * s;
|
|
223
|
+
out[2] = z * s;
|
|
224
|
+
out[3] = et * Math.cos(r);
|
|
225
|
+
return out;
|
|
133
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Calculate the natural logarithm of a unit quaternion.
|
|
229
|
+
*
|
|
230
|
+
* @param {quat} out the receiving quaternion
|
|
231
|
+
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
232
|
+
* @returns {quat} out
|
|
233
|
+
*/
|
|
134
234
|
export function ln(out, a) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
235
|
+
const x = a[0];
|
|
236
|
+
const y = a[1];
|
|
237
|
+
const z = a[2];
|
|
238
|
+
const w = a[3];
|
|
239
|
+
const r = Math.sqrt(x * x + y * y + z * z);
|
|
240
|
+
const t = r > 0 ? Math.atan2(r, w) / r : 0;
|
|
241
|
+
out[0] = x * t;
|
|
242
|
+
out[1] = y * t;
|
|
243
|
+
out[2] = z * t;
|
|
244
|
+
out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);
|
|
245
|
+
return out;
|
|
146
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Calculate the scalar power of a unit quaternion.
|
|
249
|
+
*
|
|
250
|
+
* @param {quat} out the receiving quaternion
|
|
251
|
+
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
252
|
+
* @param {Number} b amount to scale the quaternion by
|
|
253
|
+
* @returns {quat} out
|
|
254
|
+
*/
|
|
147
255
|
export function pow(out, a, b) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
256
|
+
ln(out, a);
|
|
257
|
+
scale(out, out, b);
|
|
258
|
+
exp(out, out);
|
|
259
|
+
return out;
|
|
152
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Performs a spherical linear interpolation between two quat
|
|
263
|
+
*
|
|
264
|
+
* @param {quat} out the receiving quaternion
|
|
265
|
+
* @param {ReadonlyQuat} a the first operand
|
|
266
|
+
* @param {ReadonlyQuat} b the second operand
|
|
267
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
268
|
+
* @returns {quat} out
|
|
269
|
+
*/
|
|
153
270
|
export function slerp(out, a, b, t) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
cosom =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
271
|
+
// benchmarks:
|
|
272
|
+
// http://jsperf.com/quaternion-slerp-implementations
|
|
273
|
+
const ax = a[0];
|
|
274
|
+
const ay = a[1];
|
|
275
|
+
const az = a[2];
|
|
276
|
+
const aw = a[3];
|
|
277
|
+
let bx = b[0];
|
|
278
|
+
let by = b[1];
|
|
279
|
+
let bz = b[2];
|
|
280
|
+
let bw = b[3];
|
|
281
|
+
let cosom;
|
|
282
|
+
let omega;
|
|
283
|
+
let scale0;
|
|
284
|
+
let scale1;
|
|
285
|
+
let sinom;
|
|
286
|
+
// calc cosine
|
|
287
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
288
|
+
// adjust signs (if necessary)
|
|
289
|
+
if (cosom < 0.0) {
|
|
290
|
+
cosom = -cosom;
|
|
291
|
+
bx = -bx;
|
|
292
|
+
by = -by;
|
|
293
|
+
bz = -bz;
|
|
294
|
+
bw = -bw;
|
|
295
|
+
}
|
|
296
|
+
// calculate coefficients
|
|
297
|
+
if (1.0 - cosom > glMatrix.EPSILON) {
|
|
298
|
+
// standard case (slerp)
|
|
299
|
+
omega = Math.acos(cosom);
|
|
300
|
+
sinom = Math.sin(omega);
|
|
301
|
+
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
302
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// "from" and "to" quaternions are very close
|
|
306
|
+
// ... so we can do a linear interpolation
|
|
307
|
+
scale0 = 1.0 - t;
|
|
308
|
+
scale1 = t;
|
|
309
|
+
}
|
|
310
|
+
// calculate final values
|
|
311
|
+
out[0] = scale0 * ax + scale1 * bx;
|
|
312
|
+
out[1] = scale0 * ay + scale1 * by;
|
|
313
|
+
out[2] = scale0 * az + scale1 * bz;
|
|
314
|
+
out[3] = scale0 * aw + scale1 * bw;
|
|
315
|
+
return out;
|
|
192
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Generates a random unit quaternion
|
|
319
|
+
*
|
|
320
|
+
* @param {quat} out the receiving quaternion
|
|
321
|
+
* @returns {quat} out
|
|
322
|
+
*/
|
|
323
|
+
// export function random(out) {
|
|
324
|
+
// // Implementation of http://planning.cs.uiuc.edu/node198.html
|
|
325
|
+
// // TODO: Calling random 3 times is probably not the fastest solution
|
|
326
|
+
// let u1 = glMatrix.RANDOM();
|
|
327
|
+
// let u2 = glMatrix.RANDOM();
|
|
328
|
+
// let u3 = glMatrix.RANDOM();
|
|
329
|
+
// let sqrt1MinusU1 = Math.sqrt(1 - u1);
|
|
330
|
+
// let sqrtU1 = Math.sqrt(u1);
|
|
331
|
+
// out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
|
|
332
|
+
// out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
|
|
333
|
+
// out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
|
|
334
|
+
// out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
|
|
335
|
+
// return out;
|
|
336
|
+
// }
|
|
337
|
+
/**
|
|
338
|
+
* Calculates the inverse of a quat
|
|
339
|
+
*
|
|
340
|
+
* @param {quat} out the receiving quaternion
|
|
341
|
+
* @param {ReadonlyQuat} a quat to calculate inverse of
|
|
342
|
+
* @returns {quat} out
|
|
343
|
+
*/
|
|
193
344
|
export function invert(out, a) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
345
|
+
const a0 = a[0];
|
|
346
|
+
const a1 = a[1];
|
|
347
|
+
const a2 = a[2];
|
|
348
|
+
const a3 = a[3];
|
|
349
|
+
const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
350
|
+
const invDot = dot ? 1.0 / dot : 0;
|
|
351
|
+
// TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
|
|
352
|
+
out[0] = -a0 * invDot;
|
|
353
|
+
out[1] = -a1 * invDot;
|
|
354
|
+
out[2] = -a2 * invDot;
|
|
355
|
+
out[3] = a3 * invDot;
|
|
356
|
+
return out;
|
|
205
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Calculates the conjugate of a quat
|
|
360
|
+
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
|
|
361
|
+
*
|
|
362
|
+
* @param {quat} out the receiving quaternion
|
|
363
|
+
* @param {ReadonlyQuat} a quat to calculate conjugate of
|
|
364
|
+
* @returns {quat} out
|
|
365
|
+
*/
|
|
206
366
|
export function conjugate(out, a) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
367
|
+
out[0] = -a[0];
|
|
368
|
+
out[1] = -a[1];
|
|
369
|
+
out[2] = -a[2];
|
|
370
|
+
out[3] = a[3];
|
|
371
|
+
return out;
|
|
212
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
375
|
+
*
|
|
376
|
+
* NOTE: The resultant quaternion is not normalized, so you should be sure
|
|
377
|
+
* to renormalize the quaternion yourself where necessary.
|
|
378
|
+
*
|
|
379
|
+
* @param {quat} out the receiving quaternion
|
|
380
|
+
* @param {ReadonlyMat3} m rotation matrix
|
|
381
|
+
* @returns {quat} out
|
|
382
|
+
* @function
|
|
383
|
+
*/
|
|
213
384
|
export function fromMat3(out, m) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
385
|
+
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
|
386
|
+
// article "Quaternion Calculus and Fast Animation".
|
|
387
|
+
const fTrace = m[0] + m[4] + m[8];
|
|
388
|
+
let fRoot;
|
|
389
|
+
if (fTrace > 0.0) {
|
|
390
|
+
// |w| > 1/2, may as well choose w > 1/2
|
|
391
|
+
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
|
392
|
+
out[3] = 0.5 * fRoot;
|
|
393
|
+
fRoot = 0.5 / fRoot; // 1/(4w)
|
|
394
|
+
out[0] = (m[5] - m[7]) * fRoot;
|
|
395
|
+
out[1] = (m[6] - m[2]) * fRoot;
|
|
396
|
+
out[2] = (m[1] - m[3]) * fRoot;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
// |w| <= 1/2
|
|
400
|
+
let i = 0;
|
|
401
|
+
if (m[4] > m[0])
|
|
402
|
+
i = 1;
|
|
403
|
+
if (m[8] > m[i * 3 + i])
|
|
404
|
+
i = 2;
|
|
405
|
+
const j = (i + 1) % 3;
|
|
406
|
+
const k = (i + 2) % 3;
|
|
407
|
+
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
|
|
408
|
+
out[i] = 0.5 * fRoot;
|
|
409
|
+
fRoot = 0.5 / fRoot;
|
|
410
|
+
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
411
|
+
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
412
|
+
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
239
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion.
|
|
418
|
+
*
|
|
419
|
+
* @param {quat} out the receiving quaternion
|
|
420
|
+
* @param {Number} x Angle to rotate around X axis in degrees.
|
|
421
|
+
* @param {Number} y Angle to rotate around Y axis in degrees.
|
|
422
|
+
* @param {Number} z Angle to rotate around Z axis in degrees.
|
|
423
|
+
* @param {'zyx'|'xyz'|'yxz'|'yzx'|'zxy'|'zyx'} order Intrinsic order for conversion, default is zyx.
|
|
424
|
+
* @returns {quat} out
|
|
425
|
+
* @function
|
|
426
|
+
*/
|
|
427
|
+
// export function fromEuler(out, x, y, z, order = glMatrix.ANGLE_ORDER) {
|
|
428
|
+
// let halfToRad = Math.PI / 360;
|
|
429
|
+
// x *= halfToRad;
|
|
430
|
+
// z *= halfToRad;
|
|
431
|
+
// y *= halfToRad;
|
|
432
|
+
// let sx = Math.sin(x);
|
|
433
|
+
// let cx = Math.cos(x);
|
|
434
|
+
// let sy = Math.sin(y);
|
|
435
|
+
// let cy = Math.cos(y);
|
|
436
|
+
// let sz = Math.sin(z);
|
|
437
|
+
// let cz = Math.cos(z);
|
|
438
|
+
// switch (order) {
|
|
439
|
+
// case "xyz":
|
|
440
|
+
// out[0] = sx * cy * cz + cx * sy * sz;
|
|
441
|
+
// out[1] = cx * sy * cz - sx * cy * sz;
|
|
442
|
+
// out[2] = cx * cy * sz + sx * sy * cz;
|
|
443
|
+
// out[3] = cx * cy * cz - sx * sy * sz;
|
|
444
|
+
// break;
|
|
445
|
+
// case "xzy":
|
|
446
|
+
// out[0] = sx * cy * cz - cx * sy * sz;
|
|
447
|
+
// out[1] = cx * sy * cz - sx * cy * sz;
|
|
448
|
+
// out[2] = cx * cy * sz + sx * sy * cz;
|
|
449
|
+
// out[3] = cx * cy * cz + sx * sy * sz;
|
|
450
|
+
// break;
|
|
451
|
+
// case "yxz":
|
|
452
|
+
// out[0] = sx * cy * cz + cx * sy * sz;
|
|
453
|
+
// out[1] = cx * sy * cz - sx * cy * sz;
|
|
454
|
+
// out[2] = cx * cy * sz - sx * sy * cz;
|
|
455
|
+
// out[3] = cx * cy * cz + sx * sy * sz;
|
|
456
|
+
// break;
|
|
457
|
+
// case "yzx":
|
|
458
|
+
// out[0] = sx * cy * cz + cx * sy * sz;
|
|
459
|
+
// out[1] = cx * sy * cz + sx * cy * sz;
|
|
460
|
+
// out[2] = cx * cy * sz - sx * sy * cz;
|
|
461
|
+
// out[3] = cx * cy * cz - sx * sy * sz;
|
|
462
|
+
// break;
|
|
463
|
+
// case "zxy":
|
|
464
|
+
// out[0] = sx * cy * cz - cx * sy * sz;
|
|
465
|
+
// out[1] = cx * sy * cz + sx * cy * sz;
|
|
466
|
+
// out[2] = cx * cy * sz + sx * sy * cz;
|
|
467
|
+
// out[3] = cx * cy * cz - sx * sy * sz;
|
|
468
|
+
// break;
|
|
469
|
+
// case "zyx":
|
|
470
|
+
// out[0] = sx * cy * cz - cx * sy * sz;
|
|
471
|
+
// out[1] = cx * sy * cz + sx * cy * sz;
|
|
472
|
+
// out[2] = cx * cy * sz - sx * sy * cz;
|
|
473
|
+
// out[3] = cx * cy * cz + sx * sy * sz;
|
|
474
|
+
// break;
|
|
475
|
+
// default:
|
|
476
|
+
// throw new Error('Unknown angle order ' + order);
|
|
477
|
+
// }
|
|
478
|
+
// return out;
|
|
479
|
+
// }
|
|
480
|
+
/**
|
|
481
|
+
* Returns a string representation of a quaternion
|
|
482
|
+
*
|
|
483
|
+
* @param {ReadonlyQuat} a vector to represent as a string
|
|
484
|
+
* @returns {String} string representation of the vector
|
|
485
|
+
*/
|
|
240
486
|
export function str(a) {
|
|
241
|
-
|
|
487
|
+
return `quat(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]})`;
|
|
242
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Creates a new quat initialized with values from an existing quaternion
|
|
491
|
+
*
|
|
492
|
+
* @param {ReadonlyQuat} a quaternion to clone
|
|
493
|
+
* @returns {quat} a new quaternion
|
|
494
|
+
* @function
|
|
495
|
+
*/
|
|
243
496
|
export const clone = vec4.clone;
|
|
497
|
+
/**
|
|
498
|
+
* Creates a new quat initialized with the given values
|
|
499
|
+
*
|
|
500
|
+
* @param {Number} x X component
|
|
501
|
+
* @param {Number} y Y component
|
|
502
|
+
* @param {Number} z Z component
|
|
503
|
+
* @param {Number} w W component
|
|
504
|
+
* @returns {quat} a new quaternion
|
|
505
|
+
* @function
|
|
506
|
+
*/
|
|
244
507
|
export const fromValues = vec4.fromValues;
|
|
508
|
+
/**
|
|
509
|
+
* Copy the values from one quat to another
|
|
510
|
+
*
|
|
511
|
+
* @param {quat} out the receiving quaternion
|
|
512
|
+
* @param {ReadonlyQuat} a the source quaternion
|
|
513
|
+
* @returns {quat} out
|
|
514
|
+
* @function
|
|
515
|
+
*/
|
|
245
516
|
export const copy = vec4.copy;
|
|
517
|
+
/**
|
|
518
|
+
* Set the components of a quat to the given values
|
|
519
|
+
*
|
|
520
|
+
* @param {quat} out the receiving quaternion
|
|
521
|
+
* @param {Number} x X component
|
|
522
|
+
* @param {Number} y Y component
|
|
523
|
+
* @param {Number} z Z component
|
|
524
|
+
* @param {Number} w W component
|
|
525
|
+
* @returns {quat} out
|
|
526
|
+
* @function
|
|
527
|
+
*/
|
|
246
528
|
export const set = vec4.set;
|
|
529
|
+
/**
|
|
530
|
+
* Adds two quat's
|
|
531
|
+
*
|
|
532
|
+
* @param {quat} out the receiving quaternion
|
|
533
|
+
* @param {ReadonlyQuat} a the first operand
|
|
534
|
+
* @param {ReadonlyQuat} b the second operand
|
|
535
|
+
* @returns {quat} out
|
|
536
|
+
* @function
|
|
537
|
+
*/
|
|
247
538
|
export const add = vec4.add;
|
|
539
|
+
/**
|
|
540
|
+
* Alias for {@link quat.multiply}
|
|
541
|
+
* @function
|
|
542
|
+
*/
|
|
248
543
|
export const mul = multiply;
|
|
544
|
+
/**
|
|
545
|
+
* Scales a quat by a scalar number
|
|
546
|
+
*
|
|
547
|
+
* @param {quat} out the receiving vector
|
|
548
|
+
* @param {ReadonlyQuat} a the vector to scale
|
|
549
|
+
* @param {Number} b amount to scale the vector by
|
|
550
|
+
* @returns {quat} out
|
|
551
|
+
* @function
|
|
552
|
+
*/
|
|
249
553
|
export const scale = vec4.scale;
|
|
554
|
+
/**
|
|
555
|
+
* Calculates the dot product of two quat's
|
|
556
|
+
*
|
|
557
|
+
* @param {ReadonlyQuat} a the first operand
|
|
558
|
+
* @param {ReadonlyQuat} b the second operand
|
|
559
|
+
* @returns {Number} dot product of a and b
|
|
560
|
+
* @function
|
|
561
|
+
*/
|
|
250
562
|
export const dot = vec4.dot;
|
|
563
|
+
/**
|
|
564
|
+
* Performs a linear interpolation between two quat's
|
|
565
|
+
*
|
|
566
|
+
* @param {quat} out the receiving quaternion
|
|
567
|
+
* @param {ReadonlyQuat} a the first operand
|
|
568
|
+
* @param {ReadonlyQuat} b the second operand
|
|
569
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
570
|
+
* @returns {quat} out
|
|
571
|
+
* @function
|
|
572
|
+
*/
|
|
251
573
|
export const lerp = vec4.lerp;
|
|
574
|
+
/**
|
|
575
|
+
* Calculates the length of a quat
|
|
576
|
+
*
|
|
577
|
+
* @param {ReadonlyQuat} a vector to calculate length of
|
|
578
|
+
* @returns {Number} length of a
|
|
579
|
+
*/
|
|
252
580
|
export const length = vec4.length;
|
|
581
|
+
/**
|
|
582
|
+
* Alias for {@link quat.length}
|
|
583
|
+
* @function
|
|
584
|
+
*/
|
|
253
585
|
export const len = length;
|
|
586
|
+
/**
|
|
587
|
+
* Calculates the squared length of a quat
|
|
588
|
+
*
|
|
589
|
+
* @param {ReadonlyQuat} a vector to calculate squared length of
|
|
590
|
+
* @returns {Number} squared length of a
|
|
591
|
+
* @function
|
|
592
|
+
*/
|
|
254
593
|
export const squaredLength = vec4.squaredLength;
|
|
594
|
+
/**
|
|
595
|
+
* Alias for {@link quat.squaredLength}
|
|
596
|
+
* @function
|
|
597
|
+
*/
|
|
255
598
|
export const sqrLen = squaredLength;
|
|
599
|
+
/**
|
|
600
|
+
* Normalize a quat
|
|
601
|
+
*
|
|
602
|
+
* @param {quat} out the receiving quaternion
|
|
603
|
+
* @param {ReadonlyQuat} a quaternion to normalize
|
|
604
|
+
* @returns {quat} out
|
|
605
|
+
* @function
|
|
606
|
+
*/
|
|
256
607
|
export const normalize = vec4.normalize;
|
|
608
|
+
/**
|
|
609
|
+
* Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
|
|
610
|
+
*
|
|
611
|
+
* @param {ReadonlyQuat} a The first quaternion.
|
|
612
|
+
* @param {ReadonlyQuat} b The second quaternion.
|
|
613
|
+
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
614
|
+
*/
|
|
257
615
|
export const exactEquals = vec4.exactEquals;
|
|
616
|
+
/**
|
|
617
|
+
* Returns whether or not the quaternions point approximately to the same direction.
|
|
618
|
+
*
|
|
619
|
+
* Both quaternions are assumed to be unit length.
|
|
620
|
+
*
|
|
621
|
+
* @param {ReadonlyQuat} a The first unit quaternion.
|
|
622
|
+
* @param {ReadonlyQuat} b The second unit quaternion.
|
|
623
|
+
* @returns {Boolean} True if the quaternions are equal, false otherwise.
|
|
624
|
+
*/
|
|
258
625
|
export function equals(a, b) {
|
|
259
|
-
|
|
626
|
+
return Math.abs(vec4.dot(a, b)) >= 1 - glMatrix.EPSILON;
|
|
260
627
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
628
|
+
/**
|
|
629
|
+
* Sets a quaternion to represent the shortest rotation from one
|
|
630
|
+
* vector to another.
|
|
631
|
+
*
|
|
632
|
+
* Both vectors are assumed to be unit length.
|
|
633
|
+
*
|
|
634
|
+
* @param {quat} out the receiving quaternion.
|
|
635
|
+
* @param {ReadonlyVec3} a the initial vector
|
|
636
|
+
* @param {ReadonlyVec3} b the destination vector
|
|
637
|
+
* @returns {quat} out
|
|
638
|
+
*/
|
|
639
|
+
export const rotationTo = (function () {
|
|
640
|
+
const tmpvec3 = vec3.create();
|
|
641
|
+
const xUnitVec3 = vec3.fromValues(1, 0, 0);
|
|
642
|
+
const yUnitVec3 = vec3.fromValues(0, 1, 0);
|
|
643
|
+
return function (out, a, b) {
|
|
644
|
+
const dot = vec3.dot(a, b);
|
|
645
|
+
if (dot < -0.999999) {
|
|
646
|
+
vec3.cross(tmpvec3, xUnitVec3, a);
|
|
647
|
+
if (vec3.len(tmpvec3) < 0.000001)
|
|
648
|
+
vec3.cross(tmpvec3, yUnitVec3, a);
|
|
649
|
+
vec3.normalize(tmpvec3, tmpvec3);
|
|
650
|
+
setAxisAngle(out, tmpvec3, Math.PI);
|
|
651
|
+
return out;
|
|
652
|
+
}
|
|
653
|
+
else if (dot > 0.999999) {
|
|
654
|
+
out[0] = 0;
|
|
655
|
+
out[1] = 0;
|
|
656
|
+
out[2] = 0;
|
|
657
|
+
out[3] = 1;
|
|
658
|
+
return out;
|
|
659
|
+
}
|
|
660
|
+
vec3.cross(tmpvec3, a, b);
|
|
661
|
+
out[0] = tmpvec3[0];
|
|
662
|
+
out[1] = tmpvec3[1];
|
|
663
|
+
out[2] = tmpvec3[2];
|
|
664
|
+
out[3] = 1 + dot;
|
|
665
|
+
return normalize(out, out);
|
|
666
|
+
};
|
|
667
|
+
})();
|
|
668
|
+
/**
|
|
669
|
+
* Performs a spherical linear interpolation with two control points
|
|
670
|
+
*
|
|
671
|
+
* @param {quat} out the receiving quaternion
|
|
672
|
+
* @param {ReadonlyQuat} a the first operand
|
|
673
|
+
* @param {ReadonlyQuat} b the second operand
|
|
674
|
+
* @param {ReadonlyQuat} c the third operand
|
|
675
|
+
* @param {ReadonlyQuat} d the fourth operand
|
|
676
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
677
|
+
* @returns {quat} out
|
|
678
|
+
*/
|
|
679
|
+
export const sqlerp = (function () {
|
|
680
|
+
const temp1 = create();
|
|
681
|
+
const temp2 = create();
|
|
682
|
+
return function (out, a, b, c, d, t) {
|
|
683
|
+
slerp(temp1, a, d, t);
|
|
684
|
+
slerp(temp2, b, c, t);
|
|
685
|
+
slerp(out, temp1, temp2, 2 * t * (1 - t));
|
|
686
|
+
return out;
|
|
687
|
+
};
|
|
688
|
+
})();
|
|
689
|
+
/**
|
|
690
|
+
* Sets the specified quaternion with values corresponding to the given
|
|
691
|
+
* axes. Each axis is a vec3 and is expected to be unit length and
|
|
692
|
+
* perpendicular to all other specified axes.
|
|
693
|
+
*
|
|
694
|
+
* @param {ReadonlyVec3} view the vector representing the viewing direction
|
|
695
|
+
* @param {ReadonlyVec3} right the vector representing the local "right" direction
|
|
696
|
+
* @param {ReadonlyVec3} up the vector representing the local "up" direction
|
|
697
|
+
* @returns {quat} out
|
|
698
|
+
*/
|
|
699
|
+
export const setAxes = (function () {
|
|
700
|
+
const matr = mat3.create();
|
|
701
|
+
return function (out, view, right, up) {
|
|
702
|
+
matr[0] = right[0];
|
|
703
|
+
matr[3] = right[1];
|
|
704
|
+
matr[6] = right[2];
|
|
705
|
+
matr[1] = up[0];
|
|
706
|
+
matr[4] = up[1];
|
|
707
|
+
matr[7] = up[2];
|
|
708
|
+
matr[2] = -view[0];
|
|
709
|
+
matr[5] = -view[1];
|
|
710
|
+
matr[8] = -view[2];
|
|
711
|
+
return normalize(out, fromMat3(out, matr));
|
|
712
|
+
};
|
|
713
|
+
})();
|