Browse Source

remove duplicate Quaternion.toEuler (already on Vector3.setEulerFromQuaternion), expand Quat unit test, fix merge.

Ben Houston 12 years ago
parent
commit
2103070e8a
4 changed files with 10 additions and 99 deletions
  1. 0 50
      src/math/Quaternion.js
  2. 8 5
      test/unit/math/Quaternion.js
  3. 0 43
      test/unit/sources.html
  4. 2 1
      test/unit/unittests_sources.html

+ 0 - 50
src/math/Quaternion.js

@@ -3,7 +3,6 @@
  * @author alteredq / http://alteredqualia.com/
  * @author WestLangley / http://github.com/WestLangley
  * @author bhouston / http://exocortex.com
- * @author Hasan Kamal-Al-Deen / [email protected]
  */
 
 THREE.Quaternion = function( x, y, z, w ) {
@@ -322,55 +321,6 @@ THREE.Quaternion.prototype = {
 
 	},
 
-	toEuler: function ( order, optionalTarget ) {
-
-	    var result = optionalTarget || new THREE.Vector3();
-
-	    var qx = this.x,
-	    	qy = this.y,
-	    	qz = this.z,
-	    	qw = this.w;
-	    var sqx = qx*qx,
-	        sqy = qy*qy,
-	        sqz = qz*qz,
-	        sqw = qw*qw;
-
-		if ( order === undefined || order === 'XYZ' ) {
-
-	        var test = qw*qy - qx*qz;
-
-		    if (test > 0.4999) {
-
-		        result.x = 0;
-		        result.y = 90;
-		        result.z = -2 * Math.atan2(qx, qw);
-
-		    } else if (test < -0.4999) {
-
-		        result.x = 0;
-		        result.y = -90;
-		        result.z = 2 * Math.atan2(qx, qw);
-
-		    } else {
-
-		        result.x = Math.atan2(2 * (qw*qx + qy*qz), sqw - sqx - sqy + sqz);
-		        result.y = Math.asin(2 * (qw*qy - qx*qz));
-		        result.z = Math.atan2(2 * (qx*qy + qw*qz), sqw + sqx - sqy - sqz);
-
-		    }
-
-		}
-		else {
-
-			// TODO: support more Euler orders.			
-			throw new Error( "Euler order not supported: " + order );
-
-		}
-
-	    return result;
-
-	},
-
 	slerpSelf: function ( qb, t ) {
 
 		var x = this.x, y = this.y, z = this.z, w = this.w;

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

@@ -77,14 +77,17 @@ test( "setFromAxisAngle", function() {
 });
 
 
-test( "setFromEuler/toEuler", function() {
+test( "setFromEuler/setEulerFromQuaternion", function() {
 
 	var angles = [ new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ) ];
 
-	for( var i = 0; i < angles.length; i ++ ) {
-		// check only supported toEuler format
-		var eulers2 = new THREE.Quaternion().setFromEuler( angles[i], "XYZ" ).toEuler( "XYZ" );
-		ok( eulers2.distanceTo( angles[i] ) < 0.001, "Passed!" );
+	// ensure euler conversion to/from Quaternion matches.
+	for( var i = 0; i < orders.length; i ++ ) {
+		for( var j = 0; j < angles.length; j ++ ) {
+			var eulers2 = new THREE.Vector3().setEulerFromQuaternion( new THREE.Quaternion().setFromEuler( angles[j], orders[i] ), orders[i] );
+		
+			ok( eulers2.distanceTo( angles[j] ) < 0.001, "Passed!" );
+		}
 	}
 
 });

+ 0 - 43
test/unit/sources.html

@@ -1,43 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>ThreeJS Test Suite - Using Files in /src</title>
-  <link rel="stylesheet" href="qunit-1.10.0.css">
-</head>
-<body>
-  <div id="qunit"></div>
-  <script src="qunit-1.10.0.js"></script>
-
-  <!-- add ThreeJS sources to test below -->
-
-  <script src="../../src/Three.js"></script>
-  <script src="../../src/math/Vector2.js"></script>
-  <script src="../../src/math/Vector3.js"></script>
-  <script src="../../src/math/Vector4.js"></script>
-  <script src="../../src/math/Box2.js"></script>
-  <script src="../../src/math/Box3.js"></script>
-  <script src="../../src/math/Plane.js"></script>
-  <script src="../../src/math/Ray.js"></script>
-  <script src="../../src/math/Sphere.js"></script>
-  <script src="../../src/math/Triangle.js"></script>
-  <script src="../../src/math/Matrix3.js"></script>
-  <script src="../../src/math/Matrix4.js"></script>
-  <script src="../../src/math/Quaternion.js"></script>
-  
-  <!-- add class-based unit tests below -->
-
-  <script src="math/Constants.js"></script>
-  <script src="math/Box2.js"></script>
-  <script src="math/Box3.js"></script>
-  <script src="math/Plane.js"></script>
-  <script src="math/Ray.js"></script>
-  <script src="math/Sphere.js"></script>
-  <script src="math/Triangle.js"></script>
-  <script src="math/Vector2.js"></script>
-  <script src="math/Vector3.js"></script>
-  <script src="math/Vector4.js"></script>
-  <script src="math/Quaternion.js"></script>
-  
-</body>
-</html>

+ 2 - 1
test/unit/unittests_sources.html

@@ -24,6 +24,7 @@
   <script src="../../src/math/Matrix3.js"></script>
   <script src="../../src/math/Matrix4.js"></script>
   <script src="../../src/math/Color.js"></script>
+  <script src="../../src/math/Quaternion.js"></script>
 
   <!-- add class-based unit tests below -->
 
@@ -37,7 +38,7 @@
   <script src="math/Vector2.js"></script>
   <script src="math/Vector3.js"></script>
   <script src="math/Vector4.js"></script>
-  <script src="core/Vector3Buffer.js"></script>
+  <script src="math/Quaternion.js"></script>
   
 </body>
 </html>