Skip to content

Commit 0994520

Browse files
authored
Quaternion - Support extrapolation in slerp methods (#32541)
1 parent 1d2a5f7 commit 0994520

2 files changed

Lines changed: 5 additions & 31 deletions

File tree

src/math/Quaternion.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Quaternion {
5454
* @param {number} srcOffset0 - An offset into the first source array.
5555
* @param {Array<number>} src1 - The source array of the second quaternion.
5656
* @param {number} srcOffset1 - An offset into the second source array.
57-
* @param {number} t - The interpolation factor in the range `[0,1]`.
57+
* @param {number} t - The interpolation factor. A value in the range `[0,1]` will interpolate. A value outside the range `[0,1]` will extrapolate.
5858
* @see {@link Quaternion#slerp}
5959
*/
6060
static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
@@ -69,28 +69,6 @@ class Quaternion {
6969
z1 = src1[ srcOffset1 + 2 ],
7070
w1 = src1[ srcOffset1 + 3 ];
7171

72-
if ( t <= 0 ) {
73-
74-
dst[ dstOffset + 0 ] = x0;
75-
dst[ dstOffset + 1 ] = y0;
76-
dst[ dstOffset + 2 ] = z0;
77-
dst[ dstOffset + 3 ] = w0;
78-
79-
return;
80-
81-
}
82-
83-
if ( t >= 1 ) {
84-
85-
dst[ dstOffset + 0 ] = x1;
86-
dst[ dstOffset + 1 ] = y1;
87-
dst[ dstOffset + 2 ] = z1;
88-
dst[ dstOffset + 3 ] = w1;
89-
90-
return;
91-
92-
}
93-
9472
if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
9573

9674
let dot = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1;
@@ -732,18 +710,14 @@ class Quaternion {
732710
}
733711

734712
/**
735-
* Performs a spherical linear interpolation between quaternions.
713+
* Performs a spherical linear interpolation between this quaternion and the target quaternion.
736714
*
737715
* @param {Quaternion} qb - The target quaternion.
738-
* @param {number} t - The interpolation factor in the closed interval `[0, 1]`.
716+
* @param {number} t - The interpolation factor. A value in the range `[0,1]` will interpolate. A value outside the range `[0,1]` will extrapolate.
739717
* @return {Quaternion} A reference to this quaternion.
740718
*/
741719
slerp( qb, t ) {
742720

743-
if ( t <= 0 ) return this;
744-
745-
if ( t >= 1 ) return this.copy( qb ); // copy calls _onChangeCallback()
746-
747721
let x = qb._x, y = qb._y, z = qb._z, w = qb._w;
748722

749723
let dot = this.dot( qb );

test/unit/src/math/Quaternion.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ export default QUnit.module( 'Maths', () => {
628628

629629
QUnit.test( 'slerp', ( assert ) => {
630630

631-
const a = new Quaternion( x, y, z, w );
632-
const b = new Quaternion( - x, - y, - z, - w );
631+
const a = new Quaternion( x, y, z, w ).normalize();
632+
const b = new Quaternion( w, x, y, z ).normalize();
633633

634634
const c = a.clone().slerp( b, 0 );
635635
const d = a.clone().slerp( b, 1 );

0 commit comments

Comments
 (0)