소스 검색

Merge pull request #5207 from henri-astre-msft/slerp

Fix Quaternion.slerp for special case t=0 and t=1
Mr.doob 11 년 전
부모
커밋
8f73045a0f
2개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      src/math/Quaternion.js
  2. 8 0
      test/unit/math/Quaternion.js

+ 4 - 0
src/math/Quaternion.js

@@ -399,6 +399,10 @@ THREE.Quaternion.prototype = {
 
 	slerp: function ( qb, t ) {
 
+		if ( t === 0 ) return this;
+
+		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!" );
+});