@math.gl/core 4.0.0-beta.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/base/math-array.d.ts +1 -2
- package/dist/classes/base/math-array.js +220 -266
- package/dist/classes/base/matrix.d.ts +1 -2
- package/dist/classes/base/matrix.js +52 -53
- package/dist/classes/base/vector.d.ts +1 -2
- package/dist/classes/base/vector.js +121 -135
- package/dist/classes/euler.d.ts +2 -3
- package/dist/classes/euler.js +462 -533
- package/dist/classes/matrix3.d.ts +2 -3
- package/dist/classes/matrix3.js +185 -190
- package/dist/classes/matrix4.d.ts +1 -2
- package/dist/classes/matrix4.js +516 -452
- package/dist/classes/pose.d.ts +4 -5
- package/dist/classes/pose.js +104 -119
- package/dist/classes/quaternion.d.ts +1 -2
- package/dist/classes/quaternion.js +257 -233
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.js +138 -147
- package/dist/classes/vector2.d.ts +1 -2
- package/dist/classes/vector2.js +101 -85
- package/dist/classes/vector3.d.ts +1 -2
- package/dist/classes/vector3.js +125 -136
- package/dist/classes/vector4.d.ts +2 -3
- package/dist/classes/vector4.js +106 -114
- package/dist/gl-matrix/common.d.ts +0 -1
- package/dist/gl-matrix/common.js +38 -6
- package/dist/gl-matrix/mat3.d.ts +0 -1
- package/dist/gl-matrix/mat3.js +699 -425
- package/dist/gl-matrix/mat4.d.ts +0 -1
- package/dist/gl-matrix/mat4.js +1879 -1339
- package/dist/gl-matrix/quat.d.ts +0 -1
- package/dist/gl-matrix/quat.js +655 -257
- package/dist/gl-matrix/vec2.d.ts +0 -1
- package/dist/gl-matrix/vec2.js +529 -212
- package/dist/gl-matrix/vec3.d.ts +0 -1
- package/dist/gl-matrix/vec3.js +703 -335
- package/dist/gl-matrix/vec4.d.ts +0 -1
- package/dist/gl-matrix/vec4.js +579 -293
- package/dist/gl-matrix/wip/index.d.ts +3 -4
- package/dist/gl-matrix/wip/index.js +2 -1
- package/dist/gl-matrix/wip/mat2.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2.js +333 -157
- package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2d.js +377 -202
- package/dist/gl-matrix/wip/quat2.d.ts +0 -1
- package/dist/gl-matrix/wip/quat2.js +647 -409
- package/dist/index.cjs +60 -100
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +21 -22
- package/dist/index.js +23 -16
- package/dist/lib/assert.d.ts +0 -1
- package/dist/lib/assert.js +3 -4
- package/dist/lib/common.d.ts +2 -3
- package/dist/lib/common.js +163 -134
- package/dist/lib/gl-matrix-extras.d.ts +0 -1
- package/dist/lib/gl-matrix-extras.js +39 -36
- package/dist/lib/math-utils.d.ts +0 -1
- package/dist/lib/math-utils.js +2 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.js +22 -25
- package/package.json +5 -6
- package/src/classes/matrix3.ts +1 -1
- package/dist/classes/base/math-array.d.ts.map +0 -1
- package/dist/classes/base/math-array.js.map +0 -1
- package/dist/classes/base/matrix.d.ts.map +0 -1
- package/dist/classes/base/matrix.js.map +0 -1
- package/dist/classes/base/vector.d.ts.map +0 -1
- package/dist/classes/base/vector.js.map +0 -1
- package/dist/classes/euler.d.ts.map +0 -1
- package/dist/classes/euler.js.map +0 -1
- package/dist/classes/matrix3.d.ts.map +0 -1
- package/dist/classes/matrix3.js.map +0 -1
- package/dist/classes/matrix4.d.ts.map +0 -1
- package/dist/classes/matrix4.js.map +0 -1
- package/dist/classes/pose.d.ts.map +0 -1
- package/dist/classes/pose.js.map +0 -1
- package/dist/classes/quaternion.d.ts.map +0 -1
- package/dist/classes/quaternion.js.map +0 -1
- package/dist/classes/spherical-coordinates.d.ts.map +0 -1
- package/dist/classes/spherical-coordinates.js.map +0 -1
- package/dist/classes/vector2.d.ts.map +0 -1
- package/dist/classes/vector2.js.map +0 -1
- package/dist/classes/vector3.d.ts.map +0 -1
- package/dist/classes/vector3.js.map +0 -1
- package/dist/classes/vector4.d.ts.map +0 -1
- package/dist/classes/vector4.js.map +0 -1
- package/dist/gl-matrix/common.d.ts.map +0 -1
- package/dist/gl-matrix/common.js.map +0 -1
- package/dist/gl-matrix/mat3.d.ts.map +0 -1
- package/dist/gl-matrix/mat3.js.map +0 -1
- package/dist/gl-matrix/mat4.d.ts.map +0 -1
- package/dist/gl-matrix/mat4.js.map +0 -1
- package/dist/gl-matrix/quat.d.ts.map +0 -1
- package/dist/gl-matrix/quat.js.map +0 -1
- package/dist/gl-matrix/vec2.d.ts.map +0 -1
- package/dist/gl-matrix/vec2.js.map +0 -1
- package/dist/gl-matrix/vec3.d.ts.map +0 -1
- package/dist/gl-matrix/vec3.js.map +0 -1
- package/dist/gl-matrix/vec4.d.ts.map +0 -1
- package/dist/gl-matrix/vec4.js.map +0 -1
- package/dist/gl-matrix/wip/index.d.ts.map +0 -1
- package/dist/gl-matrix/wip/index.js.map +0 -1
- package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2.js.map +0 -1
- package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2d.js.map +0 -1
- package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/quat2.js.map +0 -1
- package/dist/gl-matrix/wip/types.d.js +0 -2
- package/dist/gl-matrix/wip/types.d.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/assert.d.ts.map +0 -1
- package/dist/lib/assert.js.map +0 -1
- package/dist/lib/common.d.ts.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
- package/dist/lib/gl-matrix-extras.js.map +0 -1
- package/dist/lib/gl-matrix.d.js +0 -2
- package/dist/lib/gl-matrix.d.js.map +0 -1
- package/dist/lib/math-utils.d.ts.map +0 -1
- package/dist/lib/math-utils.js.map +0 -1
- package/dist/lib/validators.d.ts.map +0 -1
- package/dist/lib/validators.js.map +0 -1
package/dist/classes/euler.js
CHANGED
|
@@ -1,557 +1,486 @@
|
|
|
1
|
+
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
+
// MIT License
|
|
1
3
|
import { MathArray } from "./base/math-array.js";
|
|
2
4
|
import { Quaternion } from "./quaternion.js";
|
|
3
5
|
import { clamp } from "../lib/common.js";
|
|
4
6
|
import { checkNumber } from "../lib/validators.js";
|
|
7
|
+
// Internal constants
|
|
5
8
|
const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
|
|
6
9
|
const ALMOST_ONE = 0.99999;
|
|
7
10
|
var RotationOrder;
|
|
8
|
-
|
|
9
11
|
(function (RotationOrder) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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";
|
|
16
18
|
})(RotationOrder || (RotationOrder = {}));
|
|
17
|
-
|
|
18
19
|
export class Euler extends MathArray {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
static get YXZ() {
|
|
24
|
-
return RotationOrder.YXZ;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static get XZY() {
|
|
28
|
-
return RotationOrder.XZY;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static get ZXY() {
|
|
32
|
-
return RotationOrder.ZXY;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static get YZX() {
|
|
36
|
-
return RotationOrder.YZX;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static get XYZ() {
|
|
40
|
-
return RotationOrder.XYZ;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static get RollPitchYaw() {
|
|
44
|
-
return RotationOrder.ZYX;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static get DefaultOrder() {
|
|
48
|
-
return RotationOrder.ZYX;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static get RotationOrders() {
|
|
52
|
-
return RotationOrder;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static rotationOrder(order) {
|
|
56
|
-
return RotationOrder[order];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get ELEMENTS() {
|
|
60
|
-
return 4;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
|
|
64
|
-
super(-0, -0, -0, -0);
|
|
65
|
-
|
|
66
|
-
if (arguments.length > 0 && Array.isArray(arguments[0])) {
|
|
67
|
-
this.fromVector3(...arguments);
|
|
68
|
-
} else {
|
|
69
|
-
this.set(x, y, z, order);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fromQuaternion(quaternion) {
|
|
74
|
-
const [x, y, z, w] = quaternion;
|
|
75
|
-
const ysqr = y * y;
|
|
76
|
-
const t0 = -2 * (ysqr + z * z) + 1;
|
|
77
|
-
const t1 = +2 * (x * y + w * z);
|
|
78
|
-
let t2 = -2 * (x * z - w * y);
|
|
79
|
-
const t3 = +2 * (y * z + w * x);
|
|
80
|
-
const t4 = -2 * (x * x + ysqr) + 1;
|
|
81
|
-
t2 = t2 > 1 ? 1 : t2;
|
|
82
|
-
t2 = t2 < -1 ? -1 : t2;
|
|
83
|
-
const roll = Math.atan2(t3, t4);
|
|
84
|
-
const pitch = Math.asin(t2);
|
|
85
|
-
const yaw = Math.atan2(t1, t0);
|
|
86
|
-
return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
fromObject(object) {
|
|
90
|
-
throw new Error('not implemented');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
copy(array) {
|
|
94
|
-
this[0] = array[0];
|
|
95
|
-
this[1] = array[1];
|
|
96
|
-
this[2] = array[2];
|
|
97
|
-
this[3] = Number.isFinite(array[3]) || this.order;
|
|
98
|
-
return this.check();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
set(x = 0, y = 0, z = 0, order) {
|
|
102
|
-
this[0] = x;
|
|
103
|
-
this[1] = y;
|
|
104
|
-
this[2] = z;
|
|
105
|
-
this[3] = Number.isFinite(order) ? order : this[3];
|
|
106
|
-
return this.check();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
validate() {
|
|
110
|
-
return validateOrder(this[3]) && Number.isFinite(this[0]) && Number.isFinite(this[1]) && Number.isFinite(this[2]);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
toArray(array = [], offset = 0) {
|
|
114
|
-
array[offset] = this[0];
|
|
115
|
-
array[offset + 1] = this[1];
|
|
116
|
-
array[offset + 2] = this[2];
|
|
117
|
-
return array;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
toArray4(array = [], offset = 0) {
|
|
121
|
-
array[offset] = this[0];
|
|
122
|
-
array[offset + 1] = this[1];
|
|
123
|
-
array[offset + 2] = this[2];
|
|
124
|
-
array[offset + 3] = this[3];
|
|
125
|
-
return array;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
toVector3(result = [-0, -0, -0]) {
|
|
129
|
-
result[0] = this[0];
|
|
130
|
-
result[1] = this[1];
|
|
131
|
-
result[2] = this[2];
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
get x() {
|
|
136
|
-
return this[0];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
set x(value) {
|
|
140
|
-
this[0] = checkNumber(value);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
get y() {
|
|
144
|
-
return this[1];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
set y(value) {
|
|
148
|
-
this[1] = checkNumber(value);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
get z() {
|
|
152
|
-
return this[2];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
set z(value) {
|
|
156
|
-
this[2] = checkNumber(value);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get alpha() {
|
|
160
|
-
return this[0];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set alpha(value) {
|
|
164
|
-
this[0] = checkNumber(value);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
get beta() {
|
|
168
|
-
return this[1];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
set beta(value) {
|
|
172
|
-
this[1] = checkNumber(value);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
get gamma() {
|
|
176
|
-
return this[2];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
set gamma(value) {
|
|
180
|
-
this[2] = checkNumber(value);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
get phi() {
|
|
184
|
-
return this[0];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
set phi(value) {
|
|
188
|
-
this[0] = checkNumber(value);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
get theta() {
|
|
192
|
-
return this[1];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
set theta(value) {
|
|
196
|
-
this[1] = checkNumber(value);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
get psi() {
|
|
200
|
-
return this[2];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
set psi(value) {
|
|
204
|
-
this[2] = checkNumber(value);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
get roll() {
|
|
208
|
-
return this[0];
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
set roll(value) {
|
|
212
|
-
this[0] = checkNumber(value);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
get pitch() {
|
|
216
|
-
return this[1];
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
set pitch(value) {
|
|
220
|
-
this[1] = checkNumber(value);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
get yaw() {
|
|
224
|
-
return this[2];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
set yaw(value) {
|
|
228
|
-
this[2] = checkNumber(value);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
get order() {
|
|
232
|
-
return this[3];
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
set order(value) {
|
|
236
|
-
this[3] = checkOrder(value);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
fromVector3(v, order) {
|
|
240
|
-
return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
fromArray(array, offset = 0) {
|
|
244
|
-
this[0] = array[0 + offset];
|
|
245
|
-
this[1] = array[1 + offset];
|
|
246
|
-
this[2] = array[2 + offset];
|
|
247
|
-
|
|
248
|
-
if (array[3] !== undefined) {
|
|
249
|
-
this[3] = array[3];
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return this.check();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
fromRollPitchYaw(roll, pitch, yaw) {
|
|
256
|
-
return this.set(roll, pitch, yaw, RotationOrder.ZYX);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
260
|
-
this._fromRotationMatrix(m, order);
|
|
261
|
-
|
|
262
|
-
return this.check();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
getRotationMatrix(m) {
|
|
266
|
-
return this._getRotationMatrix(m);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
getQuaternion() {
|
|
270
|
-
const q = new Quaternion();
|
|
271
|
-
|
|
272
|
-
switch (this[3]) {
|
|
273
|
-
case RotationOrder.XYZ:
|
|
274
|
-
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
275
|
-
|
|
276
|
-
case RotationOrder.YXZ:
|
|
277
|
-
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
|
|
278
|
-
|
|
279
|
-
case RotationOrder.ZXY:
|
|
280
|
-
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
|
|
281
|
-
|
|
282
|
-
case RotationOrder.ZYX:
|
|
283
|
-
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
|
|
284
|
-
|
|
285
|
-
case RotationOrder.YZX:
|
|
286
|
-
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
|
|
287
|
-
|
|
288
|
-
case RotationOrder.XZY:
|
|
289
|
-
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
|
|
290
|
-
|
|
291
|
-
default:
|
|
292
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
20
|
+
// Constants
|
|
21
|
+
static get ZYX() {
|
|
22
|
+
return RotationOrder.ZYX;
|
|
293
23
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
break;
|
|
321
|
-
|
|
322
|
-
case Euler.YXZ:
|
|
323
|
-
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
324
|
-
|
|
325
|
-
if (Math.abs(m23) < ALMOST_ONE) {
|
|
326
|
-
this[1] = Math.atan2(m13, m33);
|
|
327
|
-
this[2] = Math.atan2(m21, m22);
|
|
328
|
-
} else {
|
|
329
|
-
this[1] = Math.atan2(-m31, m11);
|
|
330
|
-
this[2] = 0;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
break;
|
|
334
|
-
|
|
335
|
-
case Euler.ZXY:
|
|
336
|
-
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
337
|
-
|
|
338
|
-
if (Math.abs(m32) < ALMOST_ONE) {
|
|
339
|
-
this[1] = Math.atan2(-m31, m33);
|
|
340
|
-
this[2] = Math.atan2(-m12, m22);
|
|
341
|
-
} else {
|
|
342
|
-
this[1] = 0;
|
|
343
|
-
this[2] = Math.atan2(m21, m11);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
break;
|
|
347
|
-
|
|
348
|
-
case Euler.ZYX:
|
|
349
|
-
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
350
|
-
|
|
351
|
-
if (Math.abs(m31) < ALMOST_ONE) {
|
|
352
|
-
this[0] = Math.atan2(m32, m33);
|
|
353
|
-
this[2] = Math.atan2(m21, m11);
|
|
354
|
-
} else {
|
|
355
|
-
this[0] = 0;
|
|
356
|
-
this[2] = Math.atan2(-m12, m22);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
break;
|
|
360
|
-
|
|
361
|
-
case Euler.YZX:
|
|
362
|
-
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
363
|
-
|
|
364
|
-
if (Math.abs(m21) < ALMOST_ONE) {
|
|
365
|
-
this[0] = Math.atan2(-m23, m22);
|
|
366
|
-
this[1] = Math.atan2(-m31, m11);
|
|
367
|
-
} else {
|
|
368
|
-
this[0] = 0;
|
|
369
|
-
this[1] = Math.atan2(m13, m33);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
break;
|
|
373
|
-
|
|
374
|
-
case Euler.XZY:
|
|
375
|
-
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
376
|
-
|
|
377
|
-
if (Math.abs(m12) < ALMOST_ONE) {
|
|
378
|
-
this[0] = Math.atan2(m32, m22);
|
|
379
|
-
this[1] = Math.atan2(m13, m11);
|
|
380
|
-
} else {
|
|
381
|
-
this[0] = Math.atan2(-m23, m33);
|
|
382
|
-
this[1] = 0;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
default:
|
|
388
|
-
throw new Error(ERR_UNKNOWN_ORDER);
|
|
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];
|
|
389
50
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
case Euler.XYZ:
|
|
409
|
-
{
|
|
410
|
-
const ae = a * e,
|
|
411
|
-
af = a * f,
|
|
412
|
-
be = b * e,
|
|
413
|
-
bf = b * f;
|
|
414
|
-
te[0] = c * e;
|
|
415
|
-
te[4] = -c * f;
|
|
416
|
-
te[8] = d;
|
|
417
|
-
te[1] = af + be * d;
|
|
418
|
-
te[5] = ae - bf * d;
|
|
419
|
-
te[9] = -b * c;
|
|
420
|
-
te[2] = bf - ae * d;
|
|
421
|
-
te[6] = be + af * d;
|
|
422
|
-
te[10] = a * c;
|
|
423
|
-
break;
|
|
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);
|
|
424
69
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
{
|
|
428
|
-
const ce = c * e,
|
|
429
|
-
cf = c * f,
|
|
430
|
-
de = d * e,
|
|
431
|
-
df = d * f;
|
|
432
|
-
te[0] = ce + df * b;
|
|
433
|
-
te[4] = de * b - cf;
|
|
434
|
-
te[8] = a * d;
|
|
435
|
-
te[1] = a * f;
|
|
436
|
-
te[5] = a * e;
|
|
437
|
-
te[9] = -b;
|
|
438
|
-
te[2] = cf * b - de;
|
|
439
|
-
te[6] = df + ce * b;
|
|
440
|
-
te[10] = a * c;
|
|
441
|
-
break;
|
|
70
|
+
else {
|
|
71
|
+
this.set(x, y, z, order);
|
|
442
72
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
+
fromObject(object) {
|
|
91
|
+
throw new Error('not implemented');
|
|
92
|
+
// return this.set(object.x, object.y, object.z, object.order);
|
|
93
|
+
}
|
|
94
|
+
// fromQuaternion(q, order) {
|
|
95
|
+
// this._fromRotationMat[-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
96
|
+
// return this.check();
|
|
97
|
+
// }
|
|
98
|
+
// If copied array does contain fourth element, preserves currently set order
|
|
99
|
+
copy(array) {
|
|
100
|
+
this[0] = array[0];
|
|
101
|
+
this[1] = array[1];
|
|
102
|
+
this[2] = array[2];
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
this[3] = Number.isFinite(array[3]) || this.order;
|
|
105
|
+
return this.check();
|
|
106
|
+
}
|
|
107
|
+
// Sets the three angles, and optionally sets the rotation order
|
|
108
|
+
// If order is not specified, preserves currently set order
|
|
109
|
+
set(x = 0, y = 0, z = 0, order) {
|
|
110
|
+
this[0] = x;
|
|
111
|
+
this[1] = y;
|
|
112
|
+
this[2] = z;
|
|
113
|
+
this[3] = Number.isFinite(order) ? order : this[3];
|
|
114
|
+
return this.check();
|
|
115
|
+
}
|
|
116
|
+
validate() {
|
|
117
|
+
return (validateOrder(this[3]) &&
|
|
118
|
+
Number.isFinite(this[0]) &&
|
|
119
|
+
Number.isFinite(this[1]) &&
|
|
120
|
+
Number.isFinite(this[2]));
|
|
121
|
+
}
|
|
122
|
+
// Does not copy the orientation element
|
|
123
|
+
toArray(array = [], offset = 0) {
|
|
124
|
+
array[offset] = this[0];
|
|
125
|
+
array[offset + 1] = this[1];
|
|
126
|
+
array[offset + 2] = this[2];
|
|
127
|
+
return array;
|
|
128
|
+
}
|
|
129
|
+
// Copies the orientation element
|
|
130
|
+
toArray4(array = [], offset = 0) {
|
|
131
|
+
array[offset] = this[0];
|
|
132
|
+
array[offset + 1] = this[1];
|
|
133
|
+
array[offset + 2] = this[2];
|
|
134
|
+
array[offset + 3] = this[3];
|
|
135
|
+
return array;
|
|
136
|
+
}
|
|
137
|
+
toVector3(result = [-0, -0, -0]) {
|
|
138
|
+
result[0] = this[0];
|
|
139
|
+
result[1] = this[1];
|
|
140
|
+
result[2] = this[2];
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
144
|
+
// x, y, z angle notation (note: only corresponds to axis in XYZ orientation)
|
|
145
|
+
get x() {
|
|
146
|
+
return this[0];
|
|
147
|
+
}
|
|
148
|
+
set x(value) {
|
|
149
|
+
this[0] = checkNumber(value);
|
|
150
|
+
}
|
|
151
|
+
get y() {
|
|
152
|
+
return this[1];
|
|
153
|
+
}
|
|
154
|
+
set y(value) {
|
|
155
|
+
this[1] = checkNumber(value);
|
|
156
|
+
}
|
|
157
|
+
get z() {
|
|
158
|
+
return this[2];
|
|
159
|
+
}
|
|
160
|
+
set z(value) {
|
|
161
|
+
this[2] = checkNumber(value);
|
|
162
|
+
}
|
|
163
|
+
// alpha, beta, gamma angle notation
|
|
164
|
+
get alpha() {
|
|
165
|
+
return this[0];
|
|
166
|
+
}
|
|
167
|
+
set alpha(value) {
|
|
168
|
+
this[0] = checkNumber(value);
|
|
169
|
+
}
|
|
170
|
+
get beta() {
|
|
171
|
+
return this[1];
|
|
172
|
+
}
|
|
173
|
+
set beta(value) {
|
|
174
|
+
this[1] = checkNumber(value);
|
|
175
|
+
}
|
|
176
|
+
get gamma() {
|
|
177
|
+
return this[2];
|
|
178
|
+
}
|
|
179
|
+
set gamma(value) {
|
|
180
|
+
this[2] = checkNumber(value);
|
|
181
|
+
}
|
|
182
|
+
// phi, theta, psi angle notation
|
|
183
|
+
get phi() {
|
|
184
|
+
return this[0];
|
|
185
|
+
}
|
|
186
|
+
set phi(value) {
|
|
187
|
+
this[0] = checkNumber(value);
|
|
188
|
+
}
|
|
189
|
+
get theta() {
|
|
190
|
+
return this[1];
|
|
191
|
+
}
|
|
192
|
+
set theta(value) {
|
|
193
|
+
this[1] = checkNumber(value);
|
|
194
|
+
}
|
|
195
|
+
get psi() {
|
|
196
|
+
return this[2];
|
|
197
|
+
}
|
|
198
|
+
set psi(value) {
|
|
199
|
+
this[2] = checkNumber(value);
|
|
200
|
+
}
|
|
201
|
+
// roll, pitch, yaw angle notation
|
|
202
|
+
get roll() {
|
|
203
|
+
return this[0];
|
|
204
|
+
}
|
|
205
|
+
set roll(value) {
|
|
206
|
+
this[0] = checkNumber(value);
|
|
207
|
+
}
|
|
208
|
+
get pitch() {
|
|
209
|
+
return this[1];
|
|
210
|
+
}
|
|
211
|
+
set pitch(value) {
|
|
212
|
+
this[1] = checkNumber(value);
|
|
213
|
+
}
|
|
214
|
+
get yaw() {
|
|
215
|
+
return this[2];
|
|
216
|
+
}
|
|
217
|
+
set yaw(value) {
|
|
218
|
+
this[2] = checkNumber(value);
|
|
219
|
+
}
|
|
220
|
+
// rotation order, in all three angle notations
|
|
221
|
+
get order() {
|
|
222
|
+
return this[3];
|
|
223
|
+
}
|
|
224
|
+
set order(value) {
|
|
225
|
+
this[3] = checkOrder(value);
|
|
226
|
+
}
|
|
227
|
+
// Constructors
|
|
228
|
+
fromVector3(v, order) {
|
|
229
|
+
return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
|
|
230
|
+
}
|
|
231
|
+
// TODO - with and without 4th element
|
|
232
|
+
fromArray(array, offset = 0) {
|
|
233
|
+
this[0] = array[0 + offset];
|
|
234
|
+
this[1] = array[1 + offset];
|
|
235
|
+
this[2] = array[2 + offset];
|
|
236
|
+
if (array[3] !== undefined) {
|
|
237
|
+
this[3] = array[3];
|
|
460
238
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
239
|
+
return this.check();
|
|
240
|
+
}
|
|
241
|
+
// Common ZYX rotation order
|
|
242
|
+
fromRollPitchYaw(roll, pitch, yaw) {
|
|
243
|
+
return this.set(roll, pitch, yaw, RotationOrder.ZYX);
|
|
244
|
+
}
|
|
245
|
+
fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
246
|
+
this._fromRotationMatrix(m, order);
|
|
247
|
+
return this.check();
|
|
248
|
+
}
|
|
249
|
+
// ACCESSORS
|
|
250
|
+
getRotationMatrix(m) {
|
|
251
|
+
return this._getRotationMatrix(m);
|
|
252
|
+
}
|
|
253
|
+
// TODO - move to Quaternion
|
|
254
|
+
getQuaternion() {
|
|
255
|
+
const q = new Quaternion();
|
|
256
|
+
switch (this[3]) {
|
|
257
|
+
case RotationOrder.XYZ:
|
|
258
|
+
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
259
|
+
case RotationOrder.YXZ:
|
|
260
|
+
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
|
|
261
|
+
case RotationOrder.ZXY:
|
|
262
|
+
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
|
|
263
|
+
case RotationOrder.ZYX:
|
|
264
|
+
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
|
|
265
|
+
case RotationOrder.YZX:
|
|
266
|
+
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
|
|
267
|
+
case RotationOrder.XZY:
|
|
268
|
+
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
|
|
269
|
+
default:
|
|
270
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
478
271
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
272
|
+
}
|
|
273
|
+
// INTERNAL METHODS
|
|
274
|
+
// Conversion from Euler to rotation matrix and from matrix to Euler
|
|
275
|
+
// Adapted from three.js under MIT license
|
|
276
|
+
// // WARNING: this discards revolution information -bhouston
|
|
277
|
+
// reorder(newOrder) {
|
|
278
|
+
// const q = new Quaternion().setFromEuler(this);
|
|
279
|
+
// return this.setFromQuaternion(q, newOrder);
|
|
280
|
+
/* eslint-disable complexity, max-statements, one-var */
|
|
281
|
+
_fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
282
|
+
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
283
|
+
const m11 = m[0], m12 = m[4], m13 = m[8];
|
|
284
|
+
const m21 = m[1], m22 = m[5], m23 = m[9];
|
|
285
|
+
const m31 = m[2], m32 = m[6], m33 = m[10];
|
|
286
|
+
order = order || this[3];
|
|
287
|
+
switch (order) {
|
|
288
|
+
case Euler.XYZ:
|
|
289
|
+
this[1] = Math.asin(clamp(m13, -1, 1));
|
|
290
|
+
if (Math.abs(m13) < ALMOST_ONE) {
|
|
291
|
+
this[0] = Math.atan2(-m23, m33);
|
|
292
|
+
this[2] = Math.atan2(-m12, m11);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
this[0] = Math.atan2(m32, m22);
|
|
296
|
+
this[2] = 0;
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
case Euler.YXZ:
|
|
300
|
+
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
301
|
+
if (Math.abs(m23) < ALMOST_ONE) {
|
|
302
|
+
this[1] = Math.atan2(m13, m33);
|
|
303
|
+
this[2] = Math.atan2(m21, m22);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this[1] = Math.atan2(-m31, m11);
|
|
307
|
+
this[2] = 0;
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
case Euler.ZXY:
|
|
311
|
+
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
312
|
+
if (Math.abs(m32) < ALMOST_ONE) {
|
|
313
|
+
this[1] = Math.atan2(-m31, m33);
|
|
314
|
+
this[2] = Math.atan2(-m12, m22);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
this[1] = 0;
|
|
318
|
+
this[2] = Math.atan2(m21, m11);
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case Euler.ZYX:
|
|
322
|
+
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
323
|
+
if (Math.abs(m31) < ALMOST_ONE) {
|
|
324
|
+
this[0] = Math.atan2(m32, m33);
|
|
325
|
+
this[2] = Math.atan2(m21, m11);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this[0] = 0;
|
|
329
|
+
this[2] = Math.atan2(-m12, m22);
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
case Euler.YZX:
|
|
333
|
+
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
334
|
+
if (Math.abs(m21) < ALMOST_ONE) {
|
|
335
|
+
this[0] = Math.atan2(-m23, m22);
|
|
336
|
+
this[1] = Math.atan2(-m31, m11);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this[0] = 0;
|
|
340
|
+
this[1] = Math.atan2(m13, m33);
|
|
341
|
+
}
|
|
342
|
+
break;
|
|
343
|
+
case Euler.XZY:
|
|
344
|
+
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
345
|
+
if (Math.abs(m12) < ALMOST_ONE) {
|
|
346
|
+
this[0] = Math.atan2(m32, m22);
|
|
347
|
+
this[1] = Math.atan2(m13, m11);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
this[0] = Math.atan2(-m23, m33);
|
|
351
|
+
this[1] = 0;
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
default:
|
|
355
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
496
356
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
357
|
+
this[3] = order;
|
|
358
|
+
return this;
|
|
359
|
+
}
|
|
360
|
+
_getRotationMatrix(result) {
|
|
361
|
+
const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
362
|
+
const x = this.x, y = this.y, z = this.z;
|
|
363
|
+
const a = Math.cos(x);
|
|
364
|
+
const c = Math.cos(y);
|
|
365
|
+
const e = Math.cos(z);
|
|
366
|
+
const b = Math.sin(x);
|
|
367
|
+
const d = Math.sin(y);
|
|
368
|
+
const f = Math.sin(z);
|
|
369
|
+
switch (this[3]) {
|
|
370
|
+
case Euler.XYZ: {
|
|
371
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
372
|
+
te[0] = c * e;
|
|
373
|
+
te[4] = -c * f;
|
|
374
|
+
te[8] = d;
|
|
375
|
+
te[1] = af + be * d;
|
|
376
|
+
te[5] = ae - bf * d;
|
|
377
|
+
te[9] = -b * c;
|
|
378
|
+
te[2] = bf - ae * d;
|
|
379
|
+
te[6] = be + af * d;
|
|
380
|
+
te[10] = a * c;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
case Euler.YXZ: {
|
|
384
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
385
|
+
te[0] = ce + df * b;
|
|
386
|
+
te[4] = de * b - cf;
|
|
387
|
+
te[8] = a * d;
|
|
388
|
+
te[1] = a * f;
|
|
389
|
+
te[5] = a * e;
|
|
390
|
+
te[9] = -b;
|
|
391
|
+
te[2] = cf * b - de;
|
|
392
|
+
te[6] = df + ce * b;
|
|
393
|
+
te[10] = a * c;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
case Euler.ZXY: {
|
|
397
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
398
|
+
te[0] = ce - df * b;
|
|
399
|
+
te[4] = -a * f;
|
|
400
|
+
te[8] = de + cf * b;
|
|
401
|
+
te[1] = cf + de * b;
|
|
402
|
+
te[5] = a * e;
|
|
403
|
+
te[9] = df - ce * b;
|
|
404
|
+
te[2] = -a * d;
|
|
405
|
+
te[6] = b;
|
|
406
|
+
te[10] = a * c;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case Euler.ZYX: {
|
|
410
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
411
|
+
te[0] = c * e;
|
|
412
|
+
te[4] = be * d - af;
|
|
413
|
+
te[8] = ae * d + bf;
|
|
414
|
+
te[1] = c * f;
|
|
415
|
+
te[5] = bf * d + ae;
|
|
416
|
+
te[9] = af * d - be;
|
|
417
|
+
te[2] = -d;
|
|
418
|
+
te[6] = b * c;
|
|
419
|
+
te[10] = a * c;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case Euler.YZX: {
|
|
423
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
424
|
+
te[0] = c * e;
|
|
425
|
+
te[4] = bd - ac * f;
|
|
426
|
+
te[8] = bc * f + ad;
|
|
427
|
+
te[1] = f;
|
|
428
|
+
te[5] = a * e;
|
|
429
|
+
te[9] = -b * e;
|
|
430
|
+
te[2] = -d * e;
|
|
431
|
+
te[6] = ad * f + bc;
|
|
432
|
+
te[10] = ac - bd * f;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case Euler.XZY: {
|
|
436
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
437
|
+
te[0] = c * e;
|
|
438
|
+
te[4] = -f;
|
|
439
|
+
te[8] = d * e;
|
|
440
|
+
te[1] = ac * f + bd;
|
|
441
|
+
te[5] = a * e;
|
|
442
|
+
te[9] = ad * f - bc;
|
|
443
|
+
te[2] = bc * f - ad;
|
|
444
|
+
te[6] = b * e;
|
|
445
|
+
te[10] = bd * f + ac;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
default:
|
|
449
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
514
450
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
451
|
+
// last column
|
|
452
|
+
te[3] = 0;
|
|
453
|
+
te[7] = 0;
|
|
454
|
+
te[11] = 0;
|
|
455
|
+
// bottom row
|
|
456
|
+
te[12] = 0;
|
|
457
|
+
te[13] = 0;
|
|
458
|
+
te[14] = 0;
|
|
459
|
+
te[15] = 1;
|
|
460
|
+
return te;
|
|
461
|
+
}
|
|
462
|
+
toQuaternion() {
|
|
463
|
+
// Abbreviations for the various angular functions
|
|
464
|
+
const cy = Math.cos(this.yaw * 0.5);
|
|
465
|
+
const sy = Math.sin(this.yaw * 0.5);
|
|
466
|
+
const cr = Math.cos(this.roll * 0.5);
|
|
467
|
+
const sr = Math.sin(this.roll * 0.5);
|
|
468
|
+
const cp = Math.cos(this.pitch * 0.5);
|
|
469
|
+
const sp = Math.sin(this.pitch * 0.5);
|
|
470
|
+
const w = cy * cr * cp + sy * sr * sp;
|
|
471
|
+
const x = cy * sr * cp - sy * cr * sp;
|
|
472
|
+
const y = cy * cr * sp + sy * sr * cp;
|
|
473
|
+
const z = sy * cr * cp - cy * sr * sp;
|
|
474
|
+
return new Quaternion(x, y, z, w);
|
|
518
475
|
}
|
|
519
|
-
|
|
520
|
-
te[3] = 0;
|
|
521
|
-
te[7] = 0;
|
|
522
|
-
te[11] = 0;
|
|
523
|
-
te[12] = 0;
|
|
524
|
-
te[13] = 0;
|
|
525
|
-
te[14] = 0;
|
|
526
|
-
te[15] = 1;
|
|
527
|
-
return te;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
toQuaternion() {
|
|
531
|
-
const cy = Math.cos(this.yaw * 0.5);
|
|
532
|
-
const sy = Math.sin(this.yaw * 0.5);
|
|
533
|
-
const cr = Math.cos(this.roll * 0.5);
|
|
534
|
-
const sr = Math.sin(this.roll * 0.5);
|
|
535
|
-
const cp = Math.cos(this.pitch * 0.5);
|
|
536
|
-
const sp = Math.sin(this.pitch * 0.5);
|
|
537
|
-
const w = cy * cr * cp + sy * sr * sp;
|
|
538
|
-
const x = cy * sr * cp - sy * cr * sp;
|
|
539
|
-
const y = cy * cr * sp + sy * sr * cp;
|
|
540
|
-
const z = sy * cr * cp - cy * sr * sp;
|
|
541
|
-
return new Quaternion(x, y, z, w);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
476
|
}
|
|
545
|
-
|
|
477
|
+
// HELPER FUNCTIONS
|
|
546
478
|
function validateOrder(value) {
|
|
547
|
-
|
|
479
|
+
return value >= 0 && value < 6;
|
|
548
480
|
}
|
|
549
|
-
|
|
550
481
|
function checkOrder(value) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return value;
|
|
482
|
+
if (value < 0 && value >= 6) {
|
|
483
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
484
|
+
}
|
|
485
|
+
return value;
|
|
556
486
|
}
|
|
557
|
-
//# sourceMappingURL=euler.js.map
|