Browse Source

Second fix to Quaternion.toRotationMatrix

David catuhe 9 years ago
parent
commit
343cc67c1d

File diff suppressed because it is too large
+ 7 - 7
dist/preview release/babylon.core.js


File diff suppressed because it is too large
+ 2664 - 2664
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 8 - 8
dist/preview release/babylon.js


File diff suppressed because it is too large
+ 16 - 20
dist/preview release/babylon.max.js


File diff suppressed because it is too large
+ 7 - 7
dist/preview release/babylon.noworker.js


+ 15 - 19
src/Math/babylon.math.js

@@ -1323,31 +1323,27 @@ var BABYLON;
             return this;
             return this;
         };
         };
         Quaternion.prototype.toRotationMatrix = function (result) {
         Quaternion.prototype.toRotationMatrix = function (result) {
-            var xx = this.x * this.x;
-            var yy = this.y * this.y;
-            var zz = this.z * this.z;
-            var xy = this.x * this.y;
-            var zw = this.z * this.w;
-            var zx = this.z * this.x;
-            var yw = this.y * this.w;
-            var yz = this.y * this.z;
-            var xw = this.x * this.w;
-            result.m[0] = 1.0 - (2.0 * (yy + zz));
-            result.m[1] = 2.0 * (xy + zw);
-            result.m[2] = 2.0 * (zx - yw);
+            var x = this.x, y = this.y, z = this.z, w = this.w;
+            var x2 = x + x, y2 = y + y, z2 = z + z;
+            var xx = x * x2, xy = x * y2, xz = x * z2;
+            var yy = y * y2, yz = y * z2, zz = z * z2;
+            var wx = w * x2, wy = w * y2, wz = w * z2;
+            result.m[0] = 1 - (yy + zz);
+            result.m[4] = xy - wz;
+            result.m[8] = xz + wy;
+            result.m[1] = xy + wz;
+            result.m[5] = 1 - (xx + zz);
+            result.m[9] = yz - wx;
+            result.m[2] = xz - wy;
+            result.m[6] = yz + wx;
+            result.m[10] = 1 - (xx + yy);
             result.m[3] = 0;
             result.m[3] = 0;
-            result.m[4] = 2.0 * (xy - zw);
-            result.m[5] = 1.0 - (2.0 * (zz + xx));
-            result.m[6] = 2.0 * (yz + xw);
             result.m[7] = 0;
             result.m[7] = 0;
-            result.m[8] = 2.0 * (zx + yw);
-            result.m[9] = 2.0 * (yz - xw);
-            result.m[10] = 1.0 - (2.0 * (yy + xx));
             result.m[11] = 0;
             result.m[11] = 0;
             result.m[12] = 0;
             result.m[12] = 0;
             result.m[13] = 0;
             result.m[13] = 0;
             result.m[14] = 0;
             result.m[14] = 0;
-            result.m[15] = 1.0;
+            result.m[15] = 1;
             return this;
             return this;
         };
         };
         Quaternion.prototype.fromRotationMatrix = function (matrix) {
         Quaternion.prototype.fromRotationMatrix = function (matrix) {

+ 20 - 20
src/Math/babylon.math.ts

@@ -1637,32 +1637,32 @@
         }
         }
 
 
         public toRotationMatrix(result: Matrix): Quaternion {
         public toRotationMatrix(result: Matrix): Quaternion {
-            var xx = this.x * this.x;
-            var yy = this.y * this.y;
-            var zz = this.z * this.z;
-            var xy = this.x * this.y;
-            var zw = this.z * this.w;
-            var zx = this.z * this.x;
-            var yw = this.y * this.w;
-            var yz = this.y * this.z;
-            var xw = this.x * this.w;
-
-            result.m[0] = 1.0 - (2.0 * (yy + zz));
-            result.m[1] = 2.0 * (xy + zw);
-            result.m[2] = 2.0 * (zx - yw);
+            var x = this.x, y = this.y, z = this.z, w = this.w;
+            var x2 = x + x, y2 = y + y, z2 = z + z;
+            var xx = x * x2, xy = x * y2, xz = x * z2;
+            var yy = y * y2, yz = y * z2, zz = z * z2;
+            var wx = w * x2, wy = w * y2, wz = w * z2; 
+ 
+            result.m[0] = 1 - (yy + zz);
+            result.m[4] = xy - wz;
+            result.m[8] = xz + wy;
+            
+            result.m[1] = xy + wz;
+            result.m[5] = 1 - (xx + zz);
+            result.m[9] = yz - wx;
+            
+            result.m[2] = xz - wy;
+            result.m[6] = yz + wx;
+            result.m[10] = 1 - (xx + yy);
+            
             result.m[3] = 0;
             result.m[3] = 0;
-            result.m[4] = 2.0 * (xy - zw);
-            result.m[5] = 1.0 - (2.0 * (zz + xx));
-            result.m[6] = 2.0 * (yz + xw);
             result.m[7] = 0;
             result.m[7] = 0;
-            result.m[8] = 2.0 * (zx + yw);
-            result.m[9] = 2.0 * (yz - xw);
-            result.m[10] = 1.0 - (2.0 * (yy + xx));
             result.m[11] = 0;
             result.m[11] = 0;
+            
             result.m[12] = 0;
             result.m[12] = 0;
             result.m[13] = 0;
             result.m[13] = 0;
             result.m[14] = 0;
             result.m[14] = 0;
-            result.m[15] = 1.0;
+            result.m[15] = 1; 
 
 
             return this;
             return this;
         }
         }