@woosh/meep-engine 2.126.56 → 2.126.57
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 +1 -1
- package/src/core/geom/3d/mat4/apply_mat4_transform_to_v3_array.d.ts.map +1 -1
- package/src/core/geom/3d/mat4/apply_mat4_transform_to_v3_array.js +3 -29
- package/src/core/geom/Quaternion.d.ts +31 -20
- package/src/core/geom/Quaternion.d.ts.map +1 -1
- package/src/core/geom/Quaternion.js +35 -21
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Pure JavaScript game engine. Fully featured and production ready.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.126.
|
|
8
|
+
"version": "2.126.57",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply_mat4_transform_to_v3_array.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/apply_mat4_transform_to_v3_array.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apply_mat4_transform_to_v3_array.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/apply_mat4_transform_to_v3_array.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,yDAPW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,eACN,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,sBAClC,MAAM,gBACN,MAAM,QACN,MAAK,MAAM,EAAE,GAAC,YAAY,QAkBpC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { v3_matrix4_multiply } from "../../vec3/v3_matrix4_multiply.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Matrix-transform an array of 3d points
|
|
3
5
|
* Code is inlined for speed
|
|
@@ -14,41 +16,13 @@ export function apply_mat4_transform_to_v3_array(
|
|
|
14
16
|
vertex_count, mat4
|
|
15
17
|
) {
|
|
16
18
|
|
|
17
|
-
const a0 = mat4[0];
|
|
18
|
-
const a1 = mat4[1];
|
|
19
|
-
const a2 = mat4[2];
|
|
20
|
-
|
|
21
|
-
const b0 = mat4[4];
|
|
22
|
-
const b1 = mat4[5];
|
|
23
|
-
const b2 = mat4[6];
|
|
24
|
-
|
|
25
|
-
const c0 = mat4[8];
|
|
26
|
-
const c1 = mat4[9];
|
|
27
|
-
const c2 = mat4[10];
|
|
28
|
-
|
|
29
|
-
const d0 = mat4[12];
|
|
30
|
-
const d1 = mat4[13];
|
|
31
|
-
const d2 = mat4[14];
|
|
32
|
-
|
|
33
19
|
for (let i = 0; i < vertex_count; i++) {
|
|
34
20
|
const i3 = i * 3;
|
|
35
21
|
|
|
36
22
|
const source_vertex_address = source_offset + i3;
|
|
37
|
-
|
|
38
|
-
const _x = source[source_vertex_address];
|
|
39
|
-
const _y = source[source_vertex_address + 1];
|
|
40
|
-
const _z = source[source_vertex_address + 2];
|
|
41
|
-
|
|
42
|
-
const x = a0 * _x + b0 * _y + c0 * _z + d0;
|
|
43
|
-
const y = a1 * _x + b1 * _y + c1 * _z + d1;
|
|
44
|
-
const z = a2 * _x + b2 * _y + c2 * _z + d2;
|
|
45
|
-
|
|
46
23
|
const destination_vertex_address = destination_offset + i3;
|
|
47
24
|
|
|
48
|
-
destination
|
|
49
|
-
destination[destination_vertex_address + 1] = y;
|
|
50
|
-
destination[destination_vertex_address + 2] = z;
|
|
51
|
-
|
|
25
|
+
v3_matrix4_multiply(destination,destination_vertex_address, source,source_vertex_address, mat4);
|
|
52
26
|
|
|
53
27
|
}
|
|
54
28
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Represents rotation in 3d space
|
|
4
4
|
*
|
|
5
5
|
* Iterating through a Quaternion instance will yield its components `(x, y, z, w)` in the corresponding order.
|
|
6
|
-
*
|
|
6
|
+
* Note that a quaternion must be {@link normalize}d to properly represent rotation. Check documentation of individual operations when in doubt.
|
|
7
7
|
* @see https://en.wikipedia.org/wiki/Quaternion
|
|
8
8
|
* @implements Iterable<number>
|
|
9
9
|
*
|
|
@@ -120,7 +120,8 @@ export class Quaternion implements Iterable<number> {
|
|
|
120
120
|
get 3(): number;
|
|
121
121
|
/**
|
|
122
122
|
* Orient quaternion on a `forward` vector, with the spin matching `up` vector
|
|
123
|
-
* Useful for `lookAt` operations, such as for camera or inverse kinematics
|
|
123
|
+
* Useful for `lookAt` operations, such as for camera or inverse kinematics.
|
|
124
|
+
* Normalizes input, meaning input does not have to be normalized.
|
|
124
125
|
* @param {number} fx forward vector
|
|
125
126
|
* @param {number} fy forward vector
|
|
126
127
|
* @param {number} fz forward vector
|
|
@@ -131,11 +132,12 @@ export class Quaternion implements Iterable<number> {
|
|
|
131
132
|
*/
|
|
132
133
|
_lookRotation(fx: number, fy: number, fz: number, ux: number, uy: number, uz: number): this;
|
|
133
134
|
/**
|
|
134
|
-
* Orient quaternion to align with the `forward`
|
|
135
|
-
* @param {Vector3} forward
|
|
136
|
-
* @param {Vector3} [up=Vector3.up]
|
|
135
|
+
* Orient quaternion to align with the `forward` direction.
|
|
136
|
+
* @param {Vector3} forward Does not need to be normalized.
|
|
137
|
+
* @param {Vector3} [up=Vector3.up] Does not need to be normalized.
|
|
138
|
+
* @returns {this}
|
|
137
139
|
*/
|
|
138
|
-
lookRotation(forward: Vector3, up?: Vector3):
|
|
140
|
+
lookRotation(forward: Vector3, up?: Vector3): this;
|
|
139
141
|
/**
|
|
140
142
|
* Vector dot product in 4 dimensions
|
|
141
143
|
* @param {Quaternion} other
|
|
@@ -145,8 +147,9 @@ export class Quaternion implements Iterable<number> {
|
|
|
145
147
|
/**
|
|
146
148
|
* Makes this quaternion into an inverse of the other
|
|
147
149
|
* @param {Quaternion} other
|
|
150
|
+
* @returns {this}
|
|
148
151
|
*/
|
|
149
|
-
copyInverse(other: Quaternion):
|
|
152
|
+
copyInverse(other: Quaternion): this;
|
|
150
153
|
/**
|
|
151
154
|
* Calculates the inverse
|
|
152
155
|
* @returns {this}
|
|
@@ -162,16 +165,18 @@ export class Quaternion implements Iterable<number> {
|
|
|
162
165
|
* Set quaternion from axis + angle definition
|
|
163
166
|
* @param {Vector3} axis
|
|
164
167
|
* @param {number} angle
|
|
168
|
+
* @returns {this}
|
|
165
169
|
*/
|
|
166
|
-
fromAxisAngle(axis: Vector3, angle: number):
|
|
170
|
+
fromAxisAngle(axis: Vector3, angle: number): this;
|
|
167
171
|
/**
|
|
168
172
|
*
|
|
169
173
|
* @param {number} axis_x
|
|
170
174
|
* @param {number} axis_y
|
|
171
175
|
* @param {number} axis_z
|
|
172
176
|
* @param {number} angle
|
|
177
|
+
* @returns {this}
|
|
173
178
|
*/
|
|
174
|
-
_fromAxisAngle(axis_x: number, axis_y: number, axis_z: number, angle: number):
|
|
179
|
+
_fromAxisAngle(axis_x: number, axis_y: number, axis_z: number, angle: number): this;
|
|
175
180
|
/**
|
|
176
181
|
* Given a direction axis, compute rotation quaternions from current rotation to that axis as swing and twist. Swing moves to a given orientation while without "twisting",
|
|
177
182
|
* `twist` just the twist around the given axis, no change in orientation.
|
|
@@ -189,11 +194,11 @@ export class Quaternion implements Iterable<number> {
|
|
|
189
194
|
*/
|
|
190
195
|
computeTwistAngle(axis: Vector3): number;
|
|
191
196
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param {Vector3} axis
|
|
197
|
+
* Decompose quaternion to the axis of rotation and angle around this axis.
|
|
198
|
+
* @param {Vector3} out_axis axis will be written here
|
|
194
199
|
* @returns {number} angle in radians
|
|
195
200
|
*/
|
|
196
|
-
toAxisAngle(
|
|
201
|
+
toAxisAngle(out_axis: Vector3): number;
|
|
197
202
|
/**
|
|
198
203
|
*
|
|
199
204
|
* @returns {this}
|
|
@@ -261,9 +266,15 @@ export class Quaternion implements Iterable<number> {
|
|
|
261
266
|
* @param {number} y
|
|
262
267
|
* @param {number} z
|
|
263
268
|
* @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
264
|
-
* @returns {
|
|
269
|
+
* @returns {this}
|
|
270
|
+
* @see fromEulerAnglesXYZ
|
|
271
|
+
* @see fromEulerAnglesYXZ
|
|
272
|
+
* @see fromEulerAnglesZXY
|
|
273
|
+
* @see fromEulerAnglesZYX
|
|
274
|
+
* @see fromEulerAnglesYZX
|
|
275
|
+
* @see fromEulerAnglesXZY
|
|
265
276
|
*/
|
|
266
|
-
__setFromEuler(x: number, y: number, z: number, order?: string):
|
|
277
|
+
__setFromEuler(x: number, y: number, z: number, order?: string): this;
|
|
267
278
|
/**
|
|
268
279
|
* @see https://localcoder.org/euler-angle-to-quaternion-then-quaternion-to-euler-angle
|
|
269
280
|
* @see https://discourse.mcneel.com/t/what-is-the-right-method-to-convert-quaternion-to-plane-using-rhinocommon/92411/21?page=2
|
|
@@ -349,18 +360,18 @@ export class Quaternion implements Iterable<number> {
|
|
|
349
360
|
/**
|
|
350
361
|
* NOTE: Vectors need to be normalized
|
|
351
362
|
*
|
|
352
|
-
* @param {Vector3} from
|
|
353
|
-
* @param {Vector3} to
|
|
363
|
+
* @param {Vector3} from Must be normalized
|
|
364
|
+
* @param {Vector3} to Must be normalized
|
|
354
365
|
* @returns {this}
|
|
355
366
|
*/
|
|
356
367
|
fromUnitVectors(from: Vector3, to: Vector3): this;
|
|
357
368
|
/**
|
|
358
|
-
* @param {number[]} m4x4
|
|
369
|
+
* @param {number[]|Float32Array} m4x4
|
|
359
370
|
* @returns {this}
|
|
360
371
|
*/
|
|
361
|
-
setFromRotationMatrix(m4x4: number[]): this;
|
|
372
|
+
setFromRotationMatrix(m4x4: number[] | Float32Array): this;
|
|
362
373
|
/**
|
|
363
|
-
* This algorithm comes from
|
|
374
|
+
* This algorithm comes from "Quaternion Calculus and Fast Animation",
|
|
364
375
|
* Ken Shoemake, 1987 SIGGRAPH course notes
|
|
365
376
|
* @see https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/src/Geometry/Quaternion.h#L813
|
|
366
377
|
* @param {number} m11
|
|
@@ -395,7 +406,7 @@ export class Quaternion implements Iterable<number> {
|
|
|
395
406
|
* Spherical linear interpolation
|
|
396
407
|
* @param {Quaternion} from
|
|
397
408
|
* @param {Quaternion} to
|
|
398
|
-
* @param {number} t coefficient, how much between the input
|
|
409
|
+
* @param {number} t coefficient, how much between the input quaternions? Must be a value between 0 and 1
|
|
399
410
|
* @returns {this}
|
|
400
411
|
*/
|
|
401
412
|
slerpQuaternions(from: Quaternion, to: Quaternion, t: number): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,mCALe,QAAQ,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,mCALe,QAAQ,CAAC,MAAM;IA+R1B;;;;;OAKG;IACH,2BAJW,OAAO,SACP,MAAM,GACJ,UAAU,CAQtB;IAiqCD;;;;OAIG;IACH,kCAFa,UAAU,CAQtB;IAED;;;;;;;OAOG;IACH,0BALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,UAAU,CAQtB;IAED;;;;;;OAMG;IACH,6BALW,UAAU,QACV,UAAU,MACV,UAAU,aACV,MAAM,QA0BhB;IAlgDD;;;;;;;OAOG;IACH,gBANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAsChB;IA7BG;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,oBAFU,MAAM,CAAC,MAAM,EAAE,MAAM,EAA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,KACN,MAAM,cACN,MAAM,GACL,OAAO,CASlB;IAED;;;;OAIG;IACH,gBAHW,MAAW,MAAM,GAChB,UAAU,CAuBrB;IAED,mBAEC;IAiEL,mBApLe,MAAM,EAAE,WACR,MAAM,gBAmLS;IAC9B,kBAtKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAoKG;IAC5B,kBAvKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAqKG;IAC5B,qBA3yBe,MAAM,KACN,MAAM,KACN,MAAM,gBAyyBe;IAQpC;;;;OAIG;IACH,uBAFU,OAAO,CAEgB;IAt6C7B;;;OAGG;IACH,qBAFa,SAAS,CAAC,MAAM,CAAC,CAS7B;CAy4CJ;;kBASS,UAAU;kBAaV,MAAM;;;mBAzjDG,4BAA4B;oBAU3B,cAAc"}
|
|
@@ -23,7 +23,7 @@ const cos = Math.cos;
|
|
|
23
23
|
* Represents rotation in 3d space
|
|
24
24
|
*
|
|
25
25
|
* Iterating through a Quaternion instance will yield its components `(x, y, z, w)` in the corresponding order.
|
|
26
|
-
*
|
|
26
|
+
* Note that a quaternion must be {@link normalize}d to properly represent rotation. Check documentation of individual operations when in doubt.
|
|
27
27
|
* @see https://en.wikipedia.org/wiki/Quaternion
|
|
28
28
|
* @implements Iterable<number>
|
|
29
29
|
*
|
|
@@ -158,7 +158,8 @@ export class Quaternion {
|
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* Orient quaternion on a `forward` vector, with the spin matching `up` vector
|
|
161
|
-
* Useful for `lookAt` operations, such as for camera or inverse kinematics
|
|
161
|
+
* Useful for `lookAt` operations, such as for camera or inverse kinematics.
|
|
162
|
+
* Normalizes input, meaning input does not have to be normalized.
|
|
162
163
|
* @param {number} fx forward vector
|
|
163
164
|
* @param {number} fy forward vector
|
|
164
165
|
* @param {number} fz forward vector
|
|
@@ -221,13 +222,14 @@ export class Quaternion {
|
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
/**
|
|
224
|
-
* Orient quaternion to align with the `forward`
|
|
225
|
-
* @param {Vector3} forward
|
|
226
|
-
* @param {Vector3} [up=Vector3.up]
|
|
225
|
+
* Orient quaternion to align with the `forward` direction.
|
|
226
|
+
* @param {Vector3} forward Does not need to be normalized.
|
|
227
|
+
* @param {Vector3} [up=Vector3.up] Does not need to be normalized.
|
|
228
|
+
* @returns {this}
|
|
227
229
|
*/
|
|
228
230
|
lookRotation(forward, up = Vector3.up) {
|
|
229
231
|
|
|
230
|
-
this._lookRotation(
|
|
232
|
+
return this._lookRotation(
|
|
231
233
|
forward.x, forward.y, forward.z,
|
|
232
234
|
up.x, up.y, up.z
|
|
233
235
|
);
|
|
@@ -250,10 +252,11 @@ export class Quaternion {
|
|
|
250
252
|
/**
|
|
251
253
|
* Makes this quaternion into an inverse of the other
|
|
252
254
|
* @param {Quaternion} other
|
|
255
|
+
* @returns {this}
|
|
253
256
|
*/
|
|
254
257
|
copyInverse(other) {
|
|
255
258
|
this.copy(other);
|
|
256
|
-
this.invert();
|
|
259
|
+
return this.invert();
|
|
257
260
|
}
|
|
258
261
|
|
|
259
262
|
/**
|
|
@@ -327,11 +330,14 @@ export class Quaternion {
|
|
|
327
330
|
* Set quaternion from axis + angle definition
|
|
328
331
|
* @param {Vector3} axis
|
|
329
332
|
* @param {number} angle
|
|
333
|
+
* @returns {this}
|
|
330
334
|
*/
|
|
331
335
|
fromAxisAngle(axis, angle) {
|
|
332
336
|
assert.defined(axis, 'axis');
|
|
337
|
+
assert.isObject(axis, 'axis');
|
|
338
|
+
assert.isNumber(angle, 'angle');
|
|
333
339
|
|
|
334
|
-
this._fromAxisAngle(axis.x, axis.y, axis.z, angle);
|
|
340
|
+
return this._fromAxisAngle(axis.x, axis.y, axis.z, angle);
|
|
335
341
|
}
|
|
336
342
|
|
|
337
343
|
/**
|
|
@@ -340,6 +346,7 @@ export class Quaternion {
|
|
|
340
346
|
* @param {number} axis_y
|
|
341
347
|
* @param {number} axis_z
|
|
342
348
|
* @param {number} angle
|
|
349
|
+
* @returns {this}
|
|
343
350
|
*/
|
|
344
351
|
_fromAxisAngle(axis_x, axis_y, axis_z, angle) {
|
|
345
352
|
assert.isNumber(axis_x, 'axis_x');
|
|
@@ -372,7 +379,7 @@ export class Quaternion {
|
|
|
372
379
|
const z = qz * m;
|
|
373
380
|
const w = qw * m;
|
|
374
381
|
|
|
375
|
-
this.set(x, y, z, w);
|
|
382
|
+
return this.set(x, y, z, w);
|
|
376
383
|
}
|
|
377
384
|
|
|
378
385
|
/**
|
|
@@ -442,25 +449,26 @@ export class Quaternion {
|
|
|
442
449
|
}
|
|
443
450
|
|
|
444
451
|
/**
|
|
445
|
-
*
|
|
446
|
-
* @param {Vector3} axis
|
|
452
|
+
* Decompose quaternion to the axis of rotation and angle around this axis.
|
|
453
|
+
* @param {Vector3} out_axis axis will be written here
|
|
447
454
|
* @returns {number} angle in radians
|
|
448
455
|
*/
|
|
449
|
-
toAxisAngle(
|
|
456
|
+
toAxisAngle(out_axis) {
|
|
450
457
|
const rad = Math.acos(this.w) * 2.0;
|
|
451
458
|
|
|
452
459
|
const s = sin(rad * 0.5);
|
|
453
460
|
|
|
454
461
|
if (Math.abs(s) > EPSILON) {
|
|
455
|
-
|
|
462
|
+
out_axis.set(
|
|
456
463
|
this.x / s,
|
|
457
464
|
this.y / s,
|
|
458
465
|
this.z / s
|
|
459
466
|
);
|
|
460
467
|
} else {
|
|
461
468
|
// If s is zero, return any axis (no rotation - axis does not matter)
|
|
462
|
-
|
|
469
|
+
out_axis.set(1, 0, 0);
|
|
463
470
|
}
|
|
471
|
+
|
|
464
472
|
return rad;
|
|
465
473
|
}
|
|
466
474
|
|
|
@@ -608,7 +616,13 @@ export class Quaternion {
|
|
|
608
616
|
* @param {number} y
|
|
609
617
|
* @param {number} z
|
|
610
618
|
* @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
611
|
-
* @returns {
|
|
619
|
+
* @returns {this}
|
|
620
|
+
* @see fromEulerAnglesXYZ
|
|
621
|
+
* @see fromEulerAnglesYXZ
|
|
622
|
+
* @see fromEulerAnglesZXY
|
|
623
|
+
* @see fromEulerAnglesZYX
|
|
624
|
+
* @see fromEulerAnglesYZX
|
|
625
|
+
* @see fromEulerAnglesXZY
|
|
612
626
|
*/
|
|
613
627
|
__setFromEuler(
|
|
614
628
|
x,
|
|
@@ -934,12 +948,12 @@ export class Quaternion {
|
|
|
934
948
|
/**
|
|
935
949
|
* NOTE: Vectors need to be normalized
|
|
936
950
|
*
|
|
937
|
-
* @param {Vector3} from
|
|
938
|
-
* @param {Vector3} to
|
|
951
|
+
* @param {Vector3} from Must be normalized
|
|
952
|
+
* @param {Vector3} to Must be normalized
|
|
939
953
|
* @returns {this}
|
|
940
954
|
*/
|
|
941
955
|
fromUnitVectors(from, to) {
|
|
942
|
-
// Based on blog post: http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
|
|
956
|
+
// Based on this blog post: http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
|
|
943
957
|
|
|
944
958
|
assert.ok(from.isNormalized(), `from vector is not normalized, length = ${from.length()}`);
|
|
945
959
|
assert.ok(to.isNormalized(), `to vector is not normalized, length = ${to.length()}`);
|
|
@@ -1005,7 +1019,7 @@ export class Quaternion {
|
|
|
1005
1019
|
}
|
|
1006
1020
|
|
|
1007
1021
|
/**
|
|
1008
|
-
* @param {number[]} m4x4
|
|
1022
|
+
* @param {number[]|Float32Array} m4x4
|
|
1009
1023
|
* @returns {this}
|
|
1010
1024
|
*/
|
|
1011
1025
|
setFromRotationMatrix(m4x4) {
|
|
@@ -1021,7 +1035,7 @@ export class Quaternion {
|
|
|
1021
1035
|
}
|
|
1022
1036
|
|
|
1023
1037
|
/**
|
|
1024
|
-
* This algorithm comes from
|
|
1038
|
+
* This algorithm comes from "Quaternion Calculus and Fast Animation",
|
|
1025
1039
|
* Ken Shoemake, 1987 SIGGRAPH course notes
|
|
1026
1040
|
* @see https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/src/Geometry/Quaternion.h#L813
|
|
1027
1041
|
* @param {number} m11
|
|
@@ -1151,7 +1165,7 @@ export class Quaternion {
|
|
|
1151
1165
|
* Spherical linear interpolation
|
|
1152
1166
|
* @param {Quaternion} from
|
|
1153
1167
|
* @param {Quaternion} to
|
|
1154
|
-
* @param {number} t coefficient, how much between the input
|
|
1168
|
+
* @param {number} t coefficient, how much between the input quaternions? Must be a value between 0 and 1
|
|
1155
1169
|
* @returns {this}
|
|
1156
1170
|
*/
|
|
1157
1171
|
slerpQuaternions(from, to, t) {
|