Ver código fonte

Fix Quaternion.slerp for special case t=0 and t=1

returned value was not exactly source or target quaternion thus was
preventing testing using equal
Henri Astre 11 anos atrás
pai
commit
1965a19f3d
2 arquivos alterados com 20 adições e 0 exclusões
  1. 12 0
      src/math/Quaternion.js
  2. 8 0
      test/unit/math/Quaternion.js

+ 12 - 0
src/math/Quaternion.js

@@ -399,6 +399,18 @@ THREE.Quaternion.prototype = {
 
 	slerp: function ( qb, t ) {
 
+		if (t === 0) {
+
+			return this;
+
+		}
+
+		else if (t === 1) {
+
+			return this.copy( qb );
+
+		}
+
 		var x = this._x, y = this._y, z = this._z, w = this._w;
 
 		// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/

+ 8 - 0
test/unit/math/Quaternion.js

@@ -209,3 +209,11 @@ test( "equals", function() {
 	ok( a.equals( b ), "Passed!" );
 	ok( b.equals( a ), "Passed!" );
 });
+
+test( "slerp", function() {
+	var a = new THREE.Quaternion( 0.675341, 0.408783, 0.328567, 0.518512 );
+	var b = new THREE.Quaternion( 0.660279, 0.436474, 0.35119, 0.500187 );
+
+	ok( a.slerp(b, 0).equals(a), "Passed!" );
+	ok( a.slerp(b, 1).equals(b), "Passed!" );
+});