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