@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
|
@@ -1,482 +1,720 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
1
3
|
import * as glMatrix from './common.js';
|
|
2
4
|
import * as quat from './quat.js';
|
|
3
5
|
import * as mat4 from './mat4.js';
|
|
6
|
+
/**
|
|
7
|
+
* Dual Quaternion<br>
|
|
8
|
+
* Format: [real, dual]<br>
|
|
9
|
+
* Quaternion format: XYZW<br>
|
|
10
|
+
* Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.<br>
|
|
11
|
+
* @module quat2
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new identity dual quat
|
|
15
|
+
*
|
|
16
|
+
* @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]
|
|
17
|
+
*/
|
|
4
18
|
export function create() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
dq[3] = 1;
|
|
18
|
-
return dq;
|
|
19
|
+
let dq = new glMatrix.ARRAY_TYPE(8);
|
|
20
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
21
|
+
dq[0] = 0;
|
|
22
|
+
dq[1] = 0;
|
|
23
|
+
dq[2] = 0;
|
|
24
|
+
dq[4] = 0;
|
|
25
|
+
dq[5] = 0;
|
|
26
|
+
dq[6] = 0;
|
|
27
|
+
dq[7] = 0;
|
|
28
|
+
}
|
|
29
|
+
dq[3] = 1;
|
|
30
|
+
return dq;
|
|
19
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new quat initialized with values from an existing quaternion
|
|
34
|
+
*
|
|
35
|
+
* @param {ReadonlyQuat2} a dual quaternion to clone
|
|
36
|
+
* @returns {quat2} new dual quaternion
|
|
37
|
+
* @function
|
|
38
|
+
*/
|
|
20
39
|
export function clone(a) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
let dq = new glMatrix.ARRAY_TYPE(8);
|
|
41
|
+
dq[0] = a[0];
|
|
42
|
+
dq[1] = a[1];
|
|
43
|
+
dq[2] = a[2];
|
|
44
|
+
dq[3] = a[3];
|
|
45
|
+
dq[4] = a[4];
|
|
46
|
+
dq[5] = a[5];
|
|
47
|
+
dq[6] = a[6];
|
|
48
|
+
dq[7] = a[7];
|
|
49
|
+
return dq;
|
|
31
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new dual quat initialized with the given values
|
|
53
|
+
*
|
|
54
|
+
* @param {Number} x1 X component
|
|
55
|
+
* @param {Number} y1 Y component
|
|
56
|
+
* @param {Number} z1 Z component
|
|
57
|
+
* @param {Number} w1 W component
|
|
58
|
+
* @param {Number} x2 X component
|
|
59
|
+
* @param {Number} y2 Y component
|
|
60
|
+
* @param {Number} z2 Z component
|
|
61
|
+
* @param {Number} w2 W component
|
|
62
|
+
* @returns {quat2} new dual quaternion
|
|
63
|
+
* @function
|
|
64
|
+
*/
|
|
32
65
|
export function fromValues(x1, y1, z1, w1, x2, y2, z2, w2) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
let dq = new glMatrix.ARRAY_TYPE(8);
|
|
67
|
+
dq[0] = x1;
|
|
68
|
+
dq[1] = y1;
|
|
69
|
+
dq[2] = z1;
|
|
70
|
+
dq[3] = w1;
|
|
71
|
+
dq[4] = x2;
|
|
72
|
+
dq[5] = y2;
|
|
73
|
+
dq[6] = z2;
|
|
74
|
+
dq[7] = w2;
|
|
75
|
+
return dq;
|
|
43
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new dual quat from the given values (quat and translation)
|
|
79
|
+
*
|
|
80
|
+
* @param {Number} x1 X component
|
|
81
|
+
* @param {Number} y1 Y component
|
|
82
|
+
* @param {Number} z1 Z component
|
|
83
|
+
* @param {Number} w1 W component
|
|
84
|
+
* @param {Number} x2 X component (translation)
|
|
85
|
+
* @param {Number} y2 Y component (translation)
|
|
86
|
+
* @param {Number} z2 Z component (translation)
|
|
87
|
+
* @returns {quat2} new dual quaternion
|
|
88
|
+
* @function
|
|
89
|
+
*/
|
|
44
90
|
export function fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
dq[7] = -ax * x1 - ay * y1 - az * z1;
|
|
57
|
-
return dq;
|
|
91
|
+
let dq = new glMatrix.ARRAY_TYPE(8);
|
|
92
|
+
dq[0] = x1;
|
|
93
|
+
dq[1] = y1;
|
|
94
|
+
dq[2] = z1;
|
|
95
|
+
dq[3] = w1;
|
|
96
|
+
let ax = x2 * 0.5, ay = y2 * 0.5, az = z2 * 0.5;
|
|
97
|
+
dq[4] = ax * w1 + ay * z1 - az * y1;
|
|
98
|
+
dq[5] = ay * w1 + az * x1 - ax * z1;
|
|
99
|
+
dq[6] = az * w1 + ax * y1 - ay * x1;
|
|
100
|
+
dq[7] = -ax * x1 - ay * y1 - az * z1;
|
|
101
|
+
return dq;
|
|
58
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a dual quat from a quaternion and a translation
|
|
105
|
+
*
|
|
106
|
+
* @param {ReadonlyQuat2} dual quaternion receiving operation result
|
|
107
|
+
* @param {ReadonlyQuat} q a normalized quaternion
|
|
108
|
+
* @param {ReadonlyVec3} t translation vector
|
|
109
|
+
* @returns {quat2} dual quaternion receiving operation result
|
|
110
|
+
* @function
|
|
111
|
+
*/
|
|
59
112
|
export function fromRotationTranslation(out, q, t) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
out[3] = bw;
|
|
71
|
-
out[4] = ax * bw + ay * bz - az * by;
|
|
72
|
-
out[5] = ay * bw + az * bx - ax * bz;
|
|
73
|
-
out[6] = az * bw + ax * by - ay * bx;
|
|
74
|
-
out[7] = -ax * bx - ay * by - az * bz;
|
|
75
|
-
return out;
|
|
113
|
+
let ax = t[0] * 0.5, ay = t[1] * 0.5, az = t[2] * 0.5, bx = q[0], by = q[1], bz = q[2], bw = q[3];
|
|
114
|
+
out[0] = bx;
|
|
115
|
+
out[1] = by;
|
|
116
|
+
out[2] = bz;
|
|
117
|
+
out[3] = bw;
|
|
118
|
+
out[4] = ax * bw + ay * bz - az * by;
|
|
119
|
+
out[5] = ay * bw + az * bx - ax * bz;
|
|
120
|
+
out[6] = az * bw + ax * by - ay * bx;
|
|
121
|
+
out[7] = -ax * bx - ay * by - az * bz;
|
|
122
|
+
return out;
|
|
76
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates a dual quat from a translation
|
|
126
|
+
*
|
|
127
|
+
* @param {ReadonlyQuat2} dual quaternion receiving operation result
|
|
128
|
+
* @param {ReadonlyVec3} t translation vector
|
|
129
|
+
* @returns {quat2} dual quaternion receiving operation result
|
|
130
|
+
* @function
|
|
131
|
+
*/
|
|
77
132
|
export function fromTranslation(out, t) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
133
|
+
out[0] = 0;
|
|
134
|
+
out[1] = 0;
|
|
135
|
+
out[2] = 0;
|
|
136
|
+
out[3] = 1;
|
|
137
|
+
out[4] = t[0] * 0.5;
|
|
138
|
+
out[5] = t[1] * 0.5;
|
|
139
|
+
out[6] = t[2] * 0.5;
|
|
140
|
+
out[7] = 0;
|
|
141
|
+
return out;
|
|
87
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Creates a dual quat from a quaternion
|
|
145
|
+
*
|
|
146
|
+
* @param {ReadonlyQuat2} dual quaternion receiving operation result
|
|
147
|
+
* @param {ReadonlyQuat} q the quaternion
|
|
148
|
+
* @returns {quat2} dual quaternion receiving operation result
|
|
149
|
+
* @function
|
|
150
|
+
*/
|
|
88
151
|
export function fromRotation(out, q) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
152
|
+
out[0] = q[0];
|
|
153
|
+
out[1] = q[1];
|
|
154
|
+
out[2] = q[2];
|
|
155
|
+
out[3] = q[3];
|
|
156
|
+
out[4] = 0;
|
|
157
|
+
out[5] = 0;
|
|
158
|
+
out[6] = 0;
|
|
159
|
+
out[7] = 0;
|
|
160
|
+
return out;
|
|
98
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new dual quat from a matrix (4x4)
|
|
164
|
+
*
|
|
165
|
+
* @param {quat2} out the dual quaternion
|
|
166
|
+
* @param {ReadonlyMat4} a the matrix
|
|
167
|
+
* @returns {quat2} dual quat receiving operation result
|
|
168
|
+
* @function
|
|
169
|
+
*/
|
|
99
170
|
export function fromMat4(out, a) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
171
|
+
//TODO Optimize this
|
|
172
|
+
let outer = quat.create();
|
|
173
|
+
mat4.getRotation(outer, a);
|
|
174
|
+
let t = new glMatrix.ARRAY_TYPE(3);
|
|
175
|
+
mat4.getTranslation(t, a);
|
|
176
|
+
fromRotationTranslation(out, outer, t);
|
|
177
|
+
return out;
|
|
106
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Copy the values from one dual quat to another
|
|
181
|
+
*
|
|
182
|
+
* @param {quat2} out the receiving dual quaternion
|
|
183
|
+
* @param {ReadonlyQuat2} a the source dual quaternion
|
|
184
|
+
* @returns {quat2} out
|
|
185
|
+
* @function
|
|
186
|
+
*/
|
|
107
187
|
export function copy(out, a) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
188
|
+
out[0] = a[0];
|
|
189
|
+
out[1] = a[1];
|
|
190
|
+
out[2] = a[2];
|
|
191
|
+
out[3] = a[3];
|
|
192
|
+
out[4] = a[4];
|
|
193
|
+
out[5] = a[5];
|
|
194
|
+
out[6] = a[6];
|
|
195
|
+
out[7] = a[7];
|
|
196
|
+
return out;
|
|
117
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Set a dual quat to the identity dual quaternion
|
|
200
|
+
*
|
|
201
|
+
* @param {quat2} out the receiving quaternion
|
|
202
|
+
* @returns {quat2} out
|
|
203
|
+
*/
|
|
118
204
|
export function identity(out) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
205
|
+
out[0] = 0;
|
|
206
|
+
out[1] = 0;
|
|
207
|
+
out[2] = 0;
|
|
208
|
+
out[3] = 1;
|
|
209
|
+
out[4] = 0;
|
|
210
|
+
out[5] = 0;
|
|
211
|
+
out[6] = 0;
|
|
212
|
+
out[7] = 0;
|
|
213
|
+
return out;
|
|
128
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Set the components of a dual quat to the given values
|
|
217
|
+
*
|
|
218
|
+
* @param {quat2} out the receiving quaternion
|
|
219
|
+
* @param {Number} x1 X component
|
|
220
|
+
* @param {Number} y1 Y component
|
|
221
|
+
* @param {Number} z1 Z component
|
|
222
|
+
* @param {Number} w1 W component
|
|
223
|
+
* @param {Number} x2 X component
|
|
224
|
+
* @param {Number} y2 Y component
|
|
225
|
+
* @param {Number} z2 Z component
|
|
226
|
+
* @param {Number} w2 W component
|
|
227
|
+
* @returns {quat2} out
|
|
228
|
+
* @function
|
|
229
|
+
*/
|
|
129
230
|
export function set(out, x1, y1, z1, w1, x2, y2, z2, w2) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
231
|
+
out[0] = x1;
|
|
232
|
+
out[1] = y1;
|
|
233
|
+
out[2] = z1;
|
|
234
|
+
out[3] = w1;
|
|
235
|
+
out[4] = x2;
|
|
236
|
+
out[5] = y2;
|
|
237
|
+
out[6] = z2;
|
|
238
|
+
out[7] = w2;
|
|
239
|
+
return out;
|
|
139
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Gets the real part of a dual quat
|
|
243
|
+
* @param {quat} out real part
|
|
244
|
+
* @param {ReadonlyQuat2} a Dual Quaternion
|
|
245
|
+
* @return {quat} real part
|
|
246
|
+
*/
|
|
140
247
|
export const getReal = quat.copy;
|
|
248
|
+
/**
|
|
249
|
+
* Gets the dual part of a dual quat
|
|
250
|
+
* @param {quat} out dual part
|
|
251
|
+
* @param {ReadonlyQuat2} a Dual Quaternion
|
|
252
|
+
* @return {quat} dual part
|
|
253
|
+
*/
|
|
141
254
|
export function getDual(out, a) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
255
|
+
out[0] = a[4];
|
|
256
|
+
out[1] = a[5];
|
|
257
|
+
out[2] = a[6];
|
|
258
|
+
out[3] = a[7];
|
|
259
|
+
return out;
|
|
147
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Set the real component of a dual quat to the given quaternion
|
|
263
|
+
*
|
|
264
|
+
* @param {quat2} out the receiving quaternion
|
|
265
|
+
* @param {ReadonlyQuat} q a quaternion representing the real part
|
|
266
|
+
* @returns {quat2} out
|
|
267
|
+
* @function
|
|
268
|
+
*/
|
|
148
269
|
export const setReal = quat.copy;
|
|
270
|
+
/**
|
|
271
|
+
* Set the dual component of a dual quat to the given quaternion
|
|
272
|
+
*
|
|
273
|
+
* @param {quat2} out the receiving quaternion
|
|
274
|
+
* @param {ReadonlyQuat} q a quaternion representing the dual part
|
|
275
|
+
* @returns {quat2} out
|
|
276
|
+
* @function
|
|
277
|
+
*/
|
|
149
278
|
export function setDual(out, q) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
279
|
+
out[4] = q[0];
|
|
280
|
+
out[5] = q[1];
|
|
281
|
+
out[6] = q[2];
|
|
282
|
+
out[7] = q[3];
|
|
283
|
+
return out;
|
|
155
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Gets the translation of a normalized dual quat
|
|
287
|
+
* @param {vec3} out translation
|
|
288
|
+
* @param {ReadonlyQuat2} a Dual Quaternion to be decomposed
|
|
289
|
+
* @return {vec3} translation
|
|
290
|
+
*/
|
|
156
291
|
export function getTranslation(out, a) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
by = -a[1],
|
|
163
|
-
bz = -a[2],
|
|
164
|
-
bw = a[3];
|
|
165
|
-
out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
|
|
166
|
-
out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
|
|
167
|
-
out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
|
|
168
|
-
return out;
|
|
292
|
+
let ax = a[4], ay = a[5], az = a[6], aw = a[7], bx = -a[0], by = -a[1], bz = -a[2], bw = a[3];
|
|
293
|
+
out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
|
|
294
|
+
out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
|
|
295
|
+
out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
|
|
296
|
+
return out;
|
|
169
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Translates a dual quat by the given vector
|
|
300
|
+
*
|
|
301
|
+
* @param {quat2} out the receiving dual quaternion
|
|
302
|
+
* @param {ReadonlyQuat2} a the dual quaternion to translate
|
|
303
|
+
* @param {ReadonlyVec3} v vector to translate by
|
|
304
|
+
* @returns {quat2} out
|
|
305
|
+
*/
|
|
170
306
|
export function translate(out, a, v) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
aw2 = a[7];
|
|
182
|
-
out[0] = ax1;
|
|
183
|
-
out[1] = ay1;
|
|
184
|
-
out[2] = az1;
|
|
185
|
-
out[3] = aw1;
|
|
186
|
-
out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
|
|
187
|
-
out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
|
|
188
|
-
out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
|
|
189
|
-
out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
|
|
190
|
-
return out;
|
|
307
|
+
let ax1 = a[0], ay1 = a[1], az1 = a[2], aw1 = a[3], bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5, ax2 = a[4], ay2 = a[5], az2 = a[6], aw2 = a[7];
|
|
308
|
+
out[0] = ax1;
|
|
309
|
+
out[1] = ay1;
|
|
310
|
+
out[2] = az1;
|
|
311
|
+
out[3] = aw1;
|
|
312
|
+
out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;
|
|
313
|
+
out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;
|
|
314
|
+
out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;
|
|
315
|
+
out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;
|
|
316
|
+
return out;
|
|
191
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Rotates a dual quat around the X axis
|
|
320
|
+
*
|
|
321
|
+
* @param {quat2} out the receiving dual quaternion
|
|
322
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
323
|
+
* @param {number} rad how far should the rotation be
|
|
324
|
+
* @returns {quat2} out
|
|
325
|
+
*/
|
|
192
326
|
export function rotateX(out, a, rad) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
205
|
-
quat.rotateX(out, a, rad);
|
|
206
|
-
bx = out[0];
|
|
207
|
-
by = out[1];
|
|
208
|
-
bz = out[2];
|
|
209
|
-
bw = out[3];
|
|
210
|
-
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
211
|
-
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
212
|
-
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
213
|
-
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
214
|
-
return out;
|
|
327
|
+
let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
328
|
+
quat.rotateX(out, a, rad);
|
|
329
|
+
bx = out[0];
|
|
330
|
+
by = out[1];
|
|
331
|
+
bz = out[2];
|
|
332
|
+
bw = out[3];
|
|
333
|
+
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
334
|
+
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
335
|
+
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
336
|
+
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
337
|
+
return out;
|
|
215
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Rotates a dual quat around the Y axis
|
|
341
|
+
*
|
|
342
|
+
* @param {quat2} out the receiving dual quaternion
|
|
343
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
344
|
+
* @param {number} rad how far should the rotation be
|
|
345
|
+
* @returns {quat2} out
|
|
346
|
+
*/
|
|
216
347
|
export function rotateY(out, a, rad) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
229
|
-
quat.rotateY(out, a, rad);
|
|
230
|
-
bx = out[0];
|
|
231
|
-
by = out[1];
|
|
232
|
-
bz = out[2];
|
|
233
|
-
bw = out[3];
|
|
234
|
-
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
235
|
-
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
236
|
-
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
237
|
-
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
238
|
-
return out;
|
|
348
|
+
let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
349
|
+
quat.rotateY(out, a, rad);
|
|
350
|
+
bx = out[0];
|
|
351
|
+
by = out[1];
|
|
352
|
+
bz = out[2];
|
|
353
|
+
bw = out[3];
|
|
354
|
+
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
355
|
+
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
356
|
+
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
357
|
+
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
358
|
+
return out;
|
|
239
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Rotates a dual quat around the Z axis
|
|
362
|
+
*
|
|
363
|
+
* @param {quat2} out the receiving dual quaternion
|
|
364
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
365
|
+
* @param {number} rad how far should the rotation be
|
|
366
|
+
* @returns {quat2} out
|
|
367
|
+
*/
|
|
240
368
|
export function rotateZ(out, a, rad) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
253
|
-
quat.rotateZ(out, a, rad);
|
|
254
|
-
bx = out[0];
|
|
255
|
-
by = out[1];
|
|
256
|
-
bz = out[2];
|
|
257
|
-
bw = out[3];
|
|
258
|
-
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
259
|
-
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
260
|
-
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
261
|
-
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
262
|
-
return out;
|
|
369
|
+
let bx = -a[0], by = -a[1], bz = -a[2], bw = a[3], ax = a[4], ay = a[5], az = a[6], aw = a[7], ax1 = ax * bw + aw * bx + ay * bz - az * by, ay1 = ay * bw + aw * by + az * bx - ax * bz, az1 = az * bw + aw * bz + ax * by - ay * bx, aw1 = aw * bw - ax * bx - ay * by - az * bz;
|
|
370
|
+
quat.rotateZ(out, a, rad);
|
|
371
|
+
bx = out[0];
|
|
372
|
+
by = out[1];
|
|
373
|
+
bz = out[2];
|
|
374
|
+
bw = out[3];
|
|
375
|
+
out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
376
|
+
out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
377
|
+
out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
378
|
+
out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
379
|
+
return out;
|
|
263
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Rotates a dual quat by a given quaternion (a * q)
|
|
383
|
+
*
|
|
384
|
+
* @param {quat2} out the receiving dual quaternion
|
|
385
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
386
|
+
* @param {ReadonlyQuat} q quaternion to rotate by
|
|
387
|
+
* @returns {quat2} out
|
|
388
|
+
*/
|
|
264
389
|
export function rotateByQuatAppend(out, a, q) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
az = a[6];
|
|
280
|
-
aw = a[7];
|
|
281
|
-
out[4] = ax * qw + aw * qx + ay * qz - az * qy;
|
|
282
|
-
out[5] = ay * qw + aw * qy + az * qx - ax * qz;
|
|
283
|
-
out[6] = az * qw + aw * qz + ax * qy - ay * qx;
|
|
284
|
-
out[7] = aw * qw - ax * qx - ay * qy - az * qz;
|
|
285
|
-
return out;
|
|
390
|
+
let qx = q[0], qy = q[1], qz = q[2], qw = q[3], ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
391
|
+
out[0] = ax * qw + aw * qx + ay * qz - az * qy;
|
|
392
|
+
out[1] = ay * qw + aw * qy + az * qx - ax * qz;
|
|
393
|
+
out[2] = az * qw + aw * qz + ax * qy - ay * qx;
|
|
394
|
+
out[3] = aw * qw - ax * qx - ay * qy - az * qz;
|
|
395
|
+
ax = a[4];
|
|
396
|
+
ay = a[5];
|
|
397
|
+
az = a[6];
|
|
398
|
+
aw = a[7];
|
|
399
|
+
out[4] = ax * qw + aw * qx + ay * qz - az * qy;
|
|
400
|
+
out[5] = ay * qw + aw * qy + az * qx - ax * qz;
|
|
401
|
+
out[6] = az * qw + aw * qz + ax * qy - ay * qx;
|
|
402
|
+
out[7] = aw * qw - ax * qx - ay * qy - az * qz;
|
|
403
|
+
return out;
|
|
286
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Rotates a dual quat by a given quaternion (q * a)
|
|
407
|
+
*
|
|
408
|
+
* @param {quat2} out the receiving dual quaternion
|
|
409
|
+
* @param {ReadonlyQuat} q quaternion to rotate by
|
|
410
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
411
|
+
* @returns {quat2} out
|
|
412
|
+
*/
|
|
287
413
|
export function rotateByQuatPrepend(out, q, a) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
bz = a[6];
|
|
303
|
-
bw = a[7];
|
|
304
|
-
out[4] = qx * bw + qw * bx + qy * bz - qz * by;
|
|
305
|
-
out[5] = qy * bw + qw * by + qz * bx - qx * bz;
|
|
306
|
-
out[6] = qz * bw + qw * bz + qx * by - qy * bx;
|
|
307
|
-
out[7] = qw * bw - qx * bx - qy * by - qz * bz;
|
|
308
|
-
return out;
|
|
414
|
+
let qx = q[0], qy = q[1], qz = q[2], qw = q[3], bx = a[0], by = a[1], bz = a[2], bw = a[3];
|
|
415
|
+
out[0] = qx * bw + qw * bx + qy * bz - qz * by;
|
|
416
|
+
out[1] = qy * bw + qw * by + qz * bx - qx * bz;
|
|
417
|
+
out[2] = qz * bw + qw * bz + qx * by - qy * bx;
|
|
418
|
+
out[3] = qw * bw - qx * bx - qy * by - qz * bz;
|
|
419
|
+
bx = a[4];
|
|
420
|
+
by = a[5];
|
|
421
|
+
bz = a[6];
|
|
422
|
+
bw = a[7];
|
|
423
|
+
out[4] = qx * bw + qw * bx + qy * bz - qz * by;
|
|
424
|
+
out[5] = qy * bw + qw * by + qz * bx - qx * bz;
|
|
425
|
+
out[6] = qz * bw + qw * bz + qx * by - qy * bx;
|
|
426
|
+
out[7] = qw * bw - qx * bx - qy * by - qz * bz;
|
|
427
|
+
return out;
|
|
309
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Rotates a dual quat around a given axis. Does the normalisation automatically
|
|
431
|
+
*
|
|
432
|
+
* @param {quat2} out the receiving dual quaternion
|
|
433
|
+
* @param {ReadonlyQuat2} a the dual quaternion to rotate
|
|
434
|
+
* @param {ReadonlyVec3} axis the axis to rotate around
|
|
435
|
+
* @param {Number} rad how far the rotation should be
|
|
436
|
+
* @returns {quat2} out
|
|
437
|
+
*/
|
|
310
438
|
export function rotateAroundAxis(out, a, axis, rad) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
aw = a[7];
|
|
334
|
-
out[4] = ax * bw + aw * bx + ay * bz - az * by;
|
|
335
|
-
out[5] = ay * bw + aw * by + az * bx - ax * bz;
|
|
336
|
-
out[6] = az * bw + aw * bz + ax * by - ay * bx;
|
|
337
|
-
out[7] = aw * bw - ax * bx - ay * by - az * bz;
|
|
338
|
-
return out;
|
|
439
|
+
//Special case for rad = 0
|
|
440
|
+
if (Math.abs(rad) < glMatrix.EPSILON) {
|
|
441
|
+
return copy(out, a);
|
|
442
|
+
}
|
|
443
|
+
let axisLength = Math.sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);
|
|
444
|
+
rad = rad * 0.5;
|
|
445
|
+
let s = Math.sin(rad);
|
|
446
|
+
let bx = (s * axis[0]) / axisLength;
|
|
447
|
+
let by = (s * axis[1]) / axisLength;
|
|
448
|
+
let bz = (s * axis[2]) / axisLength;
|
|
449
|
+
let bw = Math.cos(rad);
|
|
450
|
+
let ax1 = a[0], ay1 = a[1], az1 = a[2], aw1 = a[3];
|
|
451
|
+
out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;
|
|
452
|
+
out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;
|
|
453
|
+
out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;
|
|
454
|
+
out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;
|
|
455
|
+
let ax = a[4], ay = a[5], az = a[6], aw = a[7];
|
|
456
|
+
out[4] = ax * bw + aw * bx + ay * bz - az * by;
|
|
457
|
+
out[5] = ay * bw + aw * by + az * bx - ax * bz;
|
|
458
|
+
out[6] = az * bw + aw * bz + ax * by - ay * bx;
|
|
459
|
+
out[7] = aw * bw - ax * bx - ay * by - az * bz;
|
|
460
|
+
return out;
|
|
339
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* Adds two dual quat's
|
|
464
|
+
*
|
|
465
|
+
* @param {quat2} out the receiving dual quaternion
|
|
466
|
+
* @param {ReadonlyQuat2} a the first operand
|
|
467
|
+
* @param {ReadonlyQuat2} b the second operand
|
|
468
|
+
* @returns {quat2} out
|
|
469
|
+
* @function
|
|
470
|
+
*/
|
|
340
471
|
export function add(out, a, b) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
472
|
+
out[0] = a[0] + b[0];
|
|
473
|
+
out[1] = a[1] + b[1];
|
|
474
|
+
out[2] = a[2] + b[2];
|
|
475
|
+
out[3] = a[3] + b[3];
|
|
476
|
+
out[4] = a[4] + b[4];
|
|
477
|
+
out[5] = a[5] + b[5];
|
|
478
|
+
out[6] = a[6] + b[6];
|
|
479
|
+
out[7] = a[7] + b[7];
|
|
480
|
+
return out;
|
|
350
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* Multiplies two dual quat's
|
|
484
|
+
*
|
|
485
|
+
* @param {quat2} out the receiving dual quaternion
|
|
486
|
+
* @param {ReadonlyQuat2} a the first operand
|
|
487
|
+
* @param {ReadonlyQuat2} b the second operand
|
|
488
|
+
* @returns {quat2} out
|
|
489
|
+
*/
|
|
351
490
|
export function multiply(out, a, b) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
bz0 = b[2],
|
|
367
|
-
bw0 = b[3];
|
|
368
|
-
out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
|
|
369
|
-
out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
|
|
370
|
-
out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
|
|
371
|
-
out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
|
|
372
|
-
out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;
|
|
373
|
-
out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;
|
|
374
|
-
out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;
|
|
375
|
-
out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;
|
|
376
|
-
return out;
|
|
491
|
+
let ax0 = a[0], ay0 = a[1], az0 = a[2], aw0 = a[3], bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7], ax1 = a[4], ay1 = a[5], az1 = a[6], aw1 = a[7], bx0 = b[0], by0 = b[1], bz0 = b[2], bw0 = b[3];
|
|
492
|
+
out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;
|
|
493
|
+
out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;
|
|
494
|
+
out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;
|
|
495
|
+
out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;
|
|
496
|
+
out[4] =
|
|
497
|
+
ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;
|
|
498
|
+
out[5] =
|
|
499
|
+
ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;
|
|
500
|
+
out[6] =
|
|
501
|
+
az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;
|
|
502
|
+
out[7] =
|
|
503
|
+
aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;
|
|
504
|
+
return out;
|
|
377
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Alias for {@link quat2.multiply}
|
|
508
|
+
* @function
|
|
509
|
+
*/
|
|
378
510
|
export const mul = multiply;
|
|
511
|
+
/**
|
|
512
|
+
* Scales a dual quat by a scalar number
|
|
513
|
+
*
|
|
514
|
+
* @param {quat2} out the receiving dual quat
|
|
515
|
+
* @param {ReadonlyQuat2} a the dual quat to scale
|
|
516
|
+
* @param {Number} b amount to scale the dual quat by
|
|
517
|
+
* @returns {quat2} out
|
|
518
|
+
* @function
|
|
519
|
+
*/
|
|
379
520
|
export function scale(out, a, b) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
521
|
+
out[0] = a[0] * b;
|
|
522
|
+
out[1] = a[1] * b;
|
|
523
|
+
out[2] = a[2] * b;
|
|
524
|
+
out[3] = a[3] * b;
|
|
525
|
+
out[4] = a[4] * b;
|
|
526
|
+
out[5] = a[5] * b;
|
|
527
|
+
out[6] = a[6] * b;
|
|
528
|
+
out[7] = a[7] * b;
|
|
529
|
+
return out;
|
|
389
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* Calculates the dot product of two dual quat's (The dot product of the real parts)
|
|
533
|
+
*
|
|
534
|
+
* @param {ReadonlyQuat2} a the first operand
|
|
535
|
+
* @param {ReadonlyQuat2} b the second operand
|
|
536
|
+
* @returns {Number} dot product of a and b
|
|
537
|
+
* @function
|
|
538
|
+
*/
|
|
390
539
|
export const dot = quat.dot;
|
|
540
|
+
/**
|
|
541
|
+
* Performs a linear interpolation between two dual quats's
|
|
542
|
+
* NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)
|
|
543
|
+
*
|
|
544
|
+
* @param {quat2} out the receiving dual quat
|
|
545
|
+
* @param {ReadonlyQuat2} a the first operand
|
|
546
|
+
* @param {ReadonlyQuat2} b the second operand
|
|
547
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
548
|
+
* @returns {quat2} out
|
|
549
|
+
*/
|
|
391
550
|
export function lerp(out, a, b, t) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
551
|
+
let mt = 1 - t;
|
|
552
|
+
if (dot(a, b) < 0)
|
|
553
|
+
t = -t;
|
|
554
|
+
out[0] = a[0] * mt + b[0] * t;
|
|
555
|
+
out[1] = a[1] * mt + b[1] * t;
|
|
556
|
+
out[2] = a[2] * mt + b[2] * t;
|
|
557
|
+
out[3] = a[3] * mt + b[3] * t;
|
|
558
|
+
out[4] = a[4] * mt + b[4] * t;
|
|
559
|
+
out[5] = a[5] * mt + b[5] * t;
|
|
560
|
+
out[6] = a[6] * mt + b[6] * t;
|
|
561
|
+
out[7] = a[7] * mt + b[7] * t;
|
|
562
|
+
return out;
|
|
403
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper
|
|
566
|
+
*
|
|
567
|
+
* @param {quat2} out the receiving dual quaternion
|
|
568
|
+
* @param {ReadonlyQuat2} a dual quat to calculate inverse of
|
|
569
|
+
* @returns {quat2} out
|
|
570
|
+
*/
|
|
404
571
|
export function invert(out, a) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
572
|
+
let sqlen = squaredLength(a);
|
|
573
|
+
out[0] = -a[0] / sqlen;
|
|
574
|
+
out[1] = -a[1] / sqlen;
|
|
575
|
+
out[2] = -a[2] / sqlen;
|
|
576
|
+
out[3] = a[3] / sqlen;
|
|
577
|
+
out[4] = -a[4] / sqlen;
|
|
578
|
+
out[5] = -a[5] / sqlen;
|
|
579
|
+
out[6] = -a[6] / sqlen;
|
|
580
|
+
out[7] = a[7] / sqlen;
|
|
581
|
+
return out;
|
|
415
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* Calculates the conjugate of a dual quat
|
|
585
|
+
* If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.
|
|
586
|
+
*
|
|
587
|
+
* @param {quat2} out the receiving quaternion
|
|
588
|
+
* @param {ReadonlyQuat2} a quat to calculate conjugate of
|
|
589
|
+
* @returns {quat2} out
|
|
590
|
+
*/
|
|
416
591
|
export function conjugate(out, a) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
592
|
+
out[0] = -a[0];
|
|
593
|
+
out[1] = -a[1];
|
|
594
|
+
out[2] = -a[2];
|
|
595
|
+
out[3] = a[3];
|
|
596
|
+
out[4] = -a[4];
|
|
597
|
+
out[5] = -a[5];
|
|
598
|
+
out[6] = -a[6];
|
|
599
|
+
out[7] = a[7];
|
|
600
|
+
return out;
|
|
426
601
|
}
|
|
602
|
+
/**
|
|
603
|
+
* Calculates the length of a dual quat
|
|
604
|
+
*
|
|
605
|
+
* @param {ReadonlyQuat2} a dual quat to calculate length of
|
|
606
|
+
* @returns {Number} length of a
|
|
607
|
+
* @function
|
|
608
|
+
*/
|
|
427
609
|
export const length = quat.length;
|
|
610
|
+
/**
|
|
611
|
+
* Alias for {@link quat2.length}
|
|
612
|
+
* @function
|
|
613
|
+
*/
|
|
428
614
|
export const len = length;
|
|
615
|
+
/**
|
|
616
|
+
* Calculates the squared length of a dual quat
|
|
617
|
+
*
|
|
618
|
+
* @param {ReadonlyQuat2} a dual quat to calculate squared length of
|
|
619
|
+
* @returns {Number} squared length of a
|
|
620
|
+
* @function
|
|
621
|
+
*/
|
|
429
622
|
export const squaredLength = quat.squaredLength;
|
|
623
|
+
/**
|
|
624
|
+
* Alias for {@link quat2.squaredLength}
|
|
625
|
+
* @function
|
|
626
|
+
*/
|
|
430
627
|
export const sqrLen = squaredLength;
|
|
628
|
+
/**
|
|
629
|
+
* Normalize a dual quat
|
|
630
|
+
*
|
|
631
|
+
* @param {quat2} out the receiving dual quaternion
|
|
632
|
+
* @param {ReadonlyQuat2} a dual quaternion to normalize
|
|
633
|
+
* @returns {quat2} out
|
|
634
|
+
* @function
|
|
635
|
+
*/
|
|
431
636
|
export function normalize(out, a) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return out;
|
|
637
|
+
let magnitude = squaredLength(a);
|
|
638
|
+
if (magnitude > 0) {
|
|
639
|
+
magnitude = Math.sqrt(magnitude);
|
|
640
|
+
let a0 = a[0] / magnitude;
|
|
641
|
+
let a1 = a[1] / magnitude;
|
|
642
|
+
let a2 = a[2] / magnitude;
|
|
643
|
+
let a3 = a[3] / magnitude;
|
|
644
|
+
let b0 = a[4];
|
|
645
|
+
let b1 = a[5];
|
|
646
|
+
let b2 = a[6];
|
|
647
|
+
let b3 = a[7];
|
|
648
|
+
let a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
|
|
649
|
+
out[0] = a0;
|
|
650
|
+
out[1] = a1;
|
|
651
|
+
out[2] = a2;
|
|
652
|
+
out[3] = a3;
|
|
653
|
+
out[4] = (b0 - a0 * a_dot_b) / magnitude;
|
|
654
|
+
out[5] = (b1 - a1 * a_dot_b) / magnitude;
|
|
655
|
+
out[6] = (b2 - a2 * a_dot_b) / magnitude;
|
|
656
|
+
out[7] = (b3 - a3 * a_dot_b) / magnitude;
|
|
657
|
+
}
|
|
658
|
+
return out;
|
|
456
659
|
}
|
|
660
|
+
/**
|
|
661
|
+
* Returns a string representation of a dual quaternion
|
|
662
|
+
*
|
|
663
|
+
* @param {ReadonlyQuat2} a dual quaternion to represent as a string
|
|
664
|
+
* @returns {String} string representation of the dual quat
|
|
665
|
+
*/
|
|
457
666
|
export function str(a) {
|
|
458
|
-
|
|
667
|
+
return ('quat2(' +
|
|
668
|
+
a[0] +
|
|
669
|
+
', ' +
|
|
670
|
+
a[1] +
|
|
671
|
+
', ' +
|
|
672
|
+
a[2] +
|
|
673
|
+
', ' +
|
|
674
|
+
a[3] +
|
|
675
|
+
', ' +
|
|
676
|
+
a[4] +
|
|
677
|
+
', ' +
|
|
678
|
+
a[5] +
|
|
679
|
+
', ' +
|
|
680
|
+
a[6] +
|
|
681
|
+
', ' +
|
|
682
|
+
a[7] +
|
|
683
|
+
')');
|
|
459
684
|
}
|
|
685
|
+
/**
|
|
686
|
+
* Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)
|
|
687
|
+
*
|
|
688
|
+
* @param {ReadonlyQuat2} a the first dual quaternion.
|
|
689
|
+
* @param {ReadonlyQuat2} b the second dual quaternion.
|
|
690
|
+
* @returns {Boolean} true if the dual quaternions are equal, false otherwise.
|
|
691
|
+
*/
|
|
460
692
|
export function exactEquals(a, b) {
|
|
461
|
-
|
|
693
|
+
return (a[0] === b[0] &&
|
|
694
|
+
a[1] === b[1] &&
|
|
695
|
+
a[2] === b[2] &&
|
|
696
|
+
a[3] === b[3] &&
|
|
697
|
+
a[4] === b[4] &&
|
|
698
|
+
a[5] === b[5] &&
|
|
699
|
+
a[6] === b[6] &&
|
|
700
|
+
a[7] === b[7]);
|
|
462
701
|
}
|
|
702
|
+
/**
|
|
703
|
+
* Returns whether or not the dual quaternions have approximately the same elements in the same position.
|
|
704
|
+
*
|
|
705
|
+
* @param {ReadonlyQuat2} a the first dual quat.
|
|
706
|
+
* @param {ReadonlyQuat2} b the second dual quat.
|
|
707
|
+
* @returns {Boolean} true if the dual quats are equal, false otherwise.
|
|
708
|
+
*/
|
|
463
709
|
export function equals(a, b) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
b2 = b[2],
|
|
475
|
-
b3 = b[3],
|
|
476
|
-
b4 = b[4],
|
|
477
|
-
b5 = b[5],
|
|
478
|
-
b6 = b[6],
|
|
479
|
-
b7 = b[7];
|
|
480
|
-
return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7));
|
|
710
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5], a6 = a[6], a7 = a[7];
|
|
711
|
+
let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7];
|
|
712
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
713
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
|
|
714
|
+
Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
|
|
715
|
+
Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
|
|
716
|
+
Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
|
|
717
|
+
Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
|
|
718
|
+
Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
|
|
719
|
+
Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)));
|
|
481
720
|
}
|
|
482
|
-
//# sourceMappingURL=quat2.js.map
|