@math.gl/core 3.6.0-alpha.8 → 3.6.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/package.json +3 -3
- package/dist/classes/base/math-array.js +0 -216
- package/dist/classes/base/matrix.js +0 -61
- package/dist/classes/base/vector.js +0 -126
- package/dist/classes/euler.js +0 -485
- package/dist/classes/matrix3.js +0 -202
- package/dist/classes/matrix4.js +0 -540
- package/dist/classes/pose.js +0 -109
- package/dist/classes/quaternion.js +0 -262
- package/dist/classes/spherical-coordinates.js +0 -148
- package/dist/classes/vector2.js +0 -111
- package/dist/classes/vector3.js +0 -133
- package/dist/classes/vector4.js +0 -114
- package/dist/index.js +0 -24
- package/dist/lib/assert.js +0 -5
- package/dist/lib/common.js +0 -210
- package/dist/lib/gl-matrix-extras.js +0 -49
- package/dist/lib/math-utils.js +0 -28
- package/dist/lib/validators.js +0 -33
package/dist/classes/euler.js
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
// MIT License
|
|
3
|
-
import MathArray from './base/math-array';
|
|
4
|
-
import Quaternion from './quaternion';
|
|
5
|
-
import { clamp } from '../lib/common';
|
|
6
|
-
import { checkNumber } from '../lib/validators';
|
|
7
|
-
// Internal constants
|
|
8
|
-
const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
|
|
9
|
-
const ALMOST_ONE = 0.99999;
|
|
10
|
-
var RotationOrder;
|
|
11
|
-
(function (RotationOrder) {
|
|
12
|
-
RotationOrder[RotationOrder["ZYX"] = 0] = "ZYX";
|
|
13
|
-
RotationOrder[RotationOrder["YXZ"] = 1] = "YXZ";
|
|
14
|
-
RotationOrder[RotationOrder["XZY"] = 2] = "XZY";
|
|
15
|
-
RotationOrder[RotationOrder["ZXY"] = 3] = "ZXY";
|
|
16
|
-
RotationOrder[RotationOrder["YZX"] = 4] = "YZX";
|
|
17
|
-
RotationOrder[RotationOrder["XYZ"] = 5] = "XYZ";
|
|
18
|
-
})(RotationOrder || (RotationOrder = {}));
|
|
19
|
-
export default class Euler extends MathArray {
|
|
20
|
-
// Constants
|
|
21
|
-
static get ZYX() {
|
|
22
|
-
return RotationOrder.ZYX;
|
|
23
|
-
}
|
|
24
|
-
static get YXZ() {
|
|
25
|
-
return RotationOrder.YXZ;
|
|
26
|
-
}
|
|
27
|
-
static get XZY() {
|
|
28
|
-
return RotationOrder.XZY;
|
|
29
|
-
}
|
|
30
|
-
static get ZXY() {
|
|
31
|
-
return RotationOrder.ZXY;
|
|
32
|
-
}
|
|
33
|
-
static get YZX() {
|
|
34
|
-
return RotationOrder.YZX;
|
|
35
|
-
}
|
|
36
|
-
static get XYZ() {
|
|
37
|
-
return RotationOrder.XYZ;
|
|
38
|
-
}
|
|
39
|
-
static get RollPitchYaw() {
|
|
40
|
-
return RotationOrder.ZYX;
|
|
41
|
-
}
|
|
42
|
-
static get DefaultOrder() {
|
|
43
|
-
return RotationOrder.ZYX;
|
|
44
|
-
}
|
|
45
|
-
static get RotationOrders() {
|
|
46
|
-
return RotationOrder;
|
|
47
|
-
}
|
|
48
|
-
static rotationOrder(order) {
|
|
49
|
-
return RotationOrder[order];
|
|
50
|
-
}
|
|
51
|
-
get ELEMENTS() {
|
|
52
|
-
return 4;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @class
|
|
56
|
-
* @param {Number | Number[]} x
|
|
57
|
-
* @param {Number=} [y]
|
|
58
|
-
* @param {Number=} [z]
|
|
59
|
-
* @param {Number=} [order]
|
|
60
|
-
*/
|
|
61
|
-
constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
|
|
62
|
-
// PERF NOTE: initialize elements as double precision numbers
|
|
63
|
-
super(-0, -0, -0, -0);
|
|
64
|
-
// eslint-disable-next-line prefer-rest-params
|
|
65
|
-
if (arguments.length > 0 && Array.isArray(arguments[0])) {
|
|
66
|
-
// eslint-disable-next-line prefer-rest-params
|
|
67
|
-
// @ts-expect-error
|
|
68
|
-
this.fromVector3(...arguments);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.set(x, y, z, order);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
fromQuaternion(quaternion) {
|
|
75
|
-
const [x, y, z, w] = quaternion;
|
|
76
|
-
const ysqr = y * y;
|
|
77
|
-
const t0 = -2 * (ysqr + z * z) + 1;
|
|
78
|
-
const t1 = +2 * (x * y + w * z);
|
|
79
|
-
let t2 = -2 * (x * z - w * y);
|
|
80
|
-
const t3 = +2 * (y * z + w * x);
|
|
81
|
-
const t4 = -2 * (x * x + ysqr) + 1;
|
|
82
|
-
t2 = t2 > 1 ? 1 : t2;
|
|
83
|
-
t2 = t2 < -1 ? -1 : t2;
|
|
84
|
-
const roll = Math.atan2(t3, t4);
|
|
85
|
-
const pitch = Math.asin(t2);
|
|
86
|
-
const yaw = Math.atan2(t1, t0);
|
|
87
|
-
return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
88
|
-
}
|
|
89
|
-
fromObject(object) {
|
|
90
|
-
throw new Error('not implemented');
|
|
91
|
-
// return this.set(object.x, object.y, object.z, object.order);
|
|
92
|
-
}
|
|
93
|
-
// fromQuaternion(q, order) {
|
|
94
|
-
// this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
95
|
-
// return this.check();
|
|
96
|
-
// }
|
|
97
|
-
// If copied array does contain fourth element, preserves currently set order
|
|
98
|
-
copy(array) {
|
|
99
|
-
this[0] = array[0];
|
|
100
|
-
this[1] = array[1];
|
|
101
|
-
this[2] = array[2];
|
|
102
|
-
// @ts-expect-error
|
|
103
|
-
this[3] = Number.isFinite(array[3]) || this.order;
|
|
104
|
-
return this.check();
|
|
105
|
-
}
|
|
106
|
-
// Sets the three angles, and optionally sets the rotation order
|
|
107
|
-
// If order is not specified, preserves currently set order
|
|
108
|
-
set(x = 0, y = 0, z = 0, order) {
|
|
109
|
-
this[0] = x;
|
|
110
|
-
this[1] = y;
|
|
111
|
-
this[2] = z;
|
|
112
|
-
this[3] = Number.isFinite(order) ? order : this[3];
|
|
113
|
-
return this.check();
|
|
114
|
-
}
|
|
115
|
-
validate() {
|
|
116
|
-
return (validateOrder(this[3]) &&
|
|
117
|
-
Number.isFinite(this[0]) &&
|
|
118
|
-
Number.isFinite(this[1]) &&
|
|
119
|
-
Number.isFinite(this[2]));
|
|
120
|
-
}
|
|
121
|
-
// Does not copy the orientation element
|
|
122
|
-
toArray(array = [], offset = 0) {
|
|
123
|
-
array[offset] = this[0];
|
|
124
|
-
array[offset + 1] = this[1];
|
|
125
|
-
array[offset + 2] = this[2];
|
|
126
|
-
return array;
|
|
127
|
-
}
|
|
128
|
-
// Copies the orientation element
|
|
129
|
-
toArray4(array = [], offset = 0) {
|
|
130
|
-
array[offset] = this[0];
|
|
131
|
-
array[offset + 1] = this[1];
|
|
132
|
-
array[offset + 2] = this[2];
|
|
133
|
-
array[offset + 3] = this[3];
|
|
134
|
-
return array;
|
|
135
|
-
}
|
|
136
|
-
toVector3(result = [-0, -0, -0]) {
|
|
137
|
-
result[0] = this[0];
|
|
138
|
-
result[1] = this[1];
|
|
139
|
-
result[2] = this[2];
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
143
|
-
// x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
|
|
144
|
-
get x() {
|
|
145
|
-
return this[0];
|
|
146
|
-
}
|
|
147
|
-
set x(value) {
|
|
148
|
-
this[0] = checkNumber(value);
|
|
149
|
-
}
|
|
150
|
-
get y() {
|
|
151
|
-
return this[1];
|
|
152
|
-
}
|
|
153
|
-
set y(value) {
|
|
154
|
-
this[1] = checkNumber(value);
|
|
155
|
-
}
|
|
156
|
-
get z() {
|
|
157
|
-
return this[2];
|
|
158
|
-
}
|
|
159
|
-
set z(value) {
|
|
160
|
-
this[2] = checkNumber(value);
|
|
161
|
-
}
|
|
162
|
-
// alpha, beta, gamma angle notation
|
|
163
|
-
get alpha() {
|
|
164
|
-
return this[0];
|
|
165
|
-
}
|
|
166
|
-
set alpha(value) {
|
|
167
|
-
this[0] = checkNumber(value);
|
|
168
|
-
}
|
|
169
|
-
get beta() {
|
|
170
|
-
return this[1];
|
|
171
|
-
}
|
|
172
|
-
set beta(value) {
|
|
173
|
-
this[1] = checkNumber(value);
|
|
174
|
-
}
|
|
175
|
-
get gamma() {
|
|
176
|
-
return this[2];
|
|
177
|
-
}
|
|
178
|
-
set gamma(value) {
|
|
179
|
-
this[2] = checkNumber(value);
|
|
180
|
-
}
|
|
181
|
-
// phi, theta, psi angle notation
|
|
182
|
-
get phi() {
|
|
183
|
-
return this[0];
|
|
184
|
-
}
|
|
185
|
-
set phi(value) {
|
|
186
|
-
this[0] = checkNumber(value);
|
|
187
|
-
}
|
|
188
|
-
get theta() {
|
|
189
|
-
return this[1];
|
|
190
|
-
}
|
|
191
|
-
set theta(value) {
|
|
192
|
-
this[1] = checkNumber(value);
|
|
193
|
-
}
|
|
194
|
-
get psi() {
|
|
195
|
-
return this[2];
|
|
196
|
-
}
|
|
197
|
-
set psi(value) {
|
|
198
|
-
this[2] = checkNumber(value);
|
|
199
|
-
}
|
|
200
|
-
// roll, pitch, yaw angle notation
|
|
201
|
-
get roll() {
|
|
202
|
-
return this[0];
|
|
203
|
-
}
|
|
204
|
-
set roll(value) {
|
|
205
|
-
this[0] = checkNumber(value);
|
|
206
|
-
}
|
|
207
|
-
get pitch() {
|
|
208
|
-
return this[1];
|
|
209
|
-
}
|
|
210
|
-
set pitch(value) {
|
|
211
|
-
this[1] = checkNumber(value);
|
|
212
|
-
}
|
|
213
|
-
get yaw() {
|
|
214
|
-
return this[2];
|
|
215
|
-
}
|
|
216
|
-
set yaw(value) {
|
|
217
|
-
this[2] = checkNumber(value);
|
|
218
|
-
}
|
|
219
|
-
// rotation order, in all three angle notations
|
|
220
|
-
get order() {
|
|
221
|
-
return this[3];
|
|
222
|
-
}
|
|
223
|
-
set order(value) {
|
|
224
|
-
this[3] = checkOrder(value);
|
|
225
|
-
}
|
|
226
|
-
// Constructors
|
|
227
|
-
fromVector3(v, order) {
|
|
228
|
-
return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
|
|
229
|
-
}
|
|
230
|
-
// TODO - with and without 4th element
|
|
231
|
-
fromArray(array, offset = 0) {
|
|
232
|
-
this[0] = array[0 + offset];
|
|
233
|
-
this[1] = array[1 + offset];
|
|
234
|
-
this[2] = array[2 + offset];
|
|
235
|
-
if (array[3] !== undefined) {
|
|
236
|
-
this[3] = array[3];
|
|
237
|
-
}
|
|
238
|
-
return this.check();
|
|
239
|
-
}
|
|
240
|
-
// Common ZYX rotation order
|
|
241
|
-
fromRollPitchYaw(roll, pitch, yaw) {
|
|
242
|
-
return this.set(roll, pitch, yaw, RotationOrder.ZYX);
|
|
243
|
-
}
|
|
244
|
-
fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
245
|
-
this._fromRotationMatrix(m, order);
|
|
246
|
-
return this.check();
|
|
247
|
-
}
|
|
248
|
-
// ACCESSORS
|
|
249
|
-
getRotationMatrix(m) {
|
|
250
|
-
return this._getRotationMatrix(m);
|
|
251
|
-
}
|
|
252
|
-
// TODO - move to Quaternion
|
|
253
|
-
getQuaternion() {
|
|
254
|
-
const q = new Quaternion();
|
|
255
|
-
switch (this[4]) {
|
|
256
|
-
case RotationOrder.XYZ:
|
|
257
|
-
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
258
|
-
case RotationOrder.YXZ:
|
|
259
|
-
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
|
|
260
|
-
case RotationOrder.ZXY:
|
|
261
|
-
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
|
|
262
|
-
case RotationOrder.ZYX:
|
|
263
|
-
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
|
|
264
|
-
case RotationOrder.YZX:
|
|
265
|
-
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
|
|
266
|
-
case RotationOrder.XZY:
|
|
267
|
-
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
|
|
268
|
-
default:
|
|
269
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// INTERNAL METHODS
|
|
273
|
-
// Conversion from Euler to rotation matrix and from matrix to Euler
|
|
274
|
-
// Adapted from three.js under MIT license
|
|
275
|
-
// // WARNING: this discards revolution information -bhouston
|
|
276
|
-
// reorder(newOrder) {
|
|
277
|
-
// const q = new Quaternion().setFromEuler(this);
|
|
278
|
-
// return this.setFromQuaternion(q, newOrder);
|
|
279
|
-
/* eslint-disable complexity, max-statements, one-var */
|
|
280
|
-
_fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
281
|
-
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
282
|
-
const m11 = m[0], m12 = m[4], m13 = m[8];
|
|
283
|
-
const m21 = m[1], m22 = m[5], m23 = m[9];
|
|
284
|
-
const m31 = m[2], m32 = m[6], m33 = m[10];
|
|
285
|
-
order = order || this[3];
|
|
286
|
-
switch (order) {
|
|
287
|
-
case Euler.XYZ:
|
|
288
|
-
this[1] = Math.asin(clamp(m13, -1, 1));
|
|
289
|
-
if (Math.abs(m13) < ALMOST_ONE) {
|
|
290
|
-
this[0] = Math.atan2(-m23, m33);
|
|
291
|
-
this[2] = Math.atan2(-m12, m11);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
this[0] = Math.atan2(m32, m22);
|
|
295
|
-
this[2] = 0;
|
|
296
|
-
}
|
|
297
|
-
break;
|
|
298
|
-
case Euler.YXZ:
|
|
299
|
-
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
300
|
-
if (Math.abs(m23) < ALMOST_ONE) {
|
|
301
|
-
this[1] = Math.atan2(m13, m33);
|
|
302
|
-
this[2] = Math.atan2(m21, m22);
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
this[1] = Math.atan2(-m31, m11);
|
|
306
|
-
this[2] = 0;
|
|
307
|
-
}
|
|
308
|
-
break;
|
|
309
|
-
case Euler.ZXY:
|
|
310
|
-
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
311
|
-
if (Math.abs(m32) < ALMOST_ONE) {
|
|
312
|
-
this[1] = Math.atan2(-m31, m33);
|
|
313
|
-
this[2] = Math.atan2(-m12, m22);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
this[1] = 0;
|
|
317
|
-
this[2] = Math.atan2(m21, m11);
|
|
318
|
-
}
|
|
319
|
-
break;
|
|
320
|
-
case Euler.ZYX:
|
|
321
|
-
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
322
|
-
if (Math.abs(m31) < ALMOST_ONE) {
|
|
323
|
-
this[0] = Math.atan2(m32, m33);
|
|
324
|
-
this[2] = Math.atan2(m21, m11);
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
this[0] = 0;
|
|
328
|
-
this[2] = Math.atan2(-m12, m22);
|
|
329
|
-
}
|
|
330
|
-
break;
|
|
331
|
-
case Euler.YZX:
|
|
332
|
-
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
333
|
-
if (Math.abs(m21) < ALMOST_ONE) {
|
|
334
|
-
this[0] = Math.atan2(-m23, m22);
|
|
335
|
-
this[1] = Math.atan2(-m31, m11);
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
this[0] = 0;
|
|
339
|
-
this[1] = Math.atan2(m13, m33);
|
|
340
|
-
}
|
|
341
|
-
break;
|
|
342
|
-
case Euler.XZY:
|
|
343
|
-
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
344
|
-
if (Math.abs(m12) < ALMOST_ONE) {
|
|
345
|
-
this[0] = Math.atan2(m32, m22);
|
|
346
|
-
this[1] = Math.atan2(m13, m11);
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
this[0] = Math.atan2(-m23, m33);
|
|
350
|
-
this[1] = 0;
|
|
351
|
-
}
|
|
352
|
-
break;
|
|
353
|
-
default:
|
|
354
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
355
|
-
}
|
|
356
|
-
this[3] = order;
|
|
357
|
-
return this;
|
|
358
|
-
}
|
|
359
|
-
_getRotationMatrix(result) {
|
|
360
|
-
const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
361
|
-
const x = this.x, y = this.y, z = this.z;
|
|
362
|
-
const a = Math.cos(x);
|
|
363
|
-
const c = Math.cos(y);
|
|
364
|
-
const e = Math.cos(z);
|
|
365
|
-
const b = Math.sin(x);
|
|
366
|
-
const d = Math.sin(y);
|
|
367
|
-
const f = Math.sin(z);
|
|
368
|
-
switch (this[3]) {
|
|
369
|
-
case Euler.XYZ: {
|
|
370
|
-
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
371
|
-
te[0] = c * e;
|
|
372
|
-
te[4] = -c * f;
|
|
373
|
-
te[8] = d;
|
|
374
|
-
te[1] = af + be * d;
|
|
375
|
-
te[5] = ae - bf * d;
|
|
376
|
-
te[9] = -b * c;
|
|
377
|
-
te[2] = bf - ae * d;
|
|
378
|
-
te[6] = be + af * d;
|
|
379
|
-
te[10] = a * c;
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
case Euler.YXZ: {
|
|
383
|
-
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
384
|
-
te[0] = ce + df * b;
|
|
385
|
-
te[4] = de * b - cf;
|
|
386
|
-
te[8] = a * d;
|
|
387
|
-
te[1] = a * f;
|
|
388
|
-
te[5] = a * e;
|
|
389
|
-
te[9] = -b;
|
|
390
|
-
te[2] = cf * b - de;
|
|
391
|
-
te[6] = df + ce * b;
|
|
392
|
-
te[10] = a * c;
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
case Euler.ZXY: {
|
|
396
|
-
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
397
|
-
te[0] = ce - df * b;
|
|
398
|
-
te[4] = -a * f;
|
|
399
|
-
te[8] = de + cf * b;
|
|
400
|
-
te[1] = cf + de * b;
|
|
401
|
-
te[5] = a * e;
|
|
402
|
-
te[9] = df - ce * b;
|
|
403
|
-
te[2] = -a * d;
|
|
404
|
-
te[6] = b;
|
|
405
|
-
te[10] = a * c;
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
case Euler.ZYX: {
|
|
409
|
-
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
410
|
-
te[0] = c * e;
|
|
411
|
-
te[4] = be * d - af;
|
|
412
|
-
te[8] = ae * d + bf;
|
|
413
|
-
te[1] = c * f;
|
|
414
|
-
te[5] = bf * d + ae;
|
|
415
|
-
te[9] = af * d - be;
|
|
416
|
-
te[2] = -d;
|
|
417
|
-
te[6] = b * c;
|
|
418
|
-
te[10] = a * c;
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
case Euler.YZX: {
|
|
422
|
-
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
423
|
-
te[0] = c * e;
|
|
424
|
-
te[4] = bd - ac * f;
|
|
425
|
-
te[8] = bc * f + ad;
|
|
426
|
-
te[1] = f;
|
|
427
|
-
te[5] = a * e;
|
|
428
|
-
te[9] = -b * e;
|
|
429
|
-
te[2] = -d * e;
|
|
430
|
-
te[6] = ad * f + bc;
|
|
431
|
-
te[10] = ac - bd * f;
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
case Euler.XZY: {
|
|
435
|
-
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
436
|
-
te[0] = c * e;
|
|
437
|
-
te[4] = -f;
|
|
438
|
-
te[8] = d * e;
|
|
439
|
-
te[1] = ac * f + bd;
|
|
440
|
-
te[5] = a * e;
|
|
441
|
-
te[9] = ad * f - bc;
|
|
442
|
-
te[2] = bc * f - ad;
|
|
443
|
-
te[6] = b * e;
|
|
444
|
-
te[10] = bd * f + ac;
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
default:
|
|
448
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
449
|
-
}
|
|
450
|
-
// last column
|
|
451
|
-
te[3] = 0;
|
|
452
|
-
te[7] = 0;
|
|
453
|
-
te[11] = 0;
|
|
454
|
-
// bottom row
|
|
455
|
-
te[12] = 0;
|
|
456
|
-
te[13] = 0;
|
|
457
|
-
te[14] = 0;
|
|
458
|
-
te[15] = 1;
|
|
459
|
-
return te;
|
|
460
|
-
}
|
|
461
|
-
toQuaternion() {
|
|
462
|
-
// Abbreviations for the various angular functions
|
|
463
|
-
const cy = Math.cos(this.yaw * 0.5);
|
|
464
|
-
const sy = Math.sin(this.yaw * 0.5);
|
|
465
|
-
const cr = Math.cos(this.roll * 0.5);
|
|
466
|
-
const sr = Math.sin(this.roll * 0.5);
|
|
467
|
-
const cp = Math.cos(this.pitch * 0.5);
|
|
468
|
-
const sp = Math.sin(this.pitch * 0.5);
|
|
469
|
-
const w = cy * cr * cp + sy * sr * sp;
|
|
470
|
-
const x = cy * sr * cp - sy * cr * sp;
|
|
471
|
-
const y = cy * cr * sp + sy * sr * cp;
|
|
472
|
-
const z = sy * cr * cp - cy * sr * sp;
|
|
473
|
-
return new Quaternion(x, y, z, w);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
// HELPER FUNCTIONS
|
|
477
|
-
function validateOrder(value) {
|
|
478
|
-
return value >= 0 && value < 6;
|
|
479
|
-
}
|
|
480
|
-
function checkOrder(value) {
|
|
481
|
-
if (value < 0 && value >= 6) {
|
|
482
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
483
|
-
}
|
|
484
|
-
return value;
|
|
485
|
-
}
|
package/dist/classes/matrix3.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
// MIT License
|
|
3
|
-
import Matrix from './base/matrix';
|
|
4
|
-
import { checkVector } from '../lib/validators';
|
|
5
|
-
/* eslint-disable camelcase */
|
|
6
|
-
import { vec4_transformMat3 } from '../lib/gl-matrix-extras';
|
|
7
|
-
import * as mat3 from 'gl-matrix/mat3';
|
|
8
|
-
import * as vec2 from 'gl-matrix/vec2';
|
|
9
|
-
import * as vec3 from 'gl-matrix/vec3';
|
|
10
|
-
var INDICES;
|
|
11
|
-
(function (INDICES) {
|
|
12
|
-
INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0";
|
|
13
|
-
INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1";
|
|
14
|
-
INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2";
|
|
15
|
-
INDICES[INDICES["COL1ROW0"] = 3] = "COL1ROW0";
|
|
16
|
-
INDICES[INDICES["COL1ROW1"] = 4] = "COL1ROW1";
|
|
17
|
-
INDICES[INDICES["COL1ROW2"] = 5] = "COL1ROW2";
|
|
18
|
-
INDICES[INDICES["COL2ROW0"] = 6] = "COL2ROW0";
|
|
19
|
-
INDICES[INDICES["COL2ROW1"] = 7] = "COL2ROW1";
|
|
20
|
-
INDICES[INDICES["COL2ROW2"] = 8] = "COL2ROW2";
|
|
21
|
-
})(INDICES || (INDICES = {}));
|
|
22
|
-
const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
23
|
-
export default class Matrix3 extends Matrix {
|
|
24
|
-
static get IDENTITY() {
|
|
25
|
-
return getIdentityMatrix();
|
|
26
|
-
}
|
|
27
|
-
static get ZERO() {
|
|
28
|
-
return getZeroMatrix();
|
|
29
|
-
}
|
|
30
|
-
get ELEMENTS() {
|
|
31
|
-
return 9;
|
|
32
|
-
}
|
|
33
|
-
get RANK() {
|
|
34
|
-
return 3;
|
|
35
|
-
}
|
|
36
|
-
get INDICES() {
|
|
37
|
-
return INDICES;
|
|
38
|
-
}
|
|
39
|
-
constructor(array, ...args) {
|
|
40
|
-
// PERF NOTE: initialize elements as double precision numbers
|
|
41
|
-
super(-0, -0, -0, -0, -0, -0, -0, -0, -0);
|
|
42
|
-
if (arguments.length === 1 && Array.isArray(array)) {
|
|
43
|
-
this.copy(array);
|
|
44
|
-
}
|
|
45
|
-
else if (args.length > 0) {
|
|
46
|
-
this.copy([array, ...args]);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this.identity();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
copy(array) {
|
|
53
|
-
// Element wise copy for performance
|
|
54
|
-
this[0] = array[0];
|
|
55
|
-
this[1] = array[1];
|
|
56
|
-
this[2] = array[2];
|
|
57
|
-
this[3] = array[3];
|
|
58
|
-
this[4] = array[4];
|
|
59
|
-
this[5] = array[5];
|
|
60
|
-
this[6] = array[6];
|
|
61
|
-
this[7] = array[7];
|
|
62
|
-
this[8] = array[8];
|
|
63
|
-
return this.check();
|
|
64
|
-
}
|
|
65
|
-
// Constructors
|
|
66
|
-
identity() {
|
|
67
|
-
return this.copy(IDENTITY_MATRIX);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param object
|
|
72
|
-
* @returns self
|
|
73
|
-
*/
|
|
74
|
-
fromObject(object) {
|
|
75
|
-
return this.check();
|
|
76
|
-
}
|
|
77
|
-
// Calculates a 3x3 matrix from the given quaternion
|
|
78
|
-
// q quat Quaternion to create matrix from
|
|
79
|
-
fromQuaternion(q) {
|
|
80
|
-
mat3.fromQuat(this, q);
|
|
81
|
-
return this.check();
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* accepts column major order, stores in column major order
|
|
85
|
-
*/
|
|
86
|
-
// eslint-disable-next-line max-params
|
|
87
|
-
set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
|
|
88
|
-
this[0] = m00;
|
|
89
|
-
this[1] = m10;
|
|
90
|
-
this[2] = m20;
|
|
91
|
-
this[3] = m01;
|
|
92
|
-
this[4] = m11;
|
|
93
|
-
this[5] = m21;
|
|
94
|
-
this[6] = m02;
|
|
95
|
-
this[7] = m12;
|
|
96
|
-
this[8] = m22;
|
|
97
|
-
return this.check();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* accepts row major order, stores as column major
|
|
101
|
-
*/
|
|
102
|
-
// eslint-disable-next-line max-params
|
|
103
|
-
setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
|
|
104
|
-
this[0] = m00;
|
|
105
|
-
this[1] = m10;
|
|
106
|
-
this[2] = m20;
|
|
107
|
-
this[3] = m01;
|
|
108
|
-
this[4] = m11;
|
|
109
|
-
this[5] = m21;
|
|
110
|
-
this[6] = m02;
|
|
111
|
-
this[7] = m12;
|
|
112
|
-
this[8] = m22;
|
|
113
|
-
return this.check();
|
|
114
|
-
}
|
|
115
|
-
// Accessors
|
|
116
|
-
determinant() {
|
|
117
|
-
return mat3.determinant(this);
|
|
118
|
-
}
|
|
119
|
-
// Modifiers
|
|
120
|
-
transpose() {
|
|
121
|
-
mat3.transpose(this, this);
|
|
122
|
-
return this.check();
|
|
123
|
-
}
|
|
124
|
-
/** Invert a matrix. Note that this can fail if the matrix is not invertible */
|
|
125
|
-
invert() {
|
|
126
|
-
mat3.invert(this, this);
|
|
127
|
-
return this.check();
|
|
128
|
-
}
|
|
129
|
-
// Operations
|
|
130
|
-
multiplyLeft(a) {
|
|
131
|
-
mat3.multiply(this, a, this);
|
|
132
|
-
return this.check();
|
|
133
|
-
}
|
|
134
|
-
multiplyRight(a) {
|
|
135
|
-
mat3.multiply(this, this, a);
|
|
136
|
-
return this.check();
|
|
137
|
-
}
|
|
138
|
-
rotate(radians) {
|
|
139
|
-
mat3.rotate(this, this, radians);
|
|
140
|
-
return this.check();
|
|
141
|
-
}
|
|
142
|
-
scale(factor) {
|
|
143
|
-
if (Array.isArray(factor)) {
|
|
144
|
-
mat3.scale(this, this, factor);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
mat3.scale(this, this, [factor, factor]);
|
|
148
|
-
}
|
|
149
|
-
return this.check();
|
|
150
|
-
}
|
|
151
|
-
translate(vec) {
|
|
152
|
-
mat3.translate(this, this, vec);
|
|
153
|
-
return this.check();
|
|
154
|
-
}
|
|
155
|
-
// Transforms
|
|
156
|
-
transform(vector, result) {
|
|
157
|
-
let out;
|
|
158
|
-
switch (vector.length) {
|
|
159
|
-
case 2:
|
|
160
|
-
out = vec2.transformMat3(result || [-0, -0], vector, this);
|
|
161
|
-
break;
|
|
162
|
-
case 3:
|
|
163
|
-
out = vec3.transformMat3(result || [-0, -0, -0], vector, this);
|
|
164
|
-
break;
|
|
165
|
-
case 4:
|
|
166
|
-
out = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this);
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
throw new Error('Illegal vector');
|
|
170
|
-
}
|
|
171
|
-
checkVector(out, vector.length);
|
|
172
|
-
return out;
|
|
173
|
-
}
|
|
174
|
-
/** @deprecated */
|
|
175
|
-
transformVector(vector, result) {
|
|
176
|
-
return this.transform(vector, result);
|
|
177
|
-
}
|
|
178
|
-
/** @deprecated */
|
|
179
|
-
transformVector2(vector, result) {
|
|
180
|
-
return this.transform(vector, result);
|
|
181
|
-
}
|
|
182
|
-
/** @deprecated */
|
|
183
|
-
transformVector3(vector, result) {
|
|
184
|
-
return this.transform(vector, result);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
let ZERO_MATRIX3;
|
|
188
|
-
let IDENTITY_MATRIX3;
|
|
189
|
-
function getZeroMatrix() {
|
|
190
|
-
if (!ZERO_MATRIX3) {
|
|
191
|
-
ZERO_MATRIX3 = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
192
|
-
Object.freeze(ZERO_MATRIX3);
|
|
193
|
-
}
|
|
194
|
-
return ZERO_MATRIX3;
|
|
195
|
-
}
|
|
196
|
-
function getIdentityMatrix() {
|
|
197
|
-
if (!IDENTITY_MATRIX3) {
|
|
198
|
-
IDENTITY_MATRIX3 = new Matrix3();
|
|
199
|
-
Object.freeze(IDENTITY_MATRIX3);
|
|
200
|
-
}
|
|
201
|
-
return IDENTITY_MATRIX3;
|
|
202
|
-
}
|