Explorar el Código

Quaternion: Refactor toAngle()

Mugen87 hace 7 años
padre
commit
e1ed817216
Se han modificado 2 ficheros con 4 adiciones y 2 borrados
  1. 2 2
      src/math/Quaternion.js
  2. 2 0
      test/unit/src/math/Quaternion.tests.js

+ 2 - 2
src/math/Quaternion.js

@@ -399,9 +399,9 @@ Object.assign( Quaternion.prototype, {
 
 		return function angleTo( q ) {
 
-			p.copy( q ).inverse();
+			p.copy( this ).inverse();
 
-			p.premultiply( this );
+			p.premultiply( q );
 
 			return 2 * Math.acos( p.w );
 

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

@@ -396,10 +396,12 @@ export default QUnit.module( 'Maths', () => {
 			var a = new Quaternion();
 			var b = new Quaternion().setFromEuler( new Euler( 0, Math.PI, 0 ) );
 			var c = new Quaternion().setFromEuler( new Euler( 0, Math.PI * 2, 0 ) );
+			var d = new Quaternion().setFromEuler( new Euler( 1, 1, 1 ) );
 
 			assert.ok( a.angleTo( a ) <= eps, "Passed!" );
 			assert.ok( ( a.angleTo( b ) - Math.PI ) <= eps, "Passed!" );
 			assert.ok( ( a.angleTo( c ) - ( Math.PI * 2 ) ) <= eps, "Passed!" );
+			assert.ok( ( a.angleTo( d ) - ( 1.939087528822506 ) ) <= eps, "Passed!" );
 
 		} );