Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions src/math/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions test/unit/src/math/Quaternion.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case was failing.

A quaternion and its negation represent the same rotation, so the equality test used here is invalid.

For now, I made an arbitrary change that passes the test.


const c = a.clone().slerp( b, 0 );
const d = a.clone().slerp( b, 1 );
Expand Down