Browse Source

Quaternion - Support extrapolation in slerp methods (#32541)

WestLangley 2 months ago
parent
commit
0994520f78
2 changed files with 5 additions and 31 deletions
  1. 3 29
      src/math/Quaternion.js
  2. 2 2
      test/unit/src/math/Quaternion.tests.js

+ 3 - 29
src/math/Quaternion.js

@@ -54,7 +54,7 @@ class Quaternion {
 	 * @param {number} srcOffset0 - An offset into the first source array.
 	 * @param {Array<number>} src1 -  The source array of the second quaternion.
 	 * @param {number} srcOffset1 - An offset into the second source array.
-	 * @param {number} t - The interpolation factor in the range `[0,1]`.
+	 * @param {number} t - The interpolation factor. A value in the range `[0,1]` will interpolate. A value outside the range `[0,1]` will extrapolate.
 	 * @see {@link Quaternion#slerp}
 	 */
 	static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
@@ -69,28 +69,6 @@ class Quaternion {
 			z1 = src1[ srcOffset1 + 2 ],
 			w1 = src1[ srcOffset1 + 3 ];
 
-		if ( t <= 0 ) {
-
-			dst[ dstOffset + 0 ] = x0;
-			dst[ dstOffset + 1 ] = y0;
-			dst[ dstOffset + 2 ] = z0;
-			dst[ dstOffset + 3 ] = w0;
-
-			return;
-
-		}
-
-		if ( t >= 1 ) {
-
-			dst[ dstOffset + 0 ] = x1;
-			dst[ dstOffset + 1 ] = y1;
-			dst[ dstOffset + 2 ] = z1;
-			dst[ dstOffset + 3 ] = w1;
-
-			return;
-
-		}
-
 		if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
 
 			let dot = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1;
@@ -732,18 +710,14 @@ class Quaternion {
 	}
 
 	/**
-	 * Performs a spherical linear interpolation between quaternions.
+	 * Performs a spherical linear interpolation between this quaternion and the target quaternion.
 	 *
 	 * @param {Quaternion} qb - The target quaternion.
-	 * @param {number} t - The interpolation factor in the closed interval `[0, 1]`.
+	 * @param {number} t - The interpolation factor. A value in the range `[0,1]` will interpolate. A value outside the range `[0,1]` will extrapolate.
 	 * @return {Quaternion} A reference to this quaternion.
 	 */
 	slerp( qb, t ) {
 
-		if ( t <= 0 ) return this;
-
-		if ( t >= 1 ) return this.copy( qb ); // copy calls _onChangeCallback()
-
 		let x = qb._x, y = qb._y, z = qb._z, w = qb._w;
 
 		let dot = this.dot( qb );

+ 2 - 2
test/unit/src/math/Quaternion.tests.js

@@ -628,8 +628,8 @@ export default QUnit.module( 'Maths', () => {
 
 		QUnit.test( 'slerp', ( assert ) => {
 
-			const a = new Quaternion( x, y, z, w );
-			const b = new Quaternion( - x, - y, - z, - w );
+			const a = new Quaternion( x, y, z, w ).normalize();
+			const b = new Quaternion( w, x, y, z ).normalize();
 
 			const c = a.clone().slerp( b, 0 );
 			const d = a.clone().slerp( b, 1 );

粤ICP备19079148号